transformCodec
Call Signature
Transforms a codec by mapping its input and output values.
This function takes an existing Codec<A, B> and returns a Codec<C, D>, allowing:
- Values of type
Cto be transformed intoAbefore encoding. - Values of type
Bto be transformed intoDafter decoding.
This is useful for adapting codecs to work with different representations, handling default values, or converting between primitive and structured types.
Type Parameters
| Type Parameter | Description |
|---|---|
TOldFrom | The original type expected by the codec. |
TNewFrom | The new type that will be transformed before encoding. |
TTo | - |
TSize extends number | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
codec | FixedSizeCodec<TOldFrom, TTo, TSize> | The codec to transform. |
unmap | (value) => TOldFrom | A function that converts values of TNewFrom into TOldFrom before encoding. |
Returns
FixedSizeCodec<TNewFrom, TTo, TSize>
A new codec that encodes TNewFrom and decodes into TNewTo.
Example
Mapping a u32 codec to encode string lengths and decode them into 'x' characters.
Remarks
If only input transformation is needed, use transformEncoder. If only output transformation is needed, use transformDecoder.
See
Call Signature
Transforms a codec by mapping its input and output values.
This function takes an existing Codec<A, B> and returns a Codec<C, D>, allowing:
- Values of type
Cto be transformed intoAbefore encoding. - Values of type
Bto be transformed intoDafter decoding.
This is useful for adapting codecs to work with different representations, handling default values, or converting between primitive and structured types.
Type Parameters
| Type Parameter | Description |
|---|---|
TOldFrom | The original type expected by the codec. |
TNewFrom | The new type that will be transformed before encoding. |
TTo | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
codec | VariableSizeCodec<TOldFrom, TTo> | The codec to transform. |
unmap | (value) => TOldFrom | A function that converts values of TNewFrom into TOldFrom before encoding. |
Returns
VariableSizeCodec<TNewFrom, TTo>
A new codec that encodes TNewFrom and decodes into TNewTo.
Example
Mapping a u32 codec to encode string lengths and decode them into 'x' characters.
Remarks
If only input transformation is needed, use transformEncoder. If only output transformation is needed, use transformDecoder.
See
Call Signature
Transforms a codec by mapping its input and output values.
This function takes an existing Codec<A, B> and returns a Codec<C, D>, allowing:
- Values of type
Cto be transformed intoAbefore encoding. - Values of type
Bto be transformed intoDafter decoding.
This is useful for adapting codecs to work with different representations, handling default values, or converting between primitive and structured types.
Type Parameters
| Type Parameter | Description |
|---|---|
TOldFrom | The original type expected by the codec. |
TNewFrom | The new type that will be transformed before encoding. |
TTo | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
codec | Codec<TOldFrom, TTo> | The codec to transform. |
unmap | (value) => TOldFrom | A function that converts values of TNewFrom into TOldFrom before encoding. |
Returns
Codec<TNewFrom, TTo>
A new codec that encodes TNewFrom and decodes into TNewTo.
Example
Mapping a u32 codec to encode string lengths and decode them into 'x' characters.
Remarks
If only input transformation is needed, use transformEncoder. If only output transformation is needed, use transformDecoder.
See
Call Signature
Transforms a codec by mapping its input and output values.
This function takes an existing Codec<A, B> and returns a Codec<C, D>, allowing:
- Values of type
Cto be transformed intoAbefore encoding. - Values of type
Bto be transformed intoDafter decoding.
This is useful for adapting codecs to work with different representations, handling default values, or converting between primitive and structured types.
Type Parameters
| Type Parameter | Description |
|---|---|
TOldFrom | The original type expected by the codec. |
TNewFrom | The new type that will be transformed before encoding. |
TOldTo | The original type returned by the codec. |
TNewTo | The new type that will be transformed after decoding. |
TSize extends number | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
codec | FixedSizeCodec<TOldFrom, TOldTo, TSize> | The codec to transform. |
unmap | (value) => TOldFrom | A function that converts values of TNewFrom into TOldFrom before encoding. |
map | (value, bytes, offset) => TNewTo | A function that converts values of TOldTo into TNewTo after decoding (optional). |
Returns
FixedSizeCodec<TNewFrom, TNewTo, TSize>
A new codec that encodes TNewFrom and decodes into TNewTo.
Example
Mapping a u32 codec to encode string lengths and decode them into 'x' characters.
Remarks
If only input transformation is needed, use transformEncoder. If only output transformation is needed, use transformDecoder.
See
Call Signature
Transforms a codec by mapping its input and output values.
This function takes an existing Codec<A, B> and returns a Codec<C, D>, allowing:
- Values of type
Cto be transformed intoAbefore encoding. - Values of type
Bto be transformed intoDafter decoding.
This is useful for adapting codecs to work with different representations, handling default values, or converting between primitive and structured types.
Type Parameters
| Type Parameter | Description |
|---|---|
TOldFrom | The original type expected by the codec. |
TNewFrom | The new type that will be transformed before encoding. |
TOldTo | The original type returned by the codec. |
TNewTo | The new type that will be transformed after decoding. |
Parameters
| Parameter | Type | Description |
|---|---|---|
codec | VariableSizeCodec<TOldFrom, TOldTo> | The codec to transform. |
unmap | (value) => TOldFrom | A function that converts values of TNewFrom into TOldFrom before encoding. |
map | (value, bytes, offset) => TNewTo | A function that converts values of TOldTo into TNewTo after decoding (optional). |
Returns
VariableSizeCodec<TNewFrom, TNewTo>
A new codec that encodes TNewFrom and decodes into TNewTo.
Example
Mapping a u32 codec to encode string lengths and decode them into 'x' characters.
Remarks
If only input transformation is needed, use transformEncoder. If only output transformation is needed, use transformDecoder.
See
Call Signature
Transforms a codec by mapping its input and output values.
This function takes an existing Codec<A, B> and returns a Codec<C, D>, allowing:
- Values of type
Cto be transformed intoAbefore encoding. - Values of type
Bto be transformed intoDafter decoding.
This is useful for adapting codecs to work with different representations, handling default values, or converting between primitive and structured types.
Type Parameters
| Type Parameter | Description |
|---|---|
TOldFrom | The original type expected by the codec. |
TNewFrom | The new type that will be transformed before encoding. |
TOldTo | The original type returned by the codec. |
TNewTo | The new type that will be transformed after decoding. |
Parameters
| Parameter | Type | Description |
|---|---|---|
codec | Codec<TOldFrom, TOldTo> | The codec to transform. |
unmap | (value) => TOldFrom | A function that converts values of TNewFrom into TOldFrom before encoding. |
map | (value, bytes, offset) => TNewTo | A function that converts values of TOldTo into TNewTo after decoding (optional). |
Returns
Codec<TNewFrom, TNewTo>
A new codec that encodes TNewFrom and decodes into TNewTo.
Example
Mapping a u32 codec to encode string lengths and decode them into 'x' characters.
Remarks
If only input transformation is needed, use transformEncoder. If only output transformation is needed, use transformDecoder.