Kit
Functions

getU32Codec

getU32Codec(config): FixedSizeCodec<number | bigint, number, 4>

Returns a codec for encoding and decoding 32-bit unsigned integers (u32).

This codec serializes u32 values using four bytes in little-endian format by default. You may specify big-endian storage using the endian option.

Parameters

ParameterTypeDescription
configNumberCodecConfigOptional settings for endianness.

Returns

FixedSizeCodec<number | bigint, number, 4>

A FixedSizeCodec<bigint | number, number, 4> for encoding and decoding u32 values.

Examples

Encoding and decoding a u32 value.

const codec = getU32Codec();
const bytes = codec.encode(42); // 0x2a000000 (little-endian)
const value = codec.decode(bytes); // 42

Storing values in big-endian format.

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

Remarks

This codec only supports values between 0 and 2^32 - 1. If you need a larger range, consider using getU64Codec or getU128Codec. For signed integers, use getI32Codec.

Separate getU32Encoder and getU32Decoder functions are available.

const bytes = getU32Encoder().encode(42);
const value = getU32Decoder().decode(bytes);

See

On this page