Kit
Functions

getHiddenPrefixEncoder

Call Signature

getHiddenPrefixEncoder<TFrom>(encoder, prefixedEncoders): FixedSizeEncoder<TFrom>

Returns an encoder that prefixes encoded values with hidden data.

This encoder applies a list of void encoders before encoding the main value. The prefixed data is encoded before the main value without being exposed to the user.

For more details, see getHiddenPrefixCodec.

Type Parameters

Type ParameterDescription
TFromThe type of the main value being encoded.

Parameters

ParameterTypeDescription
encoderFixedSizeEncoder<TFrom>The encoder for the main value.
prefixedEncodersreadonly FixedSizeEncoder<void>[]A list of void encoders that produce the hidden prefix.

Returns

FixedSizeEncoder<TFrom>

A FixedSizeEncoder or VariableSizeEncoder that encodes the value with a hidden prefix.

Example

Prefixing a value with constants.

const encoder = getHiddenPrefixEncoder(getUtf8Encoder(), [
  getConstantCodec(new Uint8Array([1, 2, 3])),
  getConstantCodec(new Uint8Array([4, 5, 6])),
]);
 
encoder.encode('Hello');
// 0x01020304050648656c6c6f
//   |     |     └-- Our encoded value ("Hello").
//   |     └-- Our second hidden prefix.
//   └-- Our first hidden prefix.

See

getHiddenPrefixCodec

Call Signature

getHiddenPrefixEncoder<TFrom>(encoder, prefixedEncoders): VariableSizeEncoder<TFrom>

Returns an encoder that prefixes encoded values with hidden data.

This encoder applies a list of void encoders before encoding the main value. The prefixed data is encoded before the main value without being exposed to the user.

For more details, see getHiddenPrefixCodec.

Type Parameters

Type ParameterDescription
TFromThe type of the main value being encoded.

Parameters

ParameterTypeDescription
encoderEncoder<TFrom>The encoder for the main value.
prefixedEncodersreadonly Encoder<void>[]A list of void encoders that produce the hidden prefix.

Returns

VariableSizeEncoder<TFrom>

A FixedSizeEncoder or VariableSizeEncoder that encodes the value with a hidden prefix.

Example

Prefixing a value with constants.

const encoder = getHiddenPrefixEncoder(getUtf8Encoder(), [
  getConstantCodec(new Uint8Array([1, 2, 3])),
  getConstantCodec(new Uint8Array([4, 5, 6])),
]);
 
encoder.encode('Hello');
// 0x01020304050648656c6c6f
//   |     |     └-- Our encoded value ("Hello").
//   |     └-- Our second hidden prefix.
//   └-- Our first hidden prefix.

See

getHiddenPrefixCodec

On this page