transformEncoder
Call Signature
Transforms an encoder by mapping its input values.
This function takes an existing Encoder<A> and returns an Encoder<B>, allowing values of type B
to be converted into values of type A before encoding. The transformation is applied via the unmap function.
This is useful for handling type conversions, applying default values, or structuring data before encoding.
For more details, see transformCodec.
Type Parameters
| Type Parameter | Description |
|---|---|
TOldFrom | The original type expected by the encoder. |
TNewFrom | The new type that will be transformed before encoding. |
TSize extends number | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
encoder | FixedSizeEncoder<TOldFrom, TSize> | The encoder to transform. |
unmap | (value) => TOldFrom | A function that converts values of TNewFrom into TOldFrom before encoding. |
Returns
FixedSizeEncoder<TNewFrom, TSize>
A new encoder that accepts TNewFrom values and transforms them before encoding.
Example
Encoding a string by counting its characters and storing the length as a u32.
See
Call Signature
Transforms an encoder by mapping its input values.
This function takes an existing Encoder<A> and returns an Encoder<B>, allowing values of type B
to be converted into values of type A before encoding. The transformation is applied via the unmap function.
This is useful for handling type conversions, applying default values, or structuring data before encoding.
For more details, see transformCodec.
Type Parameters
| Type Parameter | Description |
|---|---|
TOldFrom | The original type expected by the encoder. |
TNewFrom | The new type that will be transformed before encoding. |
Parameters
| Parameter | Type | Description |
|---|---|---|
encoder | VariableSizeEncoder<TOldFrom> | The encoder to transform. |
unmap | (value) => TOldFrom | A function that converts values of TNewFrom into TOldFrom before encoding. |
Returns
VariableSizeEncoder<TNewFrom>
A new encoder that accepts TNewFrom values and transforms them before encoding.
Example
Encoding a string by counting its characters and storing the length as a u32.
See
Call Signature
Transforms an encoder by mapping its input values.
This function takes an existing Encoder<A> and returns an Encoder<B>, allowing values of type B
to be converted into values of type A before encoding. The transformation is applied via the unmap function.
This is useful for handling type conversions, applying default values, or structuring data before encoding.
For more details, see transformCodec.
Type Parameters
| Type Parameter | Description |
|---|---|
TOldFrom | The original type expected by the encoder. |
TNewFrom | The new type that will be transformed before encoding. |
Parameters
| Parameter | Type | Description |
|---|---|---|
encoder | Encoder<TOldFrom> | The encoder to transform. |
unmap | (value) => TOldFrom | A function that converts values of TNewFrom into TOldFrom before encoding. |
Returns
Encoder<TNewFrom>
A new encoder that accepts TNewFrom values and transforms them before encoding.
Example
Encoding a string by counting its characters and storing the length as a u32.