Skip to content

A zvarint stores a signed 64-bit integer. The value is first zig-zag mapped so that small magnitudes of either sign become small unsigned numbers, then written as a varint.

For a value v, the encoder computes

z = (v << 1) ^ (v >> 63)

and writes z as a varint.

The decoder reads a varint z and computes

(z >> 1) ^ -(z & 1)

All the rules for a malformed or truncated varint apply unchanged, because a zvarint is a varint underneath.