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.
Raw duplicate keys are rejected recursively by default. Destination-key collisions are also checked for built-in, unregistered scalar and array key projections in maps and unambiguous direct or noinline struct fields. Struct keys and alias, auto-inline, shadowed or interned field routing are not covered by that additional projection check. Custom codecs and global msgpack.Register overrides are trusted caller-owned behavior, not predicted or executed by preflight. See docs/security.md for remaining boundaries.
MaxTotalValues admits aggregate structure before generic materialization. MaxKeyComparisonWork reserves conservative raw and projected comparison work and supported expanded array-key preparation before those operations. Zero options retain finite defaults. These quotas do not bound final driver allocations, custom codec objects, elapsed CPU time, or reader cancellation.
Index ¶
- Constants
- Variables
- func Decode(payload []byte, target any, options DecodeOptions) error
- func DecodeReader(reader io.Reader, target any, options DecodeOptions) error
- func Encode(value any, options EncodeOptions) ([]byte, error)
- func EncodeWriter(writer io.Writer, value any, options EncodeOptions) error
- type DecodeOptions
- type EncodeOptions
Constants ¶
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 // DefaultMaxTotalValues bounds aggregate containers, keys and values. DefaultMaxTotalValues = 256 << 10 // DefaultMaxKeyComparisonWork bounds conservative key-comparison units. DefaultMaxKeyComparisonWork = 8 << 20 )
const DefaultMaxBytes int64 = 1 << 20
DefaultMaxBytes is the default maximum MessagePack object size.
Variables ¶
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
// MaxTotalValues counts every container, scalar, key and value once.
// Zero selects DefaultMaxTotalValues; negative values are invalid.
MaxTotalValues int
// MaxKeyComparisonWork bounds conservative examined-byte/value units,
// including supported expanded array-key preparation. Zero selects the
// default; negative values are invalid. This is not a CPU or heap quota.
MaxKeyComparisonWork int64
AllowDuplicateKeys bool
DisallowUnknownFields bool
NormalizeNumericWidths bool
}
DecodeOptions controls MessagePack decoding and integer interoperability.