Kit
Functions

getNullableEncoder

Call Signature

getNullableEncoder<TFrom, TSize>(item, config): FixedSizeEncoder<null | TFrom, TSize>

Returns an encoder for optional values, allowing null values to be encoded.

This encoder serializes 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 encoded as zeroes.
  • If noneValue is a byte array, null values are replaced with the provided constant.

For more details, see getNullableCodec.

Type Parameters

Type ParameterDescription
TFromThe type of the main value being encoded.
TSize extends number-

Parameters

ParameterTypeDescription
itemFixedSizeEncoder<TFrom, TSize>The encoder for the value that may be present.
configNullableCodecConfig<NumberEncoder> & objectConfiguration options for encoding optional values.

Returns

FixedSizeEncoder<null | TFrom, TSize>

A FixedSizeEncoder or VariableSizeEncoder for encoding nullable values.

Example

Encoding an optional number.

const encoder = getNullableEncoder(getU32Encoder());
 
encoder.encode(null); // 0x00
encoder.encode(42);   // 0x012a000000

See

getNullableCodec

Call Signature

getNullableEncoder<TFrom>(item, config): FixedSizeEncoder<null | TFrom>

Returns an encoder for optional values, allowing null values to be encoded.

This encoder serializes 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 encoded as zeroes.
  • If noneValue is a byte array, null values are replaced with the provided constant.

For more details, see getNullableCodec.

Type Parameters

Type ParameterDescription
TFromThe type of the main value being encoded.

Parameters

ParameterTypeDescription
itemFixedSizeEncoder<TFrom>The encoder for the value that may be present.
configNullableCodecConfig<FixedSizeNumberEncoder> & objectConfiguration options for encoding optional values.

Returns

FixedSizeEncoder<null | TFrom>

A FixedSizeEncoder or VariableSizeEncoder for encoding nullable values.

Example

Encoding an optional number.

const encoder = getNullableEncoder(getU32Encoder());
 
encoder.encode(null); // 0x00
encoder.encode(42);   // 0x012a000000

See

getNullableCodec

Call Signature

getNullableEncoder<TFrom>(item, config): VariableSizeEncoder<null | TFrom>

Returns an encoder for optional values, allowing null values to be encoded.

This encoder serializes 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 encoded as zeroes.
  • If noneValue is a byte array, null values are replaced with the provided constant.

For more details, see getNullableCodec.

Type Parameters

Type ParameterDescription
TFromThe type of the main value being encoded.

Parameters

ParameterTypeDescription
itemFixedSizeEncoder<TFrom>The encoder for the value that may be present.
configNullableCodecConfig<NumberEncoder> & objectConfiguration options for encoding optional values.

Returns

VariableSizeEncoder<null | TFrom>

A FixedSizeEncoder or VariableSizeEncoder for encoding nullable values.

Example

Encoding an optional number.

const encoder = getNullableEncoder(getU32Encoder());
 
encoder.encode(null); // 0x00
encoder.encode(42);   // 0x012a000000

See

getNullableCodec

Call Signature

getNullableEncoder<TFrom>(item, config?): VariableSizeEncoder<null | TFrom>

Returns an encoder for optional values, allowing null values to be encoded.

This encoder serializes 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 encoded as zeroes.
  • If noneValue is a byte array, null values are replaced with the provided constant.

For more details, see getNullableCodec.

Type Parameters

Type ParameterDescription
TFromThe type of the main value being encoded.

Parameters

ParameterTypeDescription
itemEncoder<TFrom>The encoder for the value that may be present.
config?NullableCodecConfig<NumberEncoder> & objectConfiguration options for encoding optional values.

Returns

VariableSizeEncoder<null | TFrom>

A FixedSizeEncoder or VariableSizeEncoder for encoding nullable values.

Example

Encoding an optional number.

const encoder = getNullableEncoder(getU32Encoder());
 
encoder.encode(null); // 0x00
encoder.encode(42);   // 0x012a000000

See

getNullableCodec

On this page