msgpackwire

package
v0.0.0-...-343dfa7 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package msgpackwire provides bounded MessagePack decoding and deterministic encoding.

Decoding accepts exactly one object. Untyped maps require string keys while typed map targets may declare other comparable key types. Integer widths are preserved unless NormalizeNumericWidths is selected. The standard timestamp extension is supported; unknown extension IDs are rejected. A structural preflight rejects truncated objects and impossible collection lengths before target allocation. MessagePack is deliberately excluded from wire.DetectFormat because arbitrary binary bytes cannot be identified reliably.

Index

Constants

View Source
const (
	// DefaultMaxNestedLevels bounds recursive arrays and maps.
	DefaultMaxNestedLevels = 32
	// DefaultMaxArrayElements bounds allocation amplification from arrays.
	DefaultMaxArrayElements = 128 << 10
	// DefaultMaxMapPairs bounds allocation amplification from maps.
	DefaultMaxMapPairs = 64 << 10
)
View Source
const DefaultMaxBytes int64 = 1 << 20

DefaultMaxBytes is the default maximum MessagePack object size.

Variables

View Source
var ErrPayloadTooLarge = errors.New("payload exceeds size limit")

ErrPayloadTooLarge identifies MessagePack objects over the byte limit.

Functions

func Decode

func Decode(payload []byte, target any, options DecodeOptions) error

Decode parses exactly one MessagePack object into target.

func DecodeReader

func DecodeReader(reader io.Reader, target any, options DecodeOptions) error

DecodeReader reads one bounded MessagePack object into target.

func Encode

func Encode(value any, options EncodeOptions) ([]byte, error)

Encode serializes value with lexically sorted map keys.

func EncodeWriter

func EncodeWriter(writer io.Writer, value any, options EncodeOptions) error

EncodeWriter serializes value and writes one complete MessagePack object.

Types

type DecodeOptions

type DecodeOptions struct {
	MaxBytes               int64
	MaxNestedLevels        int
	MaxArrayElements       int
	MaxMapPairs            int
	AllowDuplicateKeys     bool
	DisallowUnknownFields  bool
	NormalizeNumericWidths bool
}

DecodeOptions controls MessagePack decoding and integer interoperability.

type EncodeOptions

type EncodeOptions struct {
	MaxBytes        int64
	CompactIntegers bool
	CompactFloats   bool
	StructAsArray   bool
}

EncodeOptions controls deterministic MessagePack serialization.

Jump to

Keyboard shortcuts

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