Documentation
¶
Overview ¶
Package msgpack implements the subset of MessagePack that the memberlist wire protocol uses, byte-for-byte compatible with the encoder the protocol was defined by: github.com/hashicorp/go-msgpack/v2 with a default MsgpackHandle (WriteExt false).
Encoding follows that handle exactly:
- strings and byte slices use the legacy raw family: fixstr (< 32 bytes), str16 (< 65536), str32; never str8 or bin. A nil byte slice is nil.
- unsigned integers use the smallest of positive fixint, uint8, uint16, uint32, uint64.
- signed integers use positive fixint for 0..127, int16/int32/int64 for larger positive values (never uint*), negative fixint for -32..-1, and the smallest of int8/int16/int32/int64 below that.
- maps use fixmap (< 16 entries), map16, map32.
Decoding accepts every encoding a MessagePack encoder can produce for the target type: any integer format whose value is in range, str and bin families for strings and bytes, 0/1 fixints for booleans, and nil for the zero value. It is deliberately stricter than go-msgpack's decoder, which also accepts arrays of integers as bytes or strings and wraps out-of-range integers; no memberlist encoder produces either. Map counts above 2^31-1 and skipped values nested deeper than 32 levels are refused. It never panics and never allocates more than the input holds: in slice mode lengths are checked against the remaining input, and in stream mode buffers grow with the bytes actually received.
Index ¶
- Variables
- func AppendBool(b []byte, v bool) []byte
- func AppendBytes(b []byte, p []byte) []byte
- func AppendInt(b []byte, v int64) []byte
- func AppendMapHeader(b []byte, n int) []byte
- func AppendNil(b []byte) []byte
- func AppendString(b []byte, s string) []byte
- func AppendUint(b []byte, v uint64) []byte
- type Decoder
- func (d *Decoder) ReadBool() (bool, error)
- func (d *Decoder) ReadBytes(limit int) ([]byte, error)
- func (d *Decoder) ReadInt(lo, hi int64) (int64, error)
- func (d *Decoder) ReadKey() ([]byte, error)
- func (d *Decoder) ReadMapHeader() (int, error)
- func (d *Decoder) ReadRaw(n int) ([]byte, error)
- func (d *Decoder) ReadString(limit int) (string, error)
- func (d *Decoder) ReadUint(limit uint64) (uint64, error)
- func (d *Decoder) Remaining() int
- func (d *Decoder) Reset(b []byte)
- func (d *Decoder) Skip() error
- type Source
Constants ¶
This section is empty.
Variables ¶
var ErrTruncated = errors.New("msgpack: truncated input")
ErrTruncated is returned when the input ends inside a value.
Functions ¶
func AppendBytes ¶
AppendBytes appends a byte slice in the legacy raw family; nil encodes as nil, an empty non-nil slice as an empty string.
func AppendInt ¶
AppendInt appends a signed integer the way go-msgpack's EncodeInt does (PositiveIntUnsigned false): positive values above 127 use the signed formats.
func AppendMapHeader ¶
AppendMapHeader appends the header of a map with n entries.
func AppendString ¶
AppendString appends a string in the legacy raw family.
func AppendUint ¶
AppendUint appends an unsigned integer in its smallest format.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder reads values from a byte slice or a Source.
func NewDecoder ¶
NewDecoder returns a decoder over b. Slices it returns alias b only where documented (ReadKey); byte and string values are copies.
func NewStreamDecoder ¶
NewStreamDecoder returns a decoder over src.
func (*Decoder) ReadBool ¶
ReadBool reads a boolean; like go-msgpack it accepts fixint 0 and 1, and nil reads as false.
func (*Decoder) ReadBytes ¶
ReadBytes reads a str or bin value as a new byte slice. nil reads as nil; an empty value as an empty non-nil slice. Values longer than limit are refused before any allocation.
func (*Decoder) ReadKey ¶
ReadKey reads a map key (str or bin). The returned slice is valid until the next call; keys longer than 64 bytes are consumed and returned as nil, which matches no field.
func (*Decoder) ReadMapHeader ¶
ReadMapHeader reads a map header and returns its entry count. A nil value reads as an empty map (go-msgpack decodes nil into a zero struct).
func (*Decoder) ReadRaw ¶
ReadRaw reads the next n raw bytes (not a MessagePack value), such as a payload that follows the encoded headers.
func (*Decoder) ReadString ¶
ReadString reads a str or bin value as a string; nil reads as "".