Compact Variable Length Integer

A variable-width data format for unsigned integers allowing a more compact representation for smaller values. This is sometimes referred to as "compact size" or "var int".

Format

Numbers are encoded with the first rule that applies of the following:

Byte Index C-Style Calculation
0 0xFD
1 value & 255
2 value >> 8
Byte Index C-Style Calculation
0 0xFE
1 value & 255
2 (value >> 8) & 255
3 (value >> 16) & 255
4 (value >> 24) & 255
Byte Index C-Style Calculation
0 0xFF
1 value & 255
2 (value >> 8) & 255
3 (value >> 16) & 255
4 (value >> 24) & 255
5 (value >> 32) & 255
6 (value >> 40) & 255
7 (value >> 48) & 255
8 (value >> 56) & 255