getOptionDecoder
Call Signature
getOptionDecoder<
TTo
,TSize
>(item
,config
):FixedSizeDecoder
<Option
<TTo
>,TSize
>
Returns a decoder for optional values using the Option type.
This decoder deserializes an Option<T>
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 identified by zeroes. - If
noneValue
is a byte array,None
values match the provided constant.
Unlike getNullableDecoder, this decoder always outputs an Option type.
For more details, see getOptionCodec.
Type Parameters
Type Parameter | Description |
---|---|
TTo | The type of the main value being decoded. |
TSize extends number | - |
Parameters
Parameter | Type | Description |
---|---|---|
item | FixedSizeDecoder <TTo , TSize > | The decoder for the value that may be present. |
config | OptionCodecConfig <NumberDecoder > & object | Configuration options for decoding optional values. |
Returns
FixedSizeDecoder
<Option
<TTo
>, TSize
>
A FixedSizeDecoder
or VariableSizeDecoder
for decoding option values.
Example
Decoding an optional string with a size prefix.
See
Call Signature
getOptionDecoder<
TTo
>(item
,config
):FixedSizeDecoder
<Option
<TTo
>>
Returns a decoder for optional values using the Option type.
This decoder deserializes an Option<T>
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 identified by zeroes. - If
noneValue
is a byte array,None
values match the provided constant.
Unlike getNullableDecoder, this decoder always outputs an Option type.
For more details, see getOptionCodec.
Type Parameters
Type Parameter | Description |
---|---|
TTo | The type of the main value being decoded. |
Parameters
Parameter | Type | Description |
---|---|---|
item | FixedSizeDecoder <TTo > | The decoder for the value that may be present. |
config | OptionCodecConfig <FixedSizeNumberDecoder > & object | Configuration options for decoding optional values. |
Returns
FixedSizeDecoder
<Option
<TTo
>>
A FixedSizeDecoder
or VariableSizeDecoder
for decoding option values.
Example
Decoding an optional string with a size prefix.
See
Call Signature
getOptionDecoder<
TTo
>(item
,config
):VariableSizeDecoder
<Option
<TTo
>>
Returns a decoder for optional values using the Option type.
This decoder deserializes an Option<T>
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 identified by zeroes. - If
noneValue
is a byte array,None
values match the provided constant.
Unlike getNullableDecoder, this decoder always outputs an Option type.
For more details, see getOptionCodec.
Type Parameters
Type Parameter | Description |
---|---|
TTo | The type of the main value being decoded. |
Parameters
Parameter | Type | Description |
---|---|---|
item | FixedSizeDecoder <TTo > | The decoder for the value that may be present. |
config | OptionCodecConfig <NumberDecoder > & object | Configuration options for decoding optional values. |
Returns
VariableSizeDecoder
<Option
<TTo
>>
A FixedSizeDecoder
or VariableSizeDecoder
for decoding option values.
Example
Decoding an optional string with a size prefix.
See
Call Signature
getOptionDecoder<
TTo
>(item
,config?
):VariableSizeDecoder
<Option
<TTo
>>
Returns a decoder for optional values using the Option type.
This decoder deserializes an Option<T>
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 identified by zeroes. - If
noneValue
is a byte array,None
values match the provided constant.
Unlike getNullableDecoder, this decoder always outputs an Option type.
For more details, see getOptionCodec.
Type Parameters
Type Parameter | Description |
---|---|
TTo | The type of the main value being decoded. |
Parameters
Parameter | Type | Description |
---|---|---|
item | Decoder <TTo > | The decoder for the value that may be present. |
config? | OptionCodecConfig <NumberDecoder > & object | Configuration options for decoding optional values. |
Returns
VariableSizeDecoder
<Option
<TTo
>>
A FixedSizeDecoder
or VariableSizeDecoder
for decoding option values.
Example
Decoding an optional string with a size prefix.