Varint Encode
Varint encoding outputs an unsigned integer as variable-length bytes grouped 7 bits at a time, with each byte's MSB serving as the continuation flag.
Purpose
It represents integers compactly in binary protocols — small values fit in 1 byte.
Mechanism
Bits are emitted 7 at a time from low to high; the highest bit is 1 while more bytes follow and 0 at the end.
Use cases
- Protobuf fields
- Variable-length database columns
- Protocol header lengths