func (d *Decoder) uint(c byte) (uint64, error) { if codes.IsFixedNum(c) { return uint64(int8(c)), nil } switch c { case codes.Uint8: n, err := d.uint8() return uint64(n), err case codes.Int8: n, err := d.uint8() return uint64(int8(n)), err case codes.Uint16: n, err := d.uint16() return uint64(n), err case codes.Int16: n, err := d.uint16() return uint64(int16(n)), err case codes.Uint32: n, err := d.uint32() return uint64(n), err case codes.Int32: n, err := d.uint32() return uint64(int32(n)), err case codes.Uint64, codes.Int64: return d.uint64() } return 0, fmt.Errorf("msgpack: invalid code %x decoding uint64", c) }
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) }
// 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.r.ReadByte() if err != nil { return nil, err } if codes.IsFixedNum(c) { if c >= 0 { return d.uint(c) } return d.int(c) } if codes.IsFixedMap(c) { d.r.UnreadByte() return d.DecodeMap() } if codes.IsFixedArray(c) { d.r.UnreadByte() return d.DecodeSlice() } if codes.IsFixedString(c) { return d.string(c) } switch c { case codes.Nil: return nil, nil case codes.False, codes.True: return d.bool(c) case codes.Float: return d.float32(c) case codes.Double: return d.float64(c) case codes.Uint8, codes.Uint16, codes.Uint32, codes.Uint64: return d.uint(c) case codes.Int8, codes.Int16, codes.Int32, codes.Int64: return d.int(c) case codes.Bin8, codes.Bin16, codes.Bin32: return d.bytes(c) case codes.Str8, codes.Str16, codes.Str32: return d.string(c) case codes.Array16, codes.Array32: d.r.UnreadByte() return d.DecodeSlice() case codes.Map16, codes.Map32: d.r.UnreadByte() return d.DecodeMap() case codes.FixExt1, codes.FixExt2, codes.FixExt4, codes.FixExt8, codes.FixExt16, codes.Ext8, codes.Ext16, codes.Ext32: return d.ext(c) } return 0, fmt.Errorf("msgpack: unknown code %x decoding interface{}", c) }
// 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() case codes.FixExt1, codes.FixExt2, codes.FixExt4, codes.FixExt8, codes.FixExt16, codes.Ext8, codes.Ext16, codes.Ext32: return d.decodeExt() } return 0, fmt.Errorf("msgpack: invalid code %x decoding interface{}", c) }
// Skip skips next value. func (d *Decoder) Skip() error { c, err := d.r.ReadByte() if err != nil { return err } if codes.IsFixedNum(c) { return nil } else if codes.IsFixedMap(c) { return d.skipMap(c) } else if codes.IsFixedArray(c) { return d.skipSlice(c) } else if codes.IsFixedString(c) { return d.skipBytes(c) } switch c { case codes.Nil, codes.False, codes.True: return nil case codes.Uint8, codes.Int8: return d.skipN(1) case codes.Uint16, codes.Int16: return d.skipN(2) case codes.Uint32, codes.Int32, codes.Float: return d.skipN(4) case codes.Uint64, codes.Int64, codes.Double: return d.skipN(8) case codes.Bin8, codes.Bin16, codes.Bin32: return d.skipBytes(c) case codes.Str8, codes.Str16, codes.Str32: return d.skipBytes(c) case codes.Array16, codes.Array32: return d.skipSlice(c) case codes.Map16, codes.Map32: return d.skipMap(c) case codes.FixExt1, codes.FixExt2, codes.FixExt4, codes.FixExt8, codes.FixExt16, codes.Ext8, codes.Ext16, codes.Ext32: return d.skipExt(c) } return fmt.Errorf("msgpack: unknown code %x", c) }