Variables
getI128Codec
const
getI128Codec: (config?
) =>FixedSizeCodec
<bigint
|number
,bigint
,16
>
Returns a codec for encoding and decoding 128-bit signed integers (i128
).
This codec serializes i128
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 i128
values.
Examples
Encoding and decoding an i128
value.
Using big-endian encoding.
Remarks
This codec supports values between -2^127
and 2^127 - 1
.
Since JavaScript number
cannot safely represent values beyond 2^53 - 1
, the decoded value is always a bigint
.
- If you need a smaller signed integer, consider using getI64Codec or getI32Codec.
- If you need a larger signed integer, consider using a custom codec.
- If you need unsigned integers, consider using getU128Codec.
Separate getI128Encoder and getI128Decoder functions are available.