Crates.io | exp-golomb |
lib.rs | exp-golomb |
version | 0.1.0 |
source | src |
created_at | 2023-02-10 15:21:29.904153 |
updated_at | 2023-02-10 15:21:29.904153 |
description | Utilities for Exponential-Golomb coding |
homepage | https://github.com/JRF63/exp-golomb |
repository | https://github.com/JRF63/exp-golomb |
max_upload_size | |
id | 781917 |
size | 18,906 |
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));
}