msgpack

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: 0BSD Imports: 12 Imported by: 3 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package msgpack implements EDB's MessagePack struct encoding. Like Fast1, MessagePack remains supported, with migration to Fast2 or Compact2 intended.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrDepth = errors.New("MessagePack nesting exceeds 256")

ErrDepth reports that a value exceeds the parser's nesting limit.

View Source
var ErrFormat = errors.New("invalid MessagePack value")

ErrFormat identifies invalid or truncated MessagePack.

Functions

func Decode

func Decode(src []byte, value reflect.Value)

Decode panics on error. Use TryDecode to handle errors explicitly.

func Encode

func Encode(dst []byte, value reflect.Value) []byte

Encode panics on error. Use TryEncode to handle errors explicitly.

func TryDecode

func TryDecode(src []byte, value reflect.Value) error

TryDecode decodes into the native destination and returns decoding failures as errors.

func TryEncode

func TryEncode(dst []byte, value reflect.Value) ([]byte, error)

TryEncode appends the MessagePack representation of value to dst and returns encoding failures as errors.

Types

type FieldEdit

type FieldEdit struct {
	Name  string
	Value []byte
}

FieldEdit replaces a string-keyed map field. A nil Value deletes the field; []byte{0xc0} stores explicit null. Values must contain one complete value.

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

Iterator borrows successive encoded children. Maps return keys and values; arrays return a missing key. No Go map, slice or element is decoded.

func (*Iterator) Len

func (it *Iterator) Len() int

Len reports how many entries remain in the iterator.

func (*Iterator) Next

func (it *Iterator) Next() (key, value View, ok bool)

Next advances to the next entry. It returns false at the end.

type View

type View struct {
	// contains filtered or unexported fields
}

View borrows one encoded MessagePack value. It never constructs a Go object. Trusted is for stored bytes; accessors still check boundaries before reading.

func BuildArray

func BuildArray(capacity int, entries iter.Seq[View]) View

BuildArray copies raw elements into one new array.

func BuildMap

func BuildMap(capacity int, entries iter.Seq2[View, View]) View

BuildMap copies raw entries into one new map, preserving their encodings. capacity is a sizing hint; nil values represent MessagePack null.

func Open

func Open(raw []byte) View

Open panics on error. Use TryOpen to handle errors explicitly.

func Trusted

func Trusted(raw []byte) View

Trusted borrows raw bytes without validating the complete value. Use TryOpen for untrusted input.

func TryOpen

func TryOpen(raw []byte) (v View, err error)

TryOpen validates exactly one encoded value and rejects trailing bytes. On success the view borrows raw.

Example
package main

import (
	"fmt"

	"github.com/andreyvit/evm/kvo/codec/msgpack"
)

func main() {
	// A MessagePack string with a two-byte payload.
	v, err := msgpack.TryOpen([]byte{0xa2, 'G', 'o'})
	if err != nil {
		panic(err)
	}
	fmt.Println(string(v.Bytes()))
	_, err = msgpack.TryOpen([]byte{0xa2, 'G'})
	fmt.Println(err != nil)
}
Output:
Go
true

func (View) Apply

func (v View) Apply(edits []FieldEdit) View

Apply copies the enclosing map once, preserving untouched bytes and key order. Repeated edits to a name use the last edit, including for duplicate wire keys. The input and result never share writable storage.

func (View) Bool

func (v View) Bool() bool

Bool reads a MessagePack boolean.

func (View) Bytes

func (v View) Bytes() []byte

Bytes reads the byte payload without copying it.

func (View) Delete

func (v View) Delete(name string) View

Delete removes all occurrences of a map key, preserving every other encoded entry verbatim. An absent key leaves the original view unchanged.

func (View) Float

func (v View) Float() float64

Float decodes a floating-point value.

func (View) Int

func (v View) Int() int64

Int interprets the integer payload as a signed value.

func (View) Iter

func (v View) Iter() Iterator

Iter starts a single traversal of the container's elements.

func (View) Lookup

func (v View) Lookup(name string) View

Lookup scans encoded field boundaries and borrows only the selected value. It checks all keys so duplicate keys retain MessagePack's last-value semantics.

func (View) Missing

func (v View) Missing() bool

Missing reports whether the view contains no encoded value.

func (View) Nil

func (v View) Nil() bool

Nil reports whether the value is missing or encodes MessagePack nil.

func (View) Raw

func (v View) Raw() []byte

Raw returns the borrowed bytes including the MessagePack header.

func (View) Set

func (v View) Set(name string, value []byte) View

Set replaces a map field while copying every untouched key and value verbatim. The result is owned, and does not mutate or retain spare capacity in the input.

func (View) Time

func (v View) Time() values.Value

Time reads the standard 32/64/96-bit integer timestamp extensions, the historical [seconds,nanoseconds] format, and RFC3339 text. It borrows bytes for wide dates instead of decoding a Go object or allocating a timestamp.

func (View) Uint

func (v View) Uint() uint64

Uint decodes the integer payload as an unsigned word.

Jump to

Keyboard shortcuts

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