Variables
getU128Codec
const
getU128Codec: (config?
) =>FixedSizeCodec
<bigint
|number
,bigint
,16
>
Returns a codec for encoding and decoding 128-bit unsigned integers (u128
).
This codec serializes u128
values using 16 bytes.
Values can be provided as either number
or bigint
, but the decoded value is always a bigint
.
Parameters
Parameter | Type | Description |
---|---|---|
config? | NumberCodecConfig | Optional configuration to specify endianness (little by default). |
Returns
FixedSizeCodec
<bigint
| number
, bigint
, 16
>
A FixedSizeCodec<number | bigint, bigint, 16>
for encoding and decoding u128
values.
Examples
Encoding and decoding a u128
value.
Using big-endian encoding.
Remarks
This codec supports values between 0
and 2^128 - 1
.
Since JavaScript number
cannot safely represent values beyond 2^53 - 1
, the decoded value is always a bigint
.
- If you need a smaller unsigned integer, consider using getU64Codec or getU32Codec.
- If you need signed integers, consider using getI128Codec.
Separate getU128Encoder and getU128Decoder functions are available.