getNullableEncoder
Call Signature
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
u8prefix is used (0 =null, 1 = present). This can be customized or disabled. - If
noneValue: 'zeroes'is set,nullvalues are encoded as zeroes. - If
noneValueis a byte array,nullvalues are replaced with the provided constant.
For more details, see getNullableCodec.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the main value being encoded. |
TSize extends number | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
item | FixedSizeEncoder<TFrom, TSize> | The encoder for the value that may be present. |
config | NullableCodecConfig<NumberEncoder> & object | Configuration options for encoding optional values. |
Returns
FixedSizeEncoder<TFrom | null, TSize>
A FixedSizeEncoder or VariableSizeEncoder for encoding nullable values.
Example
Encoding an optional number.
See
Call Signature
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
u8prefix is used (0 =null, 1 = present). This can be customized or disabled. - If
noneValue: 'zeroes'is set,nullvalues are encoded as zeroes. - If
noneValueis a byte array,nullvalues are replaced with the provided constant.
For more details, see getNullableCodec.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the main value being encoded. |
Parameters
| Parameter | Type | Description |
|---|---|---|
item | FixedSizeEncoder<TFrom> | The encoder for the value that may be present. |
config | NullableCodecConfig<FixedSizeNumberEncoder> & object | Configuration options for encoding optional values. |
Returns
FixedSizeEncoder<TFrom | null>
A FixedSizeEncoder or VariableSizeEncoder for encoding nullable values.
Example
Encoding an optional number.
See
Call Signature
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
u8prefix is used (0 =null, 1 = present). This can be customized or disabled. - If
noneValue: 'zeroes'is set,nullvalues are encoded as zeroes. - If
noneValueis a byte array,nullvalues are replaced with the provided constant.
For more details, see getNullableCodec.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the main value being encoded. |
Parameters
| Parameter | Type | Description |
|---|---|---|
item | FixedSizeEncoder<TFrom> | The encoder for the value that may be present. |
config | NullableCodecConfig<NumberEncoder> & object | Configuration options for encoding optional values. |
Returns
VariableSizeEncoder<TFrom | null>
A FixedSizeEncoder or VariableSizeEncoder for encoding nullable values.
Example
Encoding an optional number.
See
Call Signature
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
u8prefix is used (0 =null, 1 = present). This can be customized or disabled. - If
noneValue: 'zeroes'is set,nullvalues are encoded as zeroes. - If
noneValueis a byte array,nullvalues are replaced with the provided constant.
For more details, see getNullableCodec.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the main value being encoded. |
Parameters
| Parameter | Type | Description |
|---|---|---|
item | Encoder<TFrom> | The encoder for the value that may be present. |
config? | NullableCodecConfig<NumberEncoder> & object | Configuration options for encoding optional values. |
Returns
VariableSizeEncoder<TFrom | null>
A FixedSizeEncoder or VariableSizeEncoder for encoding nullable values.
Example
Encoding an optional number.