Expand description

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;

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);

Or read and write unsigned integers:

use leb128;

let mut buf = [0; 1024];

{
    let mut writable = &mut buf[..];
    leb128::write::unsigned(&mut writable, 98765).expect("Should write number");
}

let mut readable = &buf[..];
let val = leb128::read::unsigned(&mut readable).expect("Should read number");
assert_eq!(val, 98765);

Modules

A module for reading LEB128-encoded signed and unsigned integers.

A module for writing LEB128-encoded signed and unsigned integers.