getOptionDecoder
Call Signature
Returns a decoder for optional values using the Option type.
This decoder deserializes an Option<T> value using a configurable approach:
- By default, a
u8prefix is used (0 = None,1 = Some). This can be customized or disabled. - If
noneValue: 'zeroes'is set,Nonevalues are identified by zeroes. - If
noneValueis a byte array,Nonevalues 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
Returns a decoder for optional values using the Option type.
This decoder deserializes an Option<T> value using a configurable approach:
- By default, a
u8prefix is used (0 = None,1 = Some). This can be customized or disabled. - If
noneValue: 'zeroes'is set,Nonevalues are identified by zeroes. - If
noneValueis a byte array,Nonevalues 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
Returns a decoder for optional values using the Option type.
This decoder deserializes an Option<T> value using a configurable approach:
- By default, a
u8prefix is used (0 = None,1 = Some). This can be customized or disabled. - If
noneValue: 'zeroes'is set,Nonevalues are identified by zeroes. - If
noneValueis a byte array,Nonevalues 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
Returns a decoder for optional values using the Option type.
This decoder deserializes an Option<T> value using a configurable approach:
- By default, a
u8prefix is used (0 = None,1 = Some). This can be customized or disabled. - If
noneValue: 'zeroes'is set,Nonevalues are identified by zeroes. - If
noneValueis a byte array,Nonevalues 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.