Kit
Functions

getConstantEncoder

getConstantEncoder<TConstant>(constant): FixedSizeEncoder<void, TConstant["length"]>

Returns an encoder that always writes a predefined constant byte sequence.

This encoder ensures that encoding always produces the specified byte array, ignoring any input values.

For more details, see getConstantCodec.

Type Parameters

Type ParameterDescription
TConstant extends ReadonlyUint8ArrayThe fixed byte sequence that will be written during encoding.

Parameters

ParameterTypeDescription
constantTConstantThe predefined byte array to encode.

Returns

FixedSizeEncoder<void, TConstant["length"]>

A FixedSizeEncoder<void, N> where N is the length of the constant.

Example

Encoding a constant magic number.

const encoder = getConstantEncoder(new Uint8Array([1, 2, 3, 4]));
 
const bytes = encoder.encode();
// 0x01020304
//   └──────┘ The predefined 4-byte constant.

See

getConstantCodec

On this page