Skip to content

@insler/serde-msgpack

The MessagePack adapter package: msgpackSerde, a Serde<Uint8Array> backed by @msgpack/msgpack. Reach for it when compact binary encoding matters on a binary wire.

Terminal window
bun add @insler/serde-msgpack
import { msgpackSerde } from '@insler/serde-msgpack';
const bytes = msgpackSerde.encode({ id: 'ord-1', quantity: 3, price: 19.5 });
// Uint8Array — MessagePack-encoded
const order = msgpackSerde.decode(bytes);
// { id: 'ord-1', quantity: 3, price: 19.5 }

It honors the shared serde conventions: encode(undefined) produces empty bytes, decoding empty bytes returns undefined.

msgpackSerde is a standard Serde<Uint8Array> — swap it with jsonBytesSerde, cborSerde, or an Avro serde wherever a binary serde is accepted, such as the rpc subsystem’s NATS transport serde option. Develop on JSON, deploy on MessagePack, without touching a call site.

Depends on @insler/serde (the interface) and @msgpack/msgpack — it stays transport-agnostic, a pure Serde<Uint8Array> with no transport-specific assumptions.