IxiVarInt Encoding

Finalized

IxiVarInt is a custom variable-length integer encoding used throughout the Ixian protocol to serialize numeric data in a space-efficient manner. It is not compatible with other common schemes like Protobuf varint or LEB128.

Encoding Principle

The encoding scheme is based on a single-byte prefix which determines the size and type of the integer that follows.

  • Unsigned integers from 0 to 247 (0xF7) are encoded as a single byte.
  • Larger or negative numbers are encoded using a 1-byte prefix, followed by the integer value in a fixed-size, little-endian format.

Type Prefixes

PrefixData Type RepresentedPayload SizeTotal BytesNotes
0x00 - 0xF7uint80 bytes1The byte itself is the value.
0xF8short (negative)2 bytes3Used for IxiVarInt.
0xF9int (negative)4 bytes5Used for IxiVarInt.
0xFAlong (negative)8 bytes9Used for IxiVarInt.
0xFBreserved (negative)? bytes?Reserved for potential future use in IxiVarInt.
0xFCushort (positive)2 bytes3Used for both IxiVarInt and IxiVarUInt.
0xFDuint (positive)4 bytes5Used for both IxiVarInt and IxiVarUInt.
0xFEulong (positive)8 bytes9Used for both IxiVarInt and IxiVarUInt.
0xFFreserved (positive)? bytes?Reserved for potential future use in IxiVarUInt.

IxiVarInt vs. IxiVarUInt

The protocol uses two variations depending on whether the integer needs to be signed.

  • IxiVarInt (Signed): Can represent both positive and negative integers. It uses the full range of prefixes.
  • IxiVarUInt (Unsigned): Can only represent positive integers. Decoders must reject any IxiVarInt that uses the negative-specific prefixes (0xF8, 0xF9, 0xFA).

Examples

  • Value: 100
    • As IxiVarUInt: 64 (1 byte, since 100 < 248)
  • Value: 1000
    • As IxiVarUInt: FC E8 03 (3 bytes: prefix 0xFC + little-endian ushort for 1000)
  • Value: -1000
    • As IxiVarInt: F8 E8 03 (3 bytes: prefix 0xF8 + little-endian ushort for 1000)