SetCodecConfig

type SetCodecConfig<TPrefix> = object;

Defines the configuration options for set codecs.

This configuration allows specifying how the size of the set is encoded. The size option can be:

  • A NumberCodec, NumberEncoder, or NumberDecoder to store the size as a prefix.
  • A fixed number of items, enforcing a strict length.
  • The string 'remainder' to infer the set size from the remaining bytes (only for fixed-size items).
  • An ArrayLikeCodecSentinelSize object to end the set when the bytes at the next item position match a constant sentinel.

Type Parameters

Type ParameterDescription
TPrefix extends | NumberCodec | NumberDecoder | NumberEncoderThe type used for encoding the size of the set.

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 set 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 encoding strategy for the set.

Default Value

Uses a u32 prefix.

On this page