mpack

package
v0.0.0-...-cb2abbc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeWrapperMap

func DecodeWrapperMap(dec *msgpack.Decoder) (string, error)

DecodeWrapperMap reads the "single item map" whose key is string - the key name is returned and decoder is ready to read the value. It is suitable to read what EncodeMapStart produced.

func EncodeMapStart

func EncodeMapStart(enc *msgpack.Encoder, key string) error

EncodeMapStart outputs a map with single key named "key", caller must output the value:

{ key: | }

Types

type MapItems

type MapItems []MsgpackEncFunc

func (*MapItems) AddOptionalEncoder

func (ef *MapItems) AddOptionalEncoder(add bool, encFunc MsgpackEncFunc)

AddOptionalEncoder adds the encoder function only if the add flag is true.

func (*MapItems) AddOptionalStr

func (ef *MapItems) AddOptionalStr(key, value string)

AddOptionalStr adds the key/value only if the value is non empty string.

func (*MapItems) AddOptionalUInt

func (ef *MapItems) AddOptionalUInt(key string, value uint)

func (MapItems) EncodeMap

func (ef MapItems) EncodeMap(mapName string, enc *msgpack.Encoder) error

EncodeMap encodes fixed size map using the enc - it writes the number of items and then calls each item to serialize the actual key - value pair.

The mapName argument is used to add context to the error messages (when encoding fails) and not used otherwise (ie does not appear in encoded map).

type MsgpackEncFunc

type MsgpackEncFunc func(enc *msgpack.Encoder) error

func EncoderFuncArray

func EncoderFuncArray[T any](key string, items []T, itemEnc func(T) error) MsgpackEncFunc

EncoderFuncArray writes "named array".

  • key : the name of the array, ie it's the key whose value will be the array;
  • items : slice of items to store as array values;
  • itemEnc : function which encodes item, ie enc.EncodeString

Returns function which can be used with MapItems.

func EncoderFuncBool

func EncoderFuncBool(key string, value bool) MsgpackEncFunc

func EncoderFuncInt

func EncoderFuncInt(key string, value int) MsgpackEncFunc

func EncoderFuncMarshal

func EncoderFuncMarshal(key string, wf MsgpackEncFunc) MsgpackEncFunc

Callback is the "standard marshaler" signature.

func EncoderFuncString

func EncoderFuncString(key, value string) MsgpackEncFunc

EncoderFuncString returns function which encodes string key-value pair. Meant to be used with MapItems to store string value.

func EncoderFuncUInt

func EncoderFuncUInt(key string, value uint) MsgpackEncFunc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL