getOptionEncoder
Call Signature
Returns an encoder for optional values using the Option type.
This encoder serializes an OptionOrNullable value using a configurable approach:
- By default, a
u8
prefix is used (0 = None
,1 = Some
). This can be customized or disabled. - If
noneValue: 'zeroes'
is set, None values are encoded as zeroes. - If
noneValue
is a byte array, None values are replaced with the provided constant.
Unlike getNullableEncoder, this encoder accepts both Option and Nullable values.
For more details, see getOptionCodec.
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 | OptionCodecConfig <NumberEncoder > & object | Configuration options for encoding optional values. |
Returns
FixedSizeEncoder
<OptionOrNullable
<TFrom
>, TSize
>
A FixedSizeEncoder
or VariableSizeEncoder
for encoding option values.
Example
Encoding an optional string.
See
Call Signature
Returns an encoder for optional values using the Option type.
This encoder serializes an OptionOrNullable value using a configurable approach:
- By default, a
u8
prefix is used (0 = None
,1 = Some
). This can be customized or disabled. - If
noneValue: 'zeroes'
is set, None values are encoded as zeroes. - If
noneValue
is a byte array, None values are replaced with the provided constant.
Unlike getNullableEncoder, this encoder accepts both Option and Nullable values.
For more details, see getOptionCodec.
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 | OptionCodecConfig <FixedSizeNumberEncoder > & object | Configuration options for encoding optional values. |
Returns
FixedSizeEncoder
<OptionOrNullable
<TFrom
>>
A FixedSizeEncoder
or VariableSizeEncoder
for encoding option values.
Example
Encoding an optional string.
See
Call Signature
Returns an encoder for optional values using the Option type.
This encoder serializes an OptionOrNullable value using a configurable approach:
- By default, a
u8
prefix is used (0 = None
,1 = Some
). This can be customized or disabled. - If
noneValue: 'zeroes'
is set, None values are encoded as zeroes. - If
noneValue
is a byte array, None values are replaced with the provided constant.
Unlike getNullableEncoder, this encoder accepts both Option and Nullable values.
For more details, see getOptionCodec.
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 | OptionCodecConfig <NumberEncoder > & object | Configuration options for encoding optional values. |
Returns
VariableSizeEncoder
<OptionOrNullable
<TFrom
>>
A FixedSizeEncoder
or VariableSizeEncoder
for encoding option values.
Example
Encoding an optional string.
See
Call Signature
Returns an encoder for optional values using the Option type.
This encoder serializes an OptionOrNullable value using a configurable approach:
- By default, a
u8
prefix is used (0 = None
,1 = Some
). This can be customized or disabled. - If
noneValue: 'zeroes'
is set, None values are encoded as zeroes. - If
noneValue
is a byte array, None values are replaced with the provided constant.
Unlike getNullableEncoder, this encoder accepts both Option and Nullable values.
For more details, see getOptionCodec.
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? | OptionCodecConfig <NumberEncoder > & object | Configuration options for encoding optional values. |
Returns
VariableSizeEncoder
<OptionOrNullable
<TFrom
>>
A FixedSizeEncoder
or VariableSizeEncoder
for encoding option values.
Example
Encoding an optional string.