A Decoder reads and decodes MessagePack values from an input stream. Buffered returns a reader of the data remaining in the Decoder's buffer.
The reader is valid until the next call to Decode.(*Decoder) Decode(v interface{}) error DecodeArrayLen decodes array length. Length is -1 when array is nil.(*Decoder) DecodeBool() (bool, error)(*Decoder) DecodeBytes() ([]byte, error)(*Decoder) DecodeBytesLen() (int, error)(*Decoder) DecodeDuration() (time.Duration, error)(*Decoder) DecodeExtHeader() (extID int8, extLen int, err error)(*Decoder) DecodeFloat32() (float32, error) DecodeFloat64 decodes msgpack float32/64 into Go float64.(*Decoder) DecodeInt() (int, error)(*Decoder) DecodeInt16() (int16, error)(*Decoder) DecodeInt32() (int32, error) DecodeInt64 decodes msgpack int8/16/32/64 and uint8/16/32/64
into Go int64.(*Decoder) DecodeInt8() (int8, error) DecodeInterface decodes value into interface. It returns following types:
- nil,
- bool,
- int8, int16, int32, int64,
- uint8, uint16, uint32, uint64,
- float32 and float64,
- string,
- []byte,
- slices of any of the above,
- maps of any of the above.
DecodeInterface should be used only when you don't know the type of value
you are decoding. For example, if you are decoding number it is better to use
DecodeInt64 for negative numbers and DecodeUint64 for positive numbers. DecodeInterfaceLoose is like DecodeInterface except that:
- int8, int16, and int32 are converted to int64,
- uint8, uint16, and uint32 are converted to uint64,
- float32 is converted to float64.
- []byte is converted to string.(*Decoder) DecodeMap() (map[string]interface{}, error) DecodeMapLen decodes map length. Length is -1 when map is nil.(*Decoder) DecodeMulti(v ...interface{}) error(*Decoder) DecodeNil() error(*Decoder) DecodeRaw() (RawMessage, error)(*Decoder) DecodeSlice() ([]interface{}, error)(*Decoder) DecodeString() (string, error)(*Decoder) DecodeTime() (time.Time, error) DecodeTypedMap decodes a typed map. Typed map is a map that has a fixed type for keys and values.
Key and value types may be different.(*Decoder) DecodeUint() (uint, error)(*Decoder) DecodeUint16() (uint16, error)(*Decoder) DecodeUint32() (uint32, error) DecodeUint64 decodes msgpack int8/16/32/64 and uint8/16/32/64
into Go uint64.(*Decoder) DecodeUint8() (uint8, error)(*Decoder) DecodeUntypedMap() (map[interface{}]interface{}, error)(*Decoder) DecodeValue(v reflect.Value) error DisableAllocLimit enables fully allocating slices/maps when the size is known DisallowUnknownFields causes the Decoder to return an error when the destination
is a struct and the input contains object keys which do not match any
non-ignored, exported fields in the destination. PeekCode returns the next MessagePack code without advancing the reader.
Subpackage msgpack/codes defines the list of available msgpcode. Query extracts data specified by the query from the msgpack stream skipping
any other data. Query consists of map keys and array indexes separated with dot,
e.g. key1.0.key2. ReadFull reads exactly len(buf) bytes into the buf. Reset discards any buffered data, resets all state, and switches the buffered
reader to read from r. ResetDict is like Reset, but also resets the dict.(*Decoder) ResetReader(r io.Reader) SetCustomStructTag causes the decoder to use the supplied tag as a fallback option
if there is no msgpack tag.(*Decoder) SetMapDecoder(fn func(*Decoder) (interface{}, error)) Skip skips next value. UseInternedStrings enables support for decoding interned strings. UseLooseInterfaceDecoding causes decoder to use DecodeInterfaceLoose
to decode msgpack value into Go interface{}. UsePreallocateValues enables preallocating values in chunks(*Decoder) WithDict(dict []string, fn func(*Decoder) error) error
*Decoder : github.com/grpc-ecosystem/grpc-gateway/v2/runtime.Decoder
func GetDecoder() *Decoder
func NewDecoder(r io.Reader) *Decoder
func PutDecoder(dec *Decoder)
func CustomDecoder.DecodeMsgpack(*Decoder) error
func (*RawMessage).DecodeMsgpack(dec *Decoder) error
(*Encoder) Encode(v interface{}) error(*Encoder) EncodeArrayLen(l int) error(*Encoder) EncodeBool(value bool) error(*Encoder) EncodeBytes(v []byte) error(*Encoder) EncodeBytesLen(l int) error(*Encoder) EncodeDuration(d time.Duration) error(*Encoder) EncodeExtHeader(extID int8, extLen int) error(*Encoder) EncodeFloat32(n float32) error(*Encoder) EncodeFloat64(n float64) error EncodeNumber encodes an int64 in 1, 2, 3, 5, or 9 bytes.
Type of the number is lost during encoding. EncodeInt16 encodes an int16 in 3 bytes preserving type of the number. EncodeInt32 encodes an int32 in 5 bytes preserving type of the number. EncodeInt64 encodes an int64 in 9 bytes preserving type of the number. EncodeInt8 encodes an int8 in 2 bytes preserving type of the number.(*Encoder) EncodeMap(m map[string]interface{}) error(*Encoder) EncodeMapLen(l int) error(*Encoder) EncodeMapSorted(m map[string]interface{}) error(*Encoder) EncodeMulti(v ...interface{}) error(*Encoder) EncodeNil() error(*Encoder) EncodeString(v string) error(*Encoder) EncodeTime(tm time.Time) error EncodeUnsignedNumber encodes an uint64 in 1, 2, 3, 5, or 9 bytes.
Type of the number is lost during encoding. EncodeUint16 encodes an uint16 in 3 bytes preserving type of the number. EncodeUint32 encodes an uint16 in 5 bytes preserving type of the number. EncodeUint64 encodes an uint16 in 9 bytes preserving type of the number. EncodeUint8 encodes an uint8 in 2 bytes preserving type of the number.(*Encoder) EncodeValue(v reflect.Value) error Reset discards any buffered data, resets all state, and switches the writer to write to w. ResetDict is like Reset, but also resets the dict.(*Encoder) ResetWriter(w io.Writer) SetCustomStructTag causes the Encoder to use a custom struct tag as
fallback option if there is no msgpack tag. SetOmitEmpty causes the Encoder to omit empty values by default. SetSortMapKeys causes the Encoder to encode map keys in increasing order.
Supported map types are:
- map[string]string
- map[string]bool
- map[string]interface{} UseArrayEncodedStructs causes the Encoder to encode Go structs as msgpack arrays. UseCompactFloats causes the Encoder to chose a compact integer encoding
for floats that can be represented as integers. UseCompactEncoding causes the Encoder to chose the most compact encoding.
For example, it allows to encode small Go int64 as msgpack int8 saving 7 bytes. UseInternedStrings causes the Encoder to intern strings.(*Encoder) WithDict(dict map[string]int, fn func(*Encoder) error) error Writer returns the Encoder's writer.
*Encoder : github.com/grpc-ecosystem/grpc-gateway/v2/runtime.Encoder
*Encoder : go.uber.org/zap/zapcore.ReflectedEncoder
func GetEncoder() *Encoder
func NewEncoder(w io.Writer) *Encoder
func (*Encoder).SetSortMapKeys(on bool) *Encoder
func PutEncoder(enc *Encoder)
func CustomEncoder.EncodeMsgpack(*Encoder) error
func RawMessage.EncodeMsgpack(enc *Encoder) error
NewDecoder returns a new decoder that reads from r.
The decoder introduces its own buffering and may read data from r
beyond the requested msgpack values. Buffering can be disabled
by passing a reader that implements io.ByteScanner interface.
NewEncoder returns a new encoder that writes to w.
Register registers encoder and decoder functions for a value.
This is low level API and in most cases you should prefer implementing
CustomEncoder/CustomDecoder or Marshaler/Unmarshaler interfaces.
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.