leb128
Read and write DWARF's "Little Endian Base 128" (LEB128) variable length integer encoding.
The implementation is a direct translation of the psuedocode in the DWARF 4 standard's appendix C.
Either
$ cargo add leb128
or add this to your Cargo.toml
:
[dependencies]
leb128 = "0.1.0"
```rust use leb128;
let mut buf = [0; 1024];
// Write to anything that implements std::io::Write
.
{
let mut writable = &mut buf[..];
leb128::write::signed(&mut writable, -12345).expect("Should write number");
}
// Read from anything that implements std::io::Read
.
let mut readable = &buf[..];
let val = leb128::read::signed(&mut readable).expect("Should read number");
assert_eq!(val, -12345);
```
Licensed under either of
LICENSE-APACHE
or http://www.apache.org/licenses/LICENSE-2.0)LICENSE-MIT
or http://opensource.org/licenses/MIT)at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.