Expand description
Zigzag encoding for signed integers.
Zigzag maps signed integers to unsigned ones so that small-magnitude negative
values produce small-magnitude varints. Pair these helpers with the
varint functions to encode signed values compactly.
The mapping mirrors the one used by Protocol Buffers:
| signed | unsigned |
|---|---|
| 0 | 0 |
| -1 | 1 |
| 1 | 2 |
| -2 | 3 |
| 2 | 4 |
Functionsยง
- decode_
i32 - Recover the signed
i32from a zigzag-encodedu32. - decode_
i64 - Recover the signed
i64from a zigzag-encodedu64. - encode_
i32 - Map a signed
i32to its zigzag-encodedu32. - encode_
i64 - Map a signed
i64to its zigzag-encodedu64.