msgpackr
Fast MessagePack implementation for Node.js with structured cloning extensions and optional record schema optimization.
Official Documentation ↗v2.1.4. Check the official docs for the latest API surface.Installation
npm install msgpackrpnpm add msgpackrMethods
No methods match this filter.
Overview
msgpackr is a fast MessagePack implementation for Node.js with structured clone extensions and optional record structures for compact payloads. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.
Core APIs
pack— Serializes a value to a MessagePack buffer with optional structured cloning support.unpack— Deserializes MessagePack bytes back into a JavaScript value.new Packr— Creates a reusable codec, optionally with shared structures and custom extensions for compactness.
Example
const { pack, unpack } = require('msgpackr');
const buf = pack({ id: 1, tags: ['a', 'b'] });
const obj = unpack(buf);
console.log(obj.tags);
Notes
Both sides must agree on extensions and structures, so version them with your wire protocol. Plain JSON interoperability is not automatic.
Verification
Round-trip an object containing numbers and arrays and confirm the unpacked value deep-equals the original.
Errors
The following points are quoted verbatim from the official documentation (https://github.com/kriszyp/msgpackr). Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- Structured cloning also enables preserving certain typed objects like Error, Set, RegExp and TypedArray instances. (https://github.com/kriszyp/msgpackr)
- Holding more fails with “Maximum incomplete buffer size exceeded”. (https://github.com/kriszyp/msgpackr)
- If not provided, an invalid date will be encoded as an invalid timestamp (which decodes with msgpackr back to an invalid date). (https://github.com/kriszyp/msgpackr)
FAQ
- Does msgpackr preserve Maps and Sets?
- Yes, when structuredClone extensions are enabled; otherwise such values are serialized as plain objects or arrays.
- What are structures used for?
- MessagePack record structures reduce repeated key names for objects with the same shape, cutting payload size at the cost of decoder state.
- How does it compare to JSON for speed?
- MessagePack payloads are typically smaller and decode faster than JSON text for numeric and binary-heavy data, though JSON stays more readable.
Report a problem with this API docOpens a pre-filled issue on GitHub.