Skip to content

MsgPackCodec

Defined in: packages/codecs/src/msgpack-codec.ts:79

MsgPackCodec - Efficient binary serialization for JavaScript objects.

USE CASES:

  • Simple objects/arrays
  • Progress events: { percent: 50 }
  • Error responses: { code: ‘ERROR’, message: ’…’ }
  • Configuration: { batchSize: 100, threshold: 0.5 }

FEATURES:

  • Binary format (smaller than JSON)
  • Supports Buffer, Date as extension types
  • ~2-3x faster than JSON
  • ⚡️ Zero-copy Buffer.from(view) in serialize

NOT FOR:

  • Large numeric arrays (use ArrowCodec)
  • Raw binary streams (use RawChunksCodec)
const codec = new MsgPackCodec<{ name: string; count: number }>();
const buffer = codec.serialize({ name: 'test', count: 42 });
const result = codec.deserialize(buffer);
// result === { name: 'test', count: 42 }

TIn = unknown

TOut = TIn

new MsgPackCodec<TIn, TOut>(): MsgPackCodec<TIn, TOut>

MsgPackCodec<TIn, TOut>

readonly name: "msgpack" = "msgpack"

Defined in: packages/codecs/src/msgpack-codec.ts:80

Human-readable codec name for debugging/logging.

Codec.name

deserialize(buffer): TOut

Defined in: packages/codecs/src/msgpack-codec.ts:98

Deserialize MsgPack binary to object.

Buffer

TOut

Codec.deserialize


serialize(data): Buffer

Defined in: packages/codecs/src/msgpack-codec.ts:87

Serialize object to MsgPack binary format.

⚡️ OPTIMIZATION: Uses Buffer.from(view) instead of copying data.

TIn

Buffer

Codec.serialize