Skip to content

zigzag_decode

Reverses zigzag_encode: 0, 1, 2, 3, 4, ... become 0, -1, 1, -2, 2, ....

use helpers4::bytes::zigzag_decode;

Cargo feature bytes (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features bytes

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.9", default-features = false, features = ["bytes"] }
pub fn zigzag_decode(value: u64) -> i64
ParameterTypeDescription
valueu64The zigzag-encoded value.

i64 — The signed integer. A value read from a 32-bit varint always fits in an i32.

use helpers4::bytes::zigzag_decode;

assert_eq!(zigzag_decode(0), 0);
assert_eq!(zigzag_decode(1), -1);
assert_eq!(zigzag_decode(2), 1);
assert_eq!(zigzag_decode(u64::MAX), i64::MIN);

src/bytes/zigzag_decode.rs