Kit
Type aliases

OptionCodecConfig

OptionCodecConfig<TPrefix> = object

Defines the configuration options for Option codecs.

The getOptionCodec function behaves similarly to getNullableCodec but encodes Option<T> types instead of T | null types.

This configuration controls how None values are encoded and how presence is determined when decoding.

See

Type Parameters

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

Properties

noneValue?

optional noneValue: ReadonlyUint8Array | "zeroes"

Specifies how None values are represented in the encoded data.

  • By default, None values are omitted from encoding.
  • 'zeroes': The bytes allocated for the value are filled with zeroes. This requires a fixed-size codec for the item.
  • Custom byte array: None values are replaced with a predefined byte sequence. This results in a variable-size codec.

Default Value

No explicit noneValue is used; None values are omitted.


prefix?

optional prefix: TPrefix | null

The presence prefix used to distinguish between None and present values.

  • By default, a u8 prefix is used (0 = None, 1 = Some).
  • Custom number codec: Allows defining a different number size for the prefix.
  • null: No prefix is used; noneValue (if provided) determines None. If no noneValue is set, None is identified by the absence of bytes.

Default Value

u8 prefix.

On this page