Kit
Functions

getMapDecoder

Call Signature

getMapDecoder<TToKey, TToValue>(key, value, config): FixedSizeDecoder<Map<TToKey, TToValue>, 0>

Returns a decoder for maps.

This decoder deserializes maps where the keys and values are decoded using the provided key and value decoders. The number of entries is determined by the size configuration.

For more details, see getMapCodec.

Type Parameters

Type ParameterDescription
TToKeyThe type of the keys after decoding.
TToValueThe type of the values after decoding.

Parameters

ParameterTypeDescription
keyDecoder<TToKey>The decoder for the map's keys.
valueDecoder<TToValue>The decoder for the map's values.
configMapCodecConfig<NumberDecoder> & objectConfiguration options for decoding the map.

Returns

FixedSizeDecoder<Map<TToKey, TToValue>, 0>

A FixedSizeDecoder or VariableSizeDecoder for decoding maps.

Example

Decoding a map with a u32 size prefix.

const decoder = getMapDecoder(fixCodecSize(getUtf8Decoder(), 5), getU8Decoder());
const map = decoder.decode(new Uint8Array([
  0x02,0x00,0x00,0x00,0x61,0x6c,0x69,0x63,0x65,0x2a,0x62,0x6f,0x62,0x00,0x00,0x05
]));
// new Map([['alice', 42], ['bob', 5]])

See

getMapCodec

Call Signature

getMapDecoder<TToKey, TToValue>(key, value, config): FixedSizeDecoder<Map<TToKey, TToValue>>

Returns a decoder for maps.

This decoder deserializes maps where the keys and values are decoded using the provided key and value decoders. The number of entries is determined by the size configuration.

For more details, see getMapCodec.

Type Parameters

Type ParameterDescription
TToKeyThe type of the keys after decoding.
TToValueThe type of the values after decoding.

Parameters

ParameterTypeDescription
keyFixedSizeDecoder<TToKey>The decoder for the map's keys.
valueFixedSizeDecoder<TToValue>The decoder for the map's values.
configMapCodecConfig<NumberDecoder> & objectConfiguration options for decoding the map.

Returns

FixedSizeDecoder<Map<TToKey, TToValue>>

A FixedSizeDecoder or VariableSizeDecoder for decoding maps.

Example

Decoding a map with a u32 size prefix.

const decoder = getMapDecoder(fixCodecSize(getUtf8Decoder(), 5), getU8Decoder());
const map = decoder.decode(new Uint8Array([
  0x02,0x00,0x00,0x00,0x61,0x6c,0x69,0x63,0x65,0x2a,0x62,0x6f,0x62,0x00,0x00,0x05
]));
// new Map([['alice', 42], ['bob', 5]])

See

getMapCodec

Call Signature

getMapDecoder<TToKey, TToValue>(key, value, config?): VariableSizeDecoder<Map<TToKey, TToValue>>

Returns a decoder for maps.

This decoder deserializes maps where the keys and values are decoded using the provided key and value decoders. The number of entries is determined by the size configuration.

For more details, see getMapCodec.

Type Parameters

Type ParameterDescription
TToKeyThe type of the keys after decoding.
TToValueThe type of the values after decoding.

Parameters

ParameterTypeDescription
keyDecoder<TToKey>The decoder for the map's keys.
valueDecoder<TToValue>The decoder for the map's values.
config?MapCodecConfig<NumberDecoder>Configuration options for decoding the map.

Returns

VariableSizeDecoder<Map<TToKey, TToValue>>

A FixedSizeDecoder or VariableSizeDecoder for decoding maps.

Example

Decoding a map with a u32 size prefix.

const decoder = getMapDecoder(fixCodecSize(getUtf8Decoder(), 5), getU8Decoder());
const map = decoder.decode(new Uint8Array([
  0x02,0x00,0x00,0x00,0x61,0x6c,0x69,0x63,0x65,0x2a,0x62,0x6f,0x62,0x00,0x00,0x05
]));
// new Map([['alice', 42], ['bob', 5]])

See

getMapCodec

On this page