Exemple #1
0
func (p *PickleSerializer) Deserialize(b []byte, o interface{}) (err error) {
	unpacker := stalecucumber.UnpackInto(o)
	//BUG: this doens't work as pickle cannot deserialize kwargs!!
	unpacker.AllowMismatchedFields = true
	unpacker.AllowMissingFields = true
	err = unpacker.From(stalecucumber.Unpickle(bytes.NewReader(b)))
	//log.Debugf("Pickled: [%s] [%s]", task.ID, task.Task)
	return
}
/*
Python object file protocol.
Super specific to the format found in banner.p.
*/
func unpickle(p io.ReadCloser) [][][]interface{} {
	defer p.Close()
	result := make([][][]interface{}, 0)
	err := stalecucumber.UnpackInto(&result).From(stalecucumber.Unpickle(p))
	if err != nil {
		panic(err)
	}
	return result
}
Exemple #3
0
// ParseCarbonlinkRequest from pickle encoded data
func ParseCarbonlinkRequest(data []byte) (*CarbonlinkRequest, error) {
	reader := bytes.NewReader(data)
	req := NewCarbonlinkRequest()

	if err := stalecucumber.UnpackInto(req).From(stalecucumber.Unpickle(reader)); err != nil {
		return nil, err
	}

	return req, nil
}
Exemple #4
0
func Unmarshal(input []byte, inputFormat format) (interface{}, error) {
	var data interface{}
	var err error

	switch inputFormat {
	case formatJSON:
		decoder := json.NewDecoder(bytes.NewReader(input))
		decoder.UseNumber()
		err = decoder.Decode(&data)
		// FIXME: convert numbers to int64
	case formatTOML:
		_, err = toml.Decode(string(input), &data)
		// FIXME: use effective bytes to string instead whole copy
	case formatXML:
		err = xml.Unmarshal(input, &data)
	case formatMsgpack:
	case formatPickle:
		buf := new(bytes.Buffer)
		buf.Write(input)
		err = stalecucumber.UnpackInto(&data).From(stalecucumber.Unpickle(buf))
	case formatBson:
		err = bson.Unmarshal(input, &data)
	case formatPlist:
		input := bytes.NewReader(input)
		decoder := plist.NewDecoder(input)
		err = decoder.Decode(data)
	case formatYAML:
		err = yaml.Unmarshal(input, &data)
		if err == nil {
			data, err = convertMapsToStringMaps(data)
		}
	default:
		err = fmt.Errorf("unsupported input format")
	}

	return data, err
}
Exemple #5
0
func (reply *CarbonlinkReply) LoadBytes(replyBytes []byte) {
	stalecucumber.UnpackInto(reply).From(stalecucumber.Unpickle(bytes.NewReader(replyBytes)))
}