Skip to content

Codec

Defined in: packages/common/src/codecs/codec.ts:11

A bidirectional codec that transforms between application types and wire formats. Supports format-specific encoding (JSON vs msgpack).

T

The application/runtime type (e.g., bigint, string, Uint8Array)

TEncoded = T

The wire format type (may differ based on format, e.g., bigint → string in JSON)

TWireEncoded = TEncoded

new Codec<T, TEncoded, TWireEncoded>(): Codec<T, TEncoded, TWireEncoded>

Codec<T, TEncoded, TWireEncoded>

decode(value, format): T

Defined in: packages/common/src/codecs/codec.ts:46

Decode a value from wire format

The wire value

TWireEncoded | null | undefined

EncodingFormat

The wire format (json or msgpack)

T

The decoded application value


decodeOptional(value, format): T | undefined

Defined in: packages/common/src/codecs/codec.ts:60

Decode an optional value from wire format (preserves undefined vs default distinction)

The wire value

TWireEncoded | null | undefined

EncodingFormat

The wire format (json or msgpack)

T | undefined

The decoded application value, or undefined if wire value was undefined


abstract defaultValue(): T

Defined in: packages/common/src/codecs/codec.ts:15

The default value for this type (used to determine if a value should be omitted during encoding)

T


encode(value, format): TEncoded

Defined in: packages/common/src/codecs/codec.ts:23

Encode a value, always returning the value regardless of if it is default

The application value

T | null | undefined

EncodingFormat

The wire format (json or msgpack)

TEncoded

The encoded value, or the default if it is undefined or null


encodeOptional(value, format): TEncoded | undefined

Defined in: packages/common/src/codecs/codec.ts:34

Encode a value, omitting it if set to the default value.

The application value

T | null | undefined

EncodingFormat

The wire format (json or msgpack)

TEncoded | undefined

The encoded value, or undefined if it equals the default (will be omitted)


isDefaultValue(value): boolean

Defined in: packages/common/src/codecs/codec.ts:94

Check if a value equals the default value (determines if it should be omitted during encoding) Override this method for custom default comparison logic, otherwise defaults to default value equality

T

The value to check

boolean

True if value equals default