MapCodecConfig

type MapCodecConfig<TPrefix> = object;

Defines the configuration options for map codecs.

The size option determines how the number of entries in the map is stored. It can be:

  • A NumberCodec to prefix the map with its size.
  • A fixed number of entries.
  • 'remainder', which infers the number of entries based on the remaining bytes. This option is only available for fixed-size keys and values.
  • An ArrayLikeCodecSentinelSize object, which ends the map when the bytes at the next entry position match a constant sentinel.

Type Parameters

Type ParameterDescription
TPrefix extends | NumberCodec | NumberDecoder | NumberEncoderA number codec, encoder, or decoder used for the size prefix.

Properties

requireSizePrefix?

optional requireSizePrefix?: boolean;

Whether a size prefix must be present when decoding.

By default, when the size is stored as a prefix and there are no bytes left to read, the decoder returns an empty map instead of failing. This allows new collections to be appended to existing data layouts without breaking the decoding of older data. Set this option to true to throw when the size prefix is missing.

Only applies when the size option is a number codec.

Default Value

false


size?

optional size?: ArrayLikeCodecSize<TPrefix>;

The size of the map.

Default Value

u32 prefix.

On this page