Expand description
A set of helper functions to encode and decode exponential-golomb values.
This crate extends upon the BitReader
and BitWriter
from the
scuffle-bytes-util
crate to provide functionality
for reading and writing Exp-Golomb encoded numbers.
use scuffle_expgolomb::{BitReaderExpGolombExt, BitWriterExpGolombExt};
use scuffle_bytes_util::{BitReader, BitWriter};
let mut bit_writer = BitWriter::default();
bit_writer.write_exp_golomb(0)?;
bit_writer.write_exp_golomb(1)?;
bit_writer.write_exp_golomb(2)?;
let data: Vec<u8> = bit_writer.finish()?;
let mut bit_reader = BitReader::new(std::io::Cursor::new(data));
let result = bit_reader.read_exp_golomb()?;
assert_eq!(result, 0);
let result = bit_reader.read_exp_golomb()?;
assert_eq!(result, 1);
let result = bit_reader.read_exp_golomb()?;
assert_eq!(result, 2);
§License
This project is licensed under the MIT or Apache-2.0 license. You can choose between one of them if you use this work.
SPDX-License-Identifier: MIT OR Apache-2.0
Traits§
- BitReader
ExpGolomb Ext - Extension trait for reading Exp-Golomb encoded numbers from a bit reader
- BitWriter
ExpGolomb Ext - Extension trait for writing Exp-Golomb encoded numbers to a bit writer
Functions§
- size_
of_ exp_ golomb - Returns the number of bits that an Exp-Golomb encoded number would take up.
- size_
of_ signed_ exp_ golomb - Returns the number of bits that a signed Exp-Golomb encoded number would take up.