Variable-length integer
A variable-length integer encoding represents integer values using different numbers of bytes according to the format's rules.
Formats: Varint is not one interoperable encoding. Protobuf uses least-significant seven-bit groups first, with a continuation bit and a one-to-ten-byte unsigned 64-bit representation. [1]
SQLite: Its file-format varints use most-significant groups first and at most nine bytes; the ninth contributes eight payload bits. Rowids and record headers use varints, but integer column payloads use widths selected by serial types, including zero-byte encodings of 0 and 1. [2]
Interpretation: The integer 150 gives hexadecimal 96 01 in Protobuf and 81 16 in SQLite. These are integer-field bytes, excluding tags and surrounding metadata. Select the encoding and field type before decoding.
Size: Small magnitudes can use fewer bytes, but an unsigned 64-bit maximum needs ten Protobuf bytes rather than eight fixed-width bytes. Signed values require a specified mapping such as ZigZag. [1]
Relations
Citations
- Protocol Buffers encoding: Base 128 Varints and Signed Integers
- SQLite database file format: B-tree varints and record serial types, sections 1.6 and 2.1
Sources & caveats
- Source synthesis and exact integer examples, not a full serializer or a native decoder conformance test.
- Executable examples and controls: https://hesela.dev/research/varint-contracts.mjs and https://hesela.dev/research/varint-contracts.test.mjs.