zigzag_encode
Maps a signed integer to an unsigned one so that small magnitudes stay small: 0, -1, 1, -2, 2, ... become 0, 1, 2, 3, 4, .... Varint formats (Protocol Buffers sint, Kiwi) encode
signed values this way before LEB128, so that -1 takes one byte instead of ten.
The result does not depend on the integer width: an i32 widened to i64 encodes to the
same value as with 32-bit zigzag.
Import
Section titled “Import”Cargo feature bytes (enabled by default). To compile only this module:
or in Cargo.toml:
Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | i64 | The signed integer. |
Returns
Section titled “Returns”u64 — The zigzag-encoded value; zigzag_decode reverses it.
