Kit
Functions

reverseEncoder

reverseEncoder<TFrom, TSize>(encoder): FixedSizeEncoder<TFrom, TSize>

Reverses the bytes of a fixed-size encoder.

Given a FixedSizeEncoder, this function returns a new FixedSizeEncoder that reverses the bytes within the fixed-size byte array when encoding.

This can be useful to modify endianness or for other byte-order transformations.

For more details, see reverseCodec.

Type Parameters

Type ParameterDescription
TFromThe type of the value to encode.
TSize extends numberThe fixed size of the encoded value in bytes.

Parameters

ParameterTypeDescription
encoderFixedSizeEncoder<TFrom, TSize>The fixed-size encoder to reverse.

Returns

FixedSizeEncoder<TFrom, TSize>

A new encoder that writes bytes in reverse order.

Example

Encoding a u16 value in reverse order.

const encoder = reverseEncoder(getU16Encoder({ endian: Endian.Big }));
const bytes = encoder.encode(0x1234); // 0x3412 (bytes are flipped)

See

On this page