getNullableCodec
Call Signature
Returns a codec for encoding and decoding optional values, allowing null values to be handled.
This codec serializes and deserializes optional values using a configurable approach:
- By default, a
u8prefix is used (0 =null, 1 = present). This can be customized using a custom number codec or even disabled by setting theprefixtonull. - If
noneValue: 'zeroes'is set,nullvalues are encoded/decoded as zeroes. - If
noneValueis a byte array,nullvalues are represented by the provided constant.
For more details on the configuration options, see NullableCodecConfig.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the main value being encoded. |
TTo | The type of the main value being decoded. |
TSize extends number | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
item | FixedSizeCodec<TFrom, TTo, TSize> | The codec for the value that may be present. |
config | NullableCodecConfig<NumberCodec> & object | Configuration options for encoding and decoding optional values. |
Returns
FixedSizeCodec<TFrom | null, TTo | null, TSize>
A FixedSizeCodec or VariableSizeCodec for encoding and decoding nullable values.
Examples
Encoding and decoding an optional number using a u8 prefix (default).
Encoding and decoding an optional number using a fixed-size codec, by filling null values with zeroes.
Encoding and decoding null values with zeroes and no prefix.
Encoding and decoding null values with a custom byte sequence and no prefix.
Identifying null values by the absence of bytes.
Remarks
Separate getNullableEncoder and getNullableDecoder functions are available.
See
Call Signature
Returns a codec for encoding and decoding optional values, allowing null values to be handled.
This codec serializes and deserializes optional values using a configurable approach:
- By default, a
u8prefix is used (0 =null, 1 = present). This can be customized using a custom number codec or even disabled by setting theprefixtonull. - If
noneValue: 'zeroes'is set,nullvalues are encoded/decoded as zeroes. - If
noneValueis a byte array,nullvalues are represented by the provided constant.
For more details on the configuration options, see NullableCodecConfig.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
TFrom | - | The type of the main value being encoded. |
TTo | TFrom | The type of the main value being decoded. |
Parameters
| Parameter | Type | Description |
|---|---|---|
item | FixedSizeCodec<TFrom, TTo> | The codec for the value that may be present. |
config | NullableCodecConfig<FixedSizeNumberCodec> & object | Configuration options for encoding and decoding optional values. |
Returns
FixedSizeCodec<TFrom | null, TTo | null>
A FixedSizeCodec or VariableSizeCodec for encoding and decoding nullable values.
Examples
Encoding and decoding an optional number using a u8 prefix (default).
Encoding and decoding an optional number using a fixed-size codec, by filling null values with zeroes.
Encoding and decoding null values with zeroes and no prefix.
Encoding and decoding null values with a custom byte sequence and no prefix.
Identifying null values by the absence of bytes.
Remarks
Separate getNullableEncoder and getNullableDecoder functions are available.
See
Call Signature
Returns a codec for encoding and decoding optional values, allowing null values to be handled.
This codec serializes and deserializes optional values using a configurable approach:
- By default, a
u8prefix is used (0 =null, 1 = present). This can be customized using a custom number codec or even disabled by setting theprefixtonull. - If
noneValue: 'zeroes'is set,nullvalues are encoded/decoded as zeroes. - If
noneValueis a byte array,nullvalues are represented by the provided constant.
For more details on the configuration options, see NullableCodecConfig.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
TFrom | - | The type of the main value being encoded. |
TTo | TFrom | The type of the main value being decoded. |
Parameters
| Parameter | Type | Description |
|---|---|---|
item | FixedSizeCodec<TFrom, TTo> | The codec for the value that may be present. |
config | NullableCodecConfig<NumberCodec> & object | Configuration options for encoding and decoding optional values. |
Returns
VariableSizeCodec<TFrom | null, TTo | null>
A FixedSizeCodec or VariableSizeCodec for encoding and decoding nullable values.
Examples
Encoding and decoding an optional number using a u8 prefix (default).
Encoding and decoding an optional number using a fixed-size codec, by filling null values with zeroes.
Encoding and decoding null values with zeroes and no prefix.
Encoding and decoding null values with a custom byte sequence and no prefix.
Identifying null values by the absence of bytes.
Remarks
Separate getNullableEncoder and getNullableDecoder functions are available.
See
Call Signature
Returns a codec for encoding and decoding optional values, allowing null values to be handled.
This codec serializes and deserializes optional values using a configurable approach:
- By default, a
u8prefix is used (0 =null, 1 = present). This can be customized using a custom number codec or even disabled by setting theprefixtonull. - If
noneValue: 'zeroes'is set,nullvalues are encoded/decoded as zeroes. - If
noneValueis a byte array,nullvalues are represented by the provided constant.
For more details on the configuration options, see NullableCodecConfig.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
TFrom | - | The type of the main value being encoded. |
TTo | TFrom | The type of the main value being decoded. |
Parameters
| Parameter | Type | Description |
|---|---|---|
item | Codec<TFrom, TTo> | The codec for the value that may be present. |
config? | NullableCodecConfig<NumberCodec> & object | Configuration options for encoding and decoding optional values. |
Returns
VariableSizeCodec<TFrom | null, TTo | null>
A FixedSizeCodec or VariableSizeCodec for encoding and decoding nullable values.
Examples
Encoding and decoding an optional number using a u8 prefix (default).
Encoding and decoding an optional number using a fixed-size codec, by filling null values with zeroes.
Encoding and decoding null values with zeroes and no prefix.
Encoding and decoding null values with a custom byte sequence and no prefix.
Identifying null values by the absence of bytes.
Remarks
Separate getNullableEncoder and getNullableDecoder functions are available.