Variable-length encoding of 32-bit integers, into 8-bit bytes. A number is encoded as follows:
- If it is less than 127 and non-negative (i.e., if the number uses only 7 bits), it is encoded as as single byte: 0bbbbbbb.
- If its highest nonzero bit is greater than bit 6 (0x40), it is represented as a series of bytes, each byte's 7 LSB containing bits from the original value, with the MSB set for all but the last byte. The first encoded byte contains the highest nonzero bits from the original; the second byte contains the next 7 MSB; and so on, with the last byte containing the 7 LSB of the original.
Examples:
- n = 117 = 1110101: This has fewer than 8 significant bits, and so is encoded as 01110101 = 0x75.
- n = 100000 = (binary) 11000011010100000. This has 17 significant bits, and so needs three Vint8 bytes. Left-zero-pad it to a multiple of 7 bits, then split it into chunks of 7 and add an MSB, 0 for the last byte, 1 for the others: 1|0000110 1|0001101 0|0100000 = 0x86 0x8D 0x20.
This encoder/decoder will correctly handle any 32-bit integer, but for negative numbers, and positive numbers with more than 28 significant bits, encoding requires 5 bytes; this is not an efficient encoding scheme for large positive numbers or any negative number.
Compatibility:
This class has been used in products that have shipped to customers, and is needed to decode legacy data. Do not modify this class in ways that will break compatibility.
@lucene.experimental