Skip to content

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.
  • Codec<Map<K, V>, Map<KEncoded, VEncoded> | Record<string, VEncoded>>

K

V

KEncoded = K

VEncoded = V

new MapCodec<K, V, KEncoded, VEncoded>(keyCodec, valueCodec): MapCodec<K, V, KEncoded, VEncoded>

Defined in: packages/common/src/codecs/composite/map.ts:15

Codec<K, KEncoded>

Codec<V, VEncoded>

MapCodec<K, V, KEncoded, VEncoded>

Codec.constructor

decode(value, format): Map

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

Decode a value from wire format

The wire value

Map<KEncoded, VEncoded> | Record<string, VEncoded> | null | undefined

EncodingFormat

The wire format (json or msgpack)

Map

The decoded application value

Codec.decode


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)

The wire value

Map<KEncoded, VEncoded> | Record<string, VEncoded> | null | undefined

EncodingFormat

The wire format (json or msgpack)

Map<K, V> | undefined

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

Codec.decodeOptional


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)

Map<K, V>

Codec.defaultValue


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

The application value

Map<K, V> | null | undefined

EncodingFormat

The wire format (json or msgpack)

Map<KEncoded, VEncoded> | Record<string, VEncoded>

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

Codec.encode


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.

The application value

Map<K, V> | null | undefined

EncodingFormat

The wire format (json or msgpack)

Map<KEncoded, VEncoded> | Record<string, VEncoded> | 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/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

Map<K, V>

The value to check

boolean

True if value equals default

Codec.isDefaultValue