Skip to content

PrimitiveModelCodec

Defined in: packages/common/src/codecs/models/primitive-model.ts:4

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

T = unknown

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

TWire = T

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

new PrimitiveModelCodec<T, TWire>(metadata): PrimitiveModelCodec<T, TWire>

Defined in: packages/common/src/codecs/models/primitive-model.ts:7

PrimitiveModelMetadata | () => PrimitiveModelMetadata

PrimitiveModelCodec<T, TWire>

Codec.constructor

decode(value, format): T

Defined in: packages/common/src/codecs/models/primitive-model.ts:38

Decode a value from wire format

The wire value

TWire | null | undefined

EncodingFormat

The wire format (json or msgpack)

T

The decoded application value

Codec.decode


decodeOptional(value, format): T | undefined

Defined in: packages/common/src/codecs/models/primitive-model.ts:43

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

The wire value

TWire | null | undefined

EncodingFormat

The wire format (json or msgpack)

T | undefined

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

Codec.decodeOptional


defaultValue(): T

Defined in: packages/common/src/codecs/models/primitive-model.ts:18

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

T

Codec.defaultValue


encode(value, format): TWire

Defined in: packages/common/src/codecs/models/primitive-model.ts:28

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)

TWire

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

Codec.encode


encodeOptional(value, format): TWire | undefined

Defined in: packages/common/src/codecs/models/primitive-model.ts:33

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

The application value

T | null | undefined

EncodingFormat

The wire format (json or msgpack)

TWire | undefined

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

Codec.encodeOptional


isDefaultValue(value): boolean

Defined in: packages/common/src/codecs/models/primitive-model.ts:23

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

Codec.isDefaultValue