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)
Example
Section titled “Example”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 }Type Parameters
Section titled “Type Parameters”TIn = unknown
TOut = TIn
Implements
Section titled “Implements”Codec<TIn,TOut>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new MsgPackCodec<
TIn,TOut>():MsgPackCodec<TIn,TOut>
Returns
Section titled “Returns”MsgPackCodec<TIn, TOut>
Properties
Section titled “Properties”
readonlyname:"msgpack"="msgpack"
Defined in: packages/codecs/src/msgpack-codec.ts:80
Human-readable codec name for debugging/logging.
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”deserialize()
Section titled “deserialize()”deserialize(
buffer):TOut
Defined in: packages/codecs/src/msgpack-codec.ts:98
Deserialize MsgPack binary to object.
Parameters
Section titled “Parameters”buffer
Section titled “buffer”Buffer
Returns
Section titled “Returns”TOut
Implementation of
Section titled “Implementation of”serialize()
Section titled “serialize()”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.
Parameters
Section titled “Parameters”TIn
Returns
Section titled “Returns”Buffer