varint
Varint, short for variable-length integer, is a method of serializing integers using a variable number of bytes rather than a fixed size. In common base-128 implementations, an integer is encoded as a stream of bytes with the least-significant bits arriving first. Each byte carries seven data bits and one continuation bit: the most significant bit is set to 1 if another byte follows and 0 if this is the last byte. This design makes small values occupy fewer bytes, while larger values require more bytes, improving space efficiency for many datasets.
Varints are widely used in data interchange formats and RPC systems, including Google Protocol Buffers and
Encoding and decoding follow straightforward rules. To encode, repeatedly take the lower 7 bits of the value,