Kit
Functions

getBase10Codec

getBase10Codec(): VariableSizeCodec<string>

Returns a codec for encoding and decoding base-10 strings.

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

Returns

VariableSizeCodec<string>

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

Example

Encoding and decoding a base-10 string.

const codec = getBase10Codec();
const bytes = codec.encode('1024'); // 0x0400
const value = codec.decode(bytes);  // "1024"

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-10 codec, consider using fixCodecSize.

const codec = fixCodecSize(getBase10Codec(), 5);

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

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

Separate getBase10Encoder and getBase10Decoder functions are available.

const bytes = getBase10Encoder().encode('1024');
const value = getBase10Decoder().decode(bytes);

See

On this page