Beispiel #1
0
func (d *Decoder) DecodeInt64() (int64, error) {
	c, err := d.r.ReadByte()
	if err != nil {
		return 0, err
	}
	if codes.IsFixedNum(c) {
		return int64(int8(c)), nil
	}
	switch c {
	case codes.Uint8:
		n, err := d.uint8()
		return int64(n), err
	case codes.Int8:
		n, err := d.uint8()
		return int64(int8(n)), err
	case codes.Uint16:
		n, err := d.uint16()
		return int64(n), err
	case codes.Int16:
		n, err := d.uint16()
		return int64(int16(n)), err
	case codes.Uint32:
		n, err := d.uint32()
		return int64(n), err
	case codes.Int32:
		n, err := d.uint32()
		return int64(int32(n)), err
	case codes.Uint64, codes.Int64:
		n, err := d.uint64()
		return int64(n), err
	}
	return 0, fmt.Errorf("msgpack: invalid code %x decoding int64", c)
}
Beispiel #2
0
// Decodes value into interface. Possible value types are:
//   - nil,
//   - int64,
//   - uint64,
//   - bool,
//   - float32 and float64,
//   - string,
//   - slices of any of the above,
//   - maps of any of the above.
func (d *Decoder) DecodeInterface() (interface{}, error) {
	c, err := d.peekCode()
	if err != nil {
		return nil, err
	}

	if codes.IsFixedNum(c) {
		return d.DecodeInt64()
	} else if codes.IsFixedMap(c) {
		return d.DecodeMap()
	} else if codes.IsFixedArray(c) {
		return d.DecodeSlice()
	} else if codes.IsFixedString(c) {
		return d.DecodeString()
	}

	switch c {
	case codes.Nil:
		_, err := d.r.ReadByte()
		return nil, err
	case codes.False, codes.True:
		return d.DecodeBool()
	case codes.Float:
		return d.DecodeFloat32()
	case codes.Double:
		return d.DecodeFloat64()
	case codes.Uint8, codes.Uint16, codes.Uint32, codes.Uint64:
		return d.DecodeUint64()
	case codes.Int8, codes.Int16, codes.Int32, codes.Int64:
		return d.DecodeInt64()
	case codes.Bin8, codes.Bin16, codes.Bin32:
		return d.DecodeBytes()
	case codes.Str8, codes.Str16, codes.Str32:
		return d.DecodeString()
	case codes.Array16, codes.Array32:
		return d.DecodeSlice()
	case codes.Map16, codes.Map32:
		return d.DecodeMap()
	}

	return 0, fmt.Errorf("msgpack: invalid code %x decoding interface{}", c)
}