Kit
Functions

getMapEncoder

Call Signature

getMapEncoder<TFromKey, TFromValue>(key, value, config): FixedSizeEncoder<Map<TFromKey, TFromValue>, 0>

Returns an encoder for maps.

This encoder serializes maps where the keys and values are encoded using the provided key and value encoders. The number of entries is determined by the size configuration.

For more details, see getMapCodec.

Type Parameters

Type ParameterDescription
TFromKeyThe type of the keys before encoding.
TFromValueThe type of the values before encoding.

Parameters

ParameterTypeDescription
keyEncoder<TFromKey>The encoder for the map's keys.
valueEncoder<TFromValue>The encoder for the map's values.
configMapCodecConfig<NumberEncoder> & objectConfiguration options for encoding the map.

Returns

FixedSizeEncoder<Map<TFromKey, TFromValue>, 0>

A FixedSizeEncoder or VariableSizeEncoder for encoding maps.

Example

Encoding a map with a u32 size prefix.

const encoder = getMapEncoder(fixCodecSize(getUtf8Encoder(), 5), getU8Encoder());
const bytes = encoder.encode(new Map([['alice', 42], ['bob', 5]]));
// 0x02000000616c6963652a626f62000005
//   |       |         | |         └── Value (5)
//   |       |         | └── Key ("bob", 5 bytes fixed, null-padded)
//   |       |         └── Value (42)
//   |       └── Key ("alice", 5 bytes fixed)
//   └── 4-byte prefix (2 entries)

See

getMapCodec

Call Signature

getMapEncoder<TFromKey, TFromValue>(key, value, config): FixedSizeEncoder<Map<TFromKey, TFromValue>>

Returns an encoder for maps.

This encoder serializes maps where the keys and values are encoded using the provided key and value encoders. The number of entries is determined by the size configuration.

For more details, see getMapCodec.

Type Parameters

Type ParameterDescription
TFromKeyThe type of the keys before encoding.
TFromValueThe type of the values before encoding.

Parameters

ParameterTypeDescription
keyFixedSizeEncoder<TFromKey>The encoder for the map's keys.
valueFixedSizeEncoder<TFromValue>The encoder for the map's values.
configMapCodecConfig<NumberEncoder> & objectConfiguration options for encoding the map.

Returns

FixedSizeEncoder<Map<TFromKey, TFromValue>>

A FixedSizeEncoder or VariableSizeEncoder for encoding maps.

Example

Encoding a map with a u32 size prefix.

const encoder = getMapEncoder(fixCodecSize(getUtf8Encoder(), 5), getU8Encoder());
const bytes = encoder.encode(new Map([['alice', 42], ['bob', 5]]));
// 0x02000000616c6963652a626f62000005
//   |       |         | |         └── Value (5)
//   |       |         | └── Key ("bob", 5 bytes fixed, null-padded)
//   |       |         └── Value (42)
//   |       └── Key ("alice", 5 bytes fixed)
//   └── 4-byte prefix (2 entries)

See

getMapCodec

Call Signature

getMapEncoder<TFromKey, TFromValue>(key, value, config?): VariableSizeEncoder<Map<TFromKey, TFromValue>>

Returns an encoder for maps.

This encoder serializes maps where the keys and values are encoded using the provided key and value encoders. The number of entries is determined by the size configuration.

For more details, see getMapCodec.

Type Parameters

Type ParameterDescription
TFromKeyThe type of the keys before encoding.
TFromValueThe type of the values before encoding.

Parameters

ParameterTypeDescription
keyEncoder<TFromKey>The encoder for the map's keys.
valueEncoder<TFromValue>The encoder for the map's values.
config?MapCodecConfig<NumberEncoder>Configuration options for encoding the map.

Returns

VariableSizeEncoder<Map<TFromKey, TFromValue>>

A FixedSizeEncoder or VariableSizeEncoder for encoding maps.

Example

Encoding a map with a u32 size prefix.

const encoder = getMapEncoder(fixCodecSize(getUtf8Encoder(), 5), getU8Encoder());
const bytes = encoder.encode(new Map([['alice', 42], ['bob', 5]]));
// 0x02000000616c6963652a626f62000005
//   |       |         | |         └── Value (5)
//   |       |         | └── Key ("bob", 5 bytes fixed, null-padded)
//   |       |         └── Value (42)
//   |       └── Key ("alice", 5 bytes fixed)
//   └── 4-byte prefix (2 entries)

See

getMapCodec

On this page