Kit
Functions

getNullableDecoder

Call Signature

getNullableDecoder<TTo, TSize>(item, config): FixedSizeDecoder<null | TTo, TSize>

Returns a decoder for optional values, allowing null values to be recognized.

This decoder deserializes an optional value using a configurable approach:

  • By default, a u8 prefix is used (0 = null, 1 = present). This can be customized or disabled.
  • If noneValue: 'zeroes' is set, null values are identified by zeroes.
  • If noneValue is a byte array, null values match the provided constant.

For more details, see getNullableCodec.

Type Parameters

Type ParameterDescription
TToThe type of the main value being decoded.
TSize extends number-

Parameters

ParameterTypeDescription
itemFixedSizeDecoder<TTo, TSize>The decoder for the value that may be present.
configNullableCodecConfig<NumberDecoder> & objectConfiguration options for decoding optional values.

Returns

FixedSizeDecoder<null | TTo, TSize>

A FixedSizeDecoder or VariableSizeDecoder for decoding nullable values.

Example

Decoding an optional number.

const decoder = getNullableDecoder(getU32Decoder());
 
decoder.decode(new Uint8Array([0x00])); // null
decoder.decode(new Uint8Array([0x01, 0x2a, 0x00, 0x00, 0x00])); // 42

See

getNullableCodec

Call Signature

getNullableDecoder<TTo>(item, config): FixedSizeDecoder<null | TTo>

Returns a decoder for optional values, allowing null values to be recognized.

This decoder deserializes an optional value using a configurable approach:

  • By default, a u8 prefix is used (0 = null, 1 = present). This can be customized or disabled.
  • If noneValue: 'zeroes' is set, null values are identified by zeroes.
  • If noneValue is a byte array, null values match the provided constant.

For more details, see getNullableCodec.

Type Parameters

Type ParameterDescription
TToThe type of the main value being decoded.

Parameters

ParameterTypeDescription
itemFixedSizeDecoder<TTo>The decoder for the value that may be present.
configNullableCodecConfig<FixedSizeNumberDecoder> & objectConfiguration options for decoding optional values.

Returns

FixedSizeDecoder<null | TTo>

A FixedSizeDecoder or VariableSizeDecoder for decoding nullable values.

Example

Decoding an optional number.

const decoder = getNullableDecoder(getU32Decoder());
 
decoder.decode(new Uint8Array([0x00])); // null
decoder.decode(new Uint8Array([0x01, 0x2a, 0x00, 0x00, 0x00])); // 42

See

getNullableCodec

Call Signature

getNullableDecoder<TTo>(item, config): VariableSizeDecoder<null | TTo>

Returns a decoder for optional values, allowing null values to be recognized.

This decoder deserializes an optional value using a configurable approach:

  • By default, a u8 prefix is used (0 = null, 1 = present). This can be customized or disabled.
  • If noneValue: 'zeroes' is set, null values are identified by zeroes.
  • If noneValue is a byte array, null values match the provided constant.

For more details, see getNullableCodec.

Type Parameters

Type ParameterDescription
TToThe type of the main value being decoded.

Parameters

ParameterTypeDescription
itemFixedSizeDecoder<TTo>The decoder for the value that may be present.
configNullableCodecConfig<NumberDecoder> & objectConfiguration options for decoding optional values.

Returns

VariableSizeDecoder<null | TTo>

A FixedSizeDecoder or VariableSizeDecoder for decoding nullable values.

Example

Decoding an optional number.

const decoder = getNullableDecoder(getU32Decoder());
 
decoder.decode(new Uint8Array([0x00])); // null
decoder.decode(new Uint8Array([0x01, 0x2a, 0x00, 0x00, 0x00])); // 42

See

getNullableCodec

Call Signature

getNullableDecoder<TTo>(item, config?): VariableSizeDecoder<null | TTo>

Returns a decoder for optional values, allowing null values to be recognized.

This decoder deserializes an optional value using a configurable approach:

  • By default, a u8 prefix is used (0 = null, 1 = present). This can be customized or disabled.
  • If noneValue: 'zeroes' is set, null values are identified by zeroes.
  • If noneValue is a byte array, null values match the provided constant.

For more details, see getNullableCodec.

Type Parameters

Type ParameterDescription
TToThe type of the main value being decoded.

Parameters

ParameterTypeDescription
itemDecoder<TTo>The decoder for the value that may be present.
config?NullableCodecConfig<NumberDecoder> & objectConfiguration options for decoding optional values.

Returns

VariableSizeDecoder<null | TTo>

A FixedSizeDecoder or VariableSizeDecoder for decoding nullable values.

Example

Decoding an optional number.

const decoder = getNullableDecoder(getU32Decoder());
 
decoder.decode(new Uint8Array([0x00])); // null
decoder.decode(new Uint8Array([0x01, 0x2a, 0x00, 0x00, 0x00])); // 42

See

getNullableCodec

On this page