Functions
getI32Codec
getI32Codec(
config
):FixedSizeCodec
<number
|bigint
,number
,4
>
Returns a codec for encoding and decoding 32-bit signed integers (i32
).
This codec serializes i32
values using 4 bytes.
Values can be provided as either number
or bigint
, but the decoded value is always a number
.
Parameters
Parameter | Type | Description |
---|---|---|
config | NumberCodecConfig | Optional configuration to specify endianness (little by default). |
Returns
FixedSizeCodec
<number
| bigint
, number
, 4
>
A FixedSizeCodec<number | bigint, number, 4>
for encoding and decoding i32
values.
Examples
Encoding and decoding an i32
value.
Using big-endian encoding.
Remarks
This codec supports values between -2^31
(-2,147,483,648
) and 2^31 - 1
(2,147,483,647
).
- If you need a smaller signed integer, consider using getI16Codec or getI8Codec.
- If you need a larger signed integer, consider using getI64Codec.
- If you need unsigned integers, consider using getU32Codec.
Separate getI32Encoder and getI32Decoder functions are available.