Skip to main content

MsgpackCodec

Defined in: src/codec/msgpack.codec.ts:43

MessagePack codec backed by a caller-provided msgpackr Packr instance.

Use this codec when publishing structured payloads larger than roughly 1–2 KB — below that size the default JsonCodec wins on per-call constant overhead. Above it, MessagePack encodes and decodes several times faster and produces smaller wire frames. The format is cross-language, so Node producers and non-Node consumers (Python, Go, Java, Rust, ...) stay interoperable.

Requires installing the optional msgpackr peer dependency:

npm install msgpackr
# or: pnpm add msgpackr

Example

import { JetstreamModule, MsgpackCodec } from '@horizon-republic/nestjs-jetstream';
import { Packr } from 'msgpackr';

JetstreamModule.forRoot({
name: 'orders',
servers: ['nats://localhost:4222'],
codec: new MsgpackCodec(new Packr()),
});

Implements

Constructors

Constructor

new MsgpackCodec(packr): MsgpackCodec

Defined in: src/codec/msgpack.codec.ts:44

Parameters

packr

PackrLike

Returns

MsgpackCodec

Methods

decode()

decode(data): unknown

Defined in: src/codec/msgpack.codec.ts:50

Deserialize binary NATS payload back to application data.

Parameters

data

Uint8Array

Returns

unknown

Implementation of

Codec.decode


encode()

encode(data): Uint8Array

Defined in: src/codec/msgpack.codec.ts:46

Serialize application data to binary for NATS transmission.

Parameters

data

unknown

Returns

Uint8Array

Implementation of

Codec.encode