Trait uleb128::ReadULeb128Ext[][src]

pub trait ReadULeb128Ext: Read {
    fn read_uleb128_u32(&mut self) -> Result<u32> { ... }
fn read_uleb128_u64(&mut self) -> Result<u64> { ... } }
Expand description

Extends Read with methods for reading numbers encoded in [unsigned LEB128*]

Examples

Read unsigned LEB128 integers from a reader:

use std::io::Cursor;
use uleb128::ReadULeb128Ext;

let mut rdr = Cursor::new(vec![
    0b0111_1111, // 127
    0b1000_0000, 0b0000_0001, // 128
    0b1000_0001, 0b0000_0001 // 129
]);

assert_eq!(127, rdr.read_uleb128_u32().unwrap());
assert_eq!(128, rdr.read_uleb128_u32().unwrap());
assert_eq!(129, rdr.read_uleb128_u32().unwrap());

Provided methods

fn read_uleb128_u32(&mut self) -> Result<u32>[src]

Read an unsigned 32-bit integer that’s encoded in unsigned LEB128 from the underlying reader.

Errors

If this function encounters an error when performing an I/O operation, then this function immediately returns an Error::Io to propagate the io::Error returned by an internal call to Read::read_exact.

If this function encounters an encoded number with a length in bytes greater than what is permitted, an Error::LengthOverflow is immediately returned.

Examples

Read an unsigned LEB128-encoded, 32-bit integer:

use std::io::Cursor;
use uleb128::ReadULeb128Ext;

let mut rdr = Cursor::new(vec![
    // 2_147_483_647
    0b1111_1111, 0b1111_1111, 0b1111_1111, 0b1111_1111, 0b0000_0111
]);

assert_eq!(2_147_483_647, rdr.read_uleb128_u32().unwrap());

fn read_uleb128_u64(&mut self) -> Result<u64>[src]

Read an unsigned 64-bit integer that’s encoded in unsigned LEB128 from the underlying reader.

Errors

If this function encounters an error when performing an I/O operation, then this function immediately returns an Error::Io to propagate the io::Error returned by an internal call to Read::read_exact.

If this function encounters an encoded number with a length in bytes greater than what is permitted, an Error::LengthOverflow is immediately returned.

Examples

Read an unsigned LEB128-encoded, 64-bit integer:

use std::io::Cursor;
use uleb128::ReadULeb128Ext;

let mut rdr = Cursor::new(vec![
    // 9_223_372_036_854_775_807
    0b1111_1111, 0b1111_1111, 0b1111_1111, 0b1111_1111, 0b1111_1111,
    0b1111_1111, 0b1111_1111, 0b1111_1111, 0b0111_1111
]);

assert_eq!(9_223_372_036_854_775_807, rdr.read_uleb128_u64().unwrap());

Implementors

impl<R: Read + ?Sized> ReadULeb128Ext for R[src]