Kit
Functions

getBase16Codec

getBase16Codec(): VariableSizeCodec<string>

Returns a codec for encoding and decoding base-16 (hexadecimal) strings.

This codec serializes strings using a base-16 encoding scheme. The output consists of bytes representing the hexadecimal values of the input string.

Returns

VariableSizeCodec<string>

A VariableSizeCodec<string> for encoding and decoding base-16 strings.

Example

Encoding and decoding a base-16 string.

const codec = getBase16Codec();
const bytes = codec.encode('deadface'); // 0xdeadface
const value = codec.decode(bytes);      // "deadface"

Remarks

This codec does not enforce a size boundary. It will encode and decode all bytes necessary to represent the string.

If you need a fixed-size base-16 codec, consider using fixCodecSize.

const codec = fixCodecSize(getBase16Codec(), 8);

If you need a size-prefixed base-16 codec, consider using addCodecSizePrefix.

const codec = addCodecSizePrefix(getBase16Codec(), getU32Codec());

Separate getBase16Encoder and getBase16Decoder functions are available.

const bytes = getBase16Encoder().encode('deadface');
const value = getBase16Decoder().decode(bytes);

See

On this page