getLiteralUnionEncoder
Call Signature
Returns an encoder for literal unions.
This encoder serializes a value from a predefined set of literals
as a numerical index representing its position in the variants array.
For more details, see getLiteralUnionCodec.
Type Parameters
| Type Parameter | Description |
|---|---|
TVariants extends readonly Variant[] | A tuple of allowed literal values. |
Parameters
| Parameter | Type | Description |
|---|---|---|
variants | TVariants | The possible literal values for the union. |
Returns
FixedSizeEncoder<GetTypeFromVariants<TVariants>, 1>
A FixedSizeEncoder or VariableSizeEncoder for encoding literal unions.
Example
Encoding a union of string literals.
See
Call Signature
Returns an encoder for literal unions.
This encoder serializes a value from a predefined set of literals
as a numerical index representing its position in the variants array.
For more details, see getLiteralUnionCodec.
Type Parameters
| Type Parameter | Description |
|---|---|
TVariants extends readonly Variant[] | A tuple of allowed literal values. |
TSize extends number | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
variants | TVariants | The possible literal values for the union. |
config | LiteralUnionCodecConfig<NumberEncoder> & object | Configuration options for encoding the literal union. |
Returns
FixedSizeEncoder<GetTypeFromVariants<TVariants>, TSize>
A FixedSizeEncoder or VariableSizeEncoder for encoding literal unions.
Example
Encoding a union of string literals.
See
Call Signature
Returns an encoder for literal unions.
This encoder serializes a value from a predefined set of literals
as a numerical index representing its position in the variants array.
For more details, see getLiteralUnionCodec.
Type Parameters
| Type Parameter | Description |
|---|---|
TVariants extends readonly Variant[] | A tuple of allowed literal values. |
Parameters
| Parameter | Type | Description |
|---|---|---|
variants | TVariants | The possible literal values for the union. |
config? | LiteralUnionCodecConfig<NumberEncoder> | Configuration options for encoding the literal union. |
Returns
VariableSizeEncoder<GetTypeFromVariants<TVariants>>
A FixedSizeEncoder or VariableSizeEncoder for encoding literal unions.
Example
Encoding a union of string literals.