1 unstable release

0.1.0 Feb 10, 2023

#8 in #exp

Download history 1/week @ 2024-07-20 33/week @ 2024-07-27 32/week @ 2024-08-03 1/week @ 2024-08-10 23/week @ 2024-08-17 23/week @ 2024-08-24 1/week @ 2024-08-31 1/week @ 2024-09-07 6/week @ 2024-09-14 50/week @ 2024-09-21 15/week @ 2024-09-28 15/week @ 2024-10-05 15/week @ 2024-10-12 15/week @ 2024-10-19 12/week @ 2024-10-26 10/week @ 2024-11-02

54 downloads per month

MIT/Apache

18KB
242 lines

exp-golomb

Encoder/decoder for Exponential-Golomb coding.

Using the Wikipedia example:

Number Bit pattern
0 1
1 010
2 011
3 00100
4 00101
5 00110
6 00111
7 0001000
8 000100
use exp_golomb::{ExpGolombDecoder, ExpGolombEncoder};

let mut buf = [0u8; 6];
let mut writer = ExpGolombEncoder::new(&mut buf, 0).unwrap();
for i in 0..=8 {
    writer.put_unsigned(i).unwrap();
}
writer.close();
    
assert_eq!(
    buf,
    [0b10100110, 0b01000010, 0b10011000, 0b11100010, 0b00000100, 0b10000000]
);

let mut reader = ExpGolombDecoder::new(&buf, 0).unwrap();
for i in 0..=8 {
    assert_eq!(reader.next_unsigned(), Some(i));
}

lib.rs:

Utilities for Exponential-Golomb coding.

No runtime deps