Kit
Variables

getU64Codec

const getU64Codec: (config?) => FixedSizeCodec<bigint | number, bigint, 8>

Returns a codec for encoding and decoding 64-bit unsigned integers (u64).

This codec serializes u64 values using 8 bytes. Values can be provided as either number or bigint, but the decoded value is always a bigint.

Parameters

ParameterTypeDescription
config?NumberCodecConfigOptional configuration to specify endianness (little by default).

Returns

FixedSizeCodec<bigint | number, bigint, 8>

A FixedSizeCodec<number | bigint, bigint, 8> for encoding and decoding u64 values.

Examples

Encoding and decoding a u64 value.

const codec = getU64Codec();
const bytes = codec.encode(42); // 0x2a00000000000000
const value = codec.decode(bytes); // 42n

Using big-endian encoding.

const codec = getU64Codec({ endian: Endian.Big });
const bytes = codec.encode(42); // 0x000000000000002a

Remarks

This codec supports values between 0 and 2^64 - 1. Since JavaScript number cannot safely represent values beyond 2^53 - 1, the decoded value is always a bigint.

Separate getU64Encoder and getU64Decoder functions are available.

const bytes = getU64Encoder().encode(42);
const value = getU64Decoder().decode(bytes);

See

On this page