@omnitron-dev/msgpack
v0.4.18
Published
MessagePack encoding and decoding with extensible JavaScript value types
Maintainers
Readme
@omnitron-dev/msgpack
MessagePack serialization with JavaScript value extensions. Netron uses it for binary RPC payloads.
Capabilities
- Encode and decode values, including registered Date, Map, Set, RegExp and BigInt extensions.
- Create isolated
Serializerinstances and register application codecs. - Read concatenated or partial values with
tryDecode. It returns the first value and its exactbytesConsumed, ornullif it cannot decode that value.
Quick start
pnpm add @omnitron-dev/msgpackimport { encode, decode } from '@omnitron-dev/msgpack';
const bytes = encode({ title: 'Guide', created: new Date('2026-01-01') });
const value = decode(bytes);
console.log(value.created instanceof Date); // trueCustom extension IDs and codecs must agree at both ends. Decoding reconstructs values; application payload validation and authorization belong to the caller.
Plain objects encode their own enumerable string keys as standard MessagePack maps. Up to 15 pairs use fixmap, 16 through 65,535 use map16, and larger objects use map32. The decoder accepts all three headers for any count they can represent. JavaScript Map uses the registered extension to preserve key types. MessagePack map format
decode and tryDecode accept a Buffer, a Uint8Array view, or a SmartBuffer from @omnitron-dev/msgpack/smart-buffer. Both helpers read from the current SmartBuffer cursor and leave it in place. Use serializer.decode(buffer) to advance past a value. With chunked input, keep the unread bytes when tryDecode returns null and retry after appending the next chunk.
Verification
From the repository root, pnpm exec xec verify-model msgpack checks a finite model of two ordinary messages sent through a fragmented stream. A separate encoder supplies the reference frame lengths. The profile compares delivery order, visible bytes, peek results and cursor position after each operation. Its JSON receipt records the depth, observations and outcome. Stream model · Run and replay a profile
Map-format tests cover cardinality thresholds, legal wider headers, independent decoding and adjacent frames. Keep these wire-format cases alongside the stream model when changing the codec. Map framing tests
Documentation
Public API · Package exports · Omni
License
MIT.
