numeric.md

December 7, 2024 ยท View on GitHub

Numeric

These datatypes represent numbers. Most of them don't take any arguments. They default to big-endian encoding. To use little-endian, prefix its name with "l".

NameSize in bytesExample of valueAlso called
i81-125byte
u81255unsigned byte
i162-32000short
u16260000unsigned short
i324-2000000000int
u3243000000000unsigned int
f3244.5float
f6484.5double
i6481long
u6481unsigned long
varint1-4300int var
varint641-8300nunsigned long
varint1281-162 ^ 68unsigned __int128
zigzag321-4-100signed int var
zigzag641-8-680nsigned long

int ({ size: Integer })

Arguments:

  • size : fixed size in bytes

Represents a unsigned integer using size bytes.

Example:

[
  "int",
  { "size": "3" }
]

Example of value: 65535 (size = 2) / 16777215 (size = 3)

varint ( )

Arguments: None

Protobuf-compatible representation for variable-length integers using one or more bytes. Intended for 32-bit unsigned integers, or signed 32-bit integers that have been directly cast to an integer (where the MSB is the sign bit) before encoding.

Example of value: 300 (size is 2 bytes)

varint64 ()

Arguments: None

Same as varint, but for 64-bit unsigned integers, or signed 64-bit integers that have been directly cast to an integer (where the MSB is the sign bit) before encoding.

varint128 ()

Arguments: None

Same as varint, but for 128-bit unsigned integers, or signed 128-bit integers that have been directly cast to an integer (where the MSB is the sign bit) before encoding.

zigzag32 ()

Arguments: None

Similar to varint, except using ZigZag encoding for signed integers. Intended for 32-bit signed numbers.

zigzag64 ()

Arguments: None

Same as zigzag32, but for 64-bit signed integers in ZigZag encoding.