MapCodec
Defined in: packages/common/src/codecs/composite/map.ts:12
Map codec - handles Maps with any key type (including Uint8Array, bigint, number) Depending on the encoding format, the map is encoded differently:
- json: Supports string and bigint keys. The map is represented as an object when encoding. Bigint keys are converted to/from strings (e.g., 1n becomes “1”). An exception is thrown upon encountering an unsupported key type.
- msgpack: Preserves key types and is represented as a Map when encoding.
Extends
Section titled “Extends”Codec<Map<K,V>,Map<KEncoded,VEncoded> |Record<string,VEncoded>>
Type Parameters
Section titled “Type Parameters”K
V
KEncoded
Section titled “KEncoded”KEncoded = K
VEncoded
Section titled “VEncoded”VEncoded = V
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new MapCodec<
K,V,KEncoded,VEncoded>(keyCodec,valueCodec):MapCodec<K,V,KEncoded,VEncoded>
Defined in: packages/common/src/codecs/composite/map.ts:15
Parameters
Section titled “Parameters”keyCodec
Section titled “keyCodec”Codec<K, KEncoded>
valueCodec
Section titled “valueCodec”Codec<V, VEncoded>
Returns
Section titled “Returns”MapCodec<K, V, KEncoded, VEncoded>
Overrides
Section titled “Overrides”Methods
Section titled “Methods”decode()
Section titled “decode()”decode(
value,format):Map
Defined in: packages/common/src/codecs/codec.ts:46
Decode a value from wire format
Parameters
Section titled “Parameters”The wire value
Map<KEncoded, VEncoded> | Record<string, VEncoded> | null | undefined
format
Section titled “format”The wire format (json or msgpack)
Returns
Section titled “Returns”Map
The decoded application value
Inherited from
Section titled “Inherited from”decodeOptional()
Section titled “decodeOptional()”decodeOptional(
value,format):Map<K,V> |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
Map<KEncoded, VEncoded> | Record<string, VEncoded> | null | undefined
format
Section titled “format”The wire format (json or msgpack)
Returns
Section titled “Returns”Map<K, V> | undefined
The decoded application value, or undefined if wire value was undefined
Inherited from
Section titled “Inherited from”defaultValue()
Section titled “defaultValue()”defaultValue():
Map<K,V>
Defined in: packages/common/src/codecs/composite/map.ts:24
The default value for this type (used to determine if a value should be omitted during encoding)
Returns
Section titled “Returns”Map<K, V>
Overrides
Section titled “Overrides”encode()
Section titled “encode()”encode(
value,format):Map<KEncoded,VEncoded> |Record<string,VEncoded>
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
Map<K, V> | null | undefined
format
Section titled “format”The wire format (json or msgpack)
Returns
Section titled “Returns”Map<KEncoded, VEncoded> | Record<string, VEncoded>
The encoded value, or the default if it is undefined or null
Inherited from
Section titled “Inherited from”encodeOptional()
Section titled “encodeOptional()”encodeOptional(
value,format):Map<KEncoded,VEncoded> |Record<string,VEncoded> |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
Map<K, V> | null | undefined
format
Section titled “format”The wire format (json or msgpack)
Returns
Section titled “Returns”Map<KEncoded, VEncoded> | Record<string, VEncoded> | undefined
The encoded value, or undefined if it equals the default (will be omitted)
Inherited from
Section titled “Inherited from”isDefaultValue()
Section titled “isDefaultValue()”isDefaultValue(
value):boolean
Defined in: packages/common/src/codecs/composite/map.ts:84
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”Map<K, V>
The value to check
Returns
Section titled “Returns”boolean
True if value equals default