reverseCodec
Reverses the bytes of a fixed-size codec.
Given a FixedSizeCodec, this function returns a new FixedSizeCodec that
reverses the bytes within the fixed-size byte array during encoding and decoding.
This can be useful to modify endianness or for other byte-order transformations.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the value to encode. |
TTo | The type of the decoded value. |
TSize extends number | The fixed size of the encoded/decoded value in bytes. |
Parameters
| Parameter | Type | Description |
|---|---|---|
codec | FixedSizeCodec<TFrom, TTo, TSize> | The fixed-size codec to reverse. |
Returns
FixedSizeCodec<TFrom, TTo, TSize>
A new codec that encodes and decodes bytes in reverse order.
Example
Reversing a u16 codec.
Remarks
If you only need to reverse an encoder, use reverseEncoder. If you only need to reverse a decoder, use reverseDecoder.