ArrayCodecConfig

type ArrayCodecConfig<TPrefix> = object;

Defines the configuration options for array codecs.

Type Parameters

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

Properties

description?

optional description?: string;

An optional description for the codec, that will be used in error messages.


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 array 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>;

Specifies how the size of the array is determined.

  • A NumberCodec, NumberDecoder, or NumberEncoder stores a size prefix before encoding the array.
  • A number enforces a fixed number of elements.
  • "remainder" uses all remaining bytes to infer the array length (only for fixed-size items).
  • An ArrayLikeCodecSentinelSize object ends the array when the bytes at the next item position match a constant sentinel.

Default Value

A u32 size prefix.

On this page