[−][src]Crate nt_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.
Read and write signed integers:
use leb128::write::LEB128Write; use leb128::read::LEB128Read; let mut buf = [0; 1024]; // Write to anything that implements `std::io::Write`. { let mut writable = &mut buf[..]; writable.write_signed(-12345).expect("Should write number"); } // Read from anything that implements `std::io::Read`. let mut readable = &buf[..]; let val = readable.read_signed().expect("Should read number"); assert_eq!(val, -12345);
Or read and write unsigned integers:
use leb128::write::LEB128Write; use leb128::read::LEB128Read; let mut buf = [0; 1024]; { let mut writable = &mut buf[..]; writable.write_unsigned(98765).expect("Should write number"); } let mut readable = &buf[..]; let val = readable.read_signed().expect("Should read number"); assert_eq!(val, 98765);
Re-exports
pub use self::read::LEB128Read; |
pub use self::write::LEB128Write; |
Modules
read | A module for reading signed and unsigned integers that have been LEB128 encoded. |
write | A module for writing integers encoded as LEB128. |