submodule for "eightpack" that adds the ability to encode and decode variable byte-sized integers.
this part of the library has been separated from "eightpack" because of the unlikeyhood of being used.
uvar stands for an unsigned variable-sized integer.
ivar stands for a signed variable-sized integer.
Purpose
these variable-sized encodings are especially useful for encoding the length of other variables in their header (i.e. at the beginning of their sequence).
How the encoding works
Unsigned integer case
the byte form of a uvar occupies a variable number of bytes to accommodate the unsigned integer that it is holding.
for each byte, it uses the first bit of the octet (0bXYYYYYYY) to signal whether the integer carries on to the next byte (X == 1) or not (X == 0).
the remaining 7 bits in each byte are used for base-7 big-endian encoding of the numeric value of the integer (YYYYYYY).
the following table lists the first few bounds of this encoding:
decimal
unsigned big endian binary
unsigned variable binary
0
0b00000000 0b00000000 0b00000000 0b00000000
0b00000000
127 = 2^7 - 1
0b00000000 0b00000000 0b00000000 0b01111111
0b01111111
128 = 2^7
0b00000000 0b00000000 0b00000000 0b10000000
0b10000001 0b00000000
16383 = 2^14 - 1
0b00000000 0b00000000 0b00111111 0b11111111
0b11111111 0b01111111
16384 = 2^14
0b00000000 0b00000000 0b01000000 0b00000000
0b10000001 0b10000000 0b00000000
Signed integer case
the ivar encoding is similar to the uvar encoding, with the exception that in the first byte,
the second-major bit Z of the octet (0b0ZYYYYYY) signals whether the number is positive (Z == 0), or negative (Z == 1).
the following table lists the first few bounds of this encoding:
submodule for "eightpack" that adds the ability to encode and decode variable byte-sized integers.
this part of the library has been separated from "eightpack" because of the unlikeyhood of being used.
uvar
stands for an unsigned variable-sized integer.ivar
stands for a signed variable-sized integer.Purpose
these variable-sized encodings are especially useful for encoding the length of other variables in their header (i.e. at the beginning of their sequence).
How the encoding works
Unsigned integer case
uvar
occupies a variable number of bytes to accommodate the unsigned integer that it is holding.0bXYYYYYYY
) to signal whether the integer carries on to the next byte (X == 1) or not (X == 0).YYYYYYY
).the following table lists the first few bounds of this encoding:
Signed integer case
ivar
encoding is similar to theuvar
encoding, with the exception that in the first byte, the second-major bitZ
of the octet (0b0ZYYYYYY) signals whether the number is positive (Z == 0), or negative (Z == 1).the following table lists the first few bounds of this encoding: