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).
Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”T
The application/runtime type (e.g., bigint, string, Uint8Array)
TEncoded
Section titled “TEncoded”TEncoded = T
The wire format type (may differ based on format, e.g., bigint → string in JSON)
TWireEncoded
Section titled “TWireEncoded”TWireEncoded = TEncoded
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Codec<
T,TEncoded,TWireEncoded>():Codec<T,TEncoded,TWireEncoded>
Returns
Section titled “Returns”Codec<T, TEncoded, TWireEncoded>
Methods
Section titled “Methods”decode()
Section titled “decode()”decode(
value,format):T
Defined in: packages/common/src/codecs/codec.ts:46
Decode a value from wire format
Parameters
Section titled “Parameters”The wire value
TWireEncoded | null | undefined
format
Section titled “format”The wire format (json or msgpack)
Returns
Section titled “Returns”T
The decoded application value
decodeOptional()
Section titled “decodeOptional()”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)
Parameters
Section titled “Parameters”The wire value
TWireEncoded | null | undefined
format
Section titled “format”The wire format (json or msgpack)
Returns
Section titled “Returns”T | undefined
The decoded application value, or undefined if wire value was undefined
defaultValue()
Section titled “defaultValue()”
abstractdefaultValue():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)
Returns
Section titled “Returns”T
encode()
Section titled “encode()”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
Parameters
Section titled “Parameters”The application value
T | null | undefined
format
Section titled “format”The wire format (json or msgpack)
Returns
Section titled “Returns”TEncoded
The encoded value, or the default if it is undefined or null
encodeOptional()
Section titled “encodeOptional()”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.
Parameters
Section titled “Parameters”The application value
T | null | undefined
format
Section titled “format”The wire format (json or msgpack)
Returns
Section titled “Returns”TEncoded | undefined
The encoded value, or undefined if it equals the default (will be omitted)
isDefaultValue()
Section titled “isDefaultValue()”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
Parameters
Section titled “Parameters”T
The value to check
Returns
Section titled “Returns”boolean
True if value equals default