transformCodec
Call Signature
transformCodec<
TOldFrom
,TNewFrom
,TTo
,TSize
>(codec
,unmap
):FixedSizeCodec
<TNewFrom
,TTo
,TSize
>
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
C
to be transformed intoA
before encoding. - Values of type
B
to be transformed intoD
after 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
transformCodec<
TOldFrom
,TNewFrom
,TTo
>(codec
,unmap
):VariableSizeCodec
<TNewFrom
,TTo
>
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
C
to be transformed intoA
before encoding. - Values of type
B
to be transformed intoD
after 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
transformCodec<
TOldFrom
,TNewFrom
,TTo
>(codec
,unmap
):Codec
<TNewFrom
,TTo
>
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
C
to be transformed intoA
before encoding. - Values of type
B
to be transformed intoD
after 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
transformCodec<
TOldFrom
,TNewFrom
,TOldTo
,TNewTo
,TSize
>(codec
,unmap
,map
):FixedSizeCodec
<TNewFrom
,TNewTo
,TSize
>
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
C
to be transformed intoA
before encoding. - Values of type
B
to be transformed intoD
after 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
transformCodec<
TOldFrom
,TNewFrom
,TOldTo
,TNewTo
>(codec
,unmap
,map
):VariableSizeCodec
<TNewFrom
,TNewTo
>
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
C
to be transformed intoA
before encoding. - Values of type
B
to be transformed intoD
after 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
transformCodec<
TOldFrom
,TNewFrom
,TOldTo
,TNewTo
>(codec
,unmap
,map
):Codec
<TNewFrom
,TNewTo
>
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
C
to be transformed intoA
before encoding. - Values of type
B
to be transformed intoD
after 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.