Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
leb128
https://docs.rs/leb128/0.2.7/leb128/
Admin
leb128 is a Rust crate for reading and writing DWARF's Little Endian Base 128 (LEB128)
...
Tokens:
2,624
Snippets:
30
Trust Score:
9.1
Update:
1 month ago
Context
Chat
Benchmark
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Read and write signed LEB128 integers Source: https://docs.rs/leb128/0.2.7/leb128/index.html Demonstrates encoding and decoding signed integers using the leb128::write::signed and leb128::read::signed functions. ```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); ``` -------------------------------- ### Read and write unsigned LEB128 integers Source: https://docs.rs/leb128/0.2.7/leb128/index.html Demonstrates encoding and decoding unsigned integers using the leb128::write::unsigned and leb128::read::unsigned functions. ```rust 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); ``` -------------------------------- ### pub fn signed<W>(w: &mut W, val: i64) -> Result<usize, Error> Source: https://docs.rs/leb128/0.2.7/leb128/write/fn.signed.html Writes a signed i64 value to a std::io::Write stream using LEB128 encoding. Returns the number of bytes written on success. ```APIDOC ## Function: signed ### Description Writes `val` to the `std::io::Write` stream `w` as a signed LEB128 value. On success, it returns the number of bytes written to the stream. ### Signature `pub fn signed<W>(w: &mut W, val: i64) -> Result<usize, Error> where W: ?Sized + Write` ### Parameters - **w** (&mut W) - The writer stream implementing `std::io::Write`. - **val** (i64) - The signed 64-bit integer to encode and write. ### Returns - **Result<usize, Error>** - Returns `Ok(usize)` representing the number of bytes written, or an `Error` if the write operation fails. ``` -------------------------------- ### pub fn unsigned_len(val: u64) -> usize Source: https://docs.rs/leb128/0.2.7/leb128/write/fn.unsigned_len.html Calculates the number of bytes needed to encode a value as unsigned LEB128. ```APIDOC ## unsigned_len ### Description Returns the number of bytes needed to encode `value` as unsigned LEB128. ### Signature `pub fn unsigned_len(val: u64) -> usize` ### Parameters - **val** (u64) - The unsigned 64-bit integer to be encoded. ### Returns - **usize** - The number of bytes required for the LEB128 representation. ``` -------------------------------- ### pub fn signed<R>(r: &mut R) -> Result<i64, Error> Source: https://docs.rs/leb128/0.2.7/leb128/read/fn.signed.html Reads a signed LEB128-encoded number from the provided std::io::Read stream. ```APIDOC ## pub fn signed<R>(r: &mut R) -> Result<i64, Error> ### Description Read a signed LEB128-encoded number from the `std::io::Read` stream `r`. On success, return the number. ### Signature `pub fn signed<R>(r: &mut R) -> Result<i64, Error> where R: ?Sized + Read` ### Parameters - **r** (&mut R) - Required - A mutable reference to a type implementing `std::io::Read`. ### Returns - **Result<i64, Error>** - Returns the decoded `i64` value on success, or an `Error` if the read fails. ``` -------------------------------- ### pub fn unsigned<W>(w: &mut W, val: u64) -> Result<usize, Error> Source: https://docs.rs/leb128/0.2.7/leb128/write/fn.unsigned.html Writes a u64 value to a std::io::Write stream using unsigned LEB128 encoding. ```APIDOC ## Function: unsigned ### Description Writes `val` to the `std::io::Write` stream `w` as an unsigned LEB128 value. On success, it returns the number of bytes written to the stream. ### Signature `pub fn unsigned<W>(w: &mut W, val: u64) -> Result<usize, Error> where W: ?Sized + Write` ### Parameters - **w** (&mut W) - The writer stream implementing `std::io::Write`. - **val** (u64) - The unsigned 64-bit integer to encode. ### Returns - **Result<usize, Error>** - Returns the number of bytes written on success, or an error if the write operation fails. ``` -------------------------------- ### unsigned Source: https://docs.rs/leb128/0.2.7/leb128/write/index.html Writes an unsigned integer to a stream using LEB128 encoding. ```APIDOC ## unsigned(w: &mut impl std::io::Write, val: u64) -> std::io::Result<usize> ### Description Write `val` to the `std::io::Write` stream `w` as an unsigned LEB128 value. ``` -------------------------------- ### signed Source: https://docs.rs/leb128/0.2.7/leb128/write/index.html Writes a signed integer to a stream using LEB128 encoding. ```APIDOC ## signed(w: &mut impl std::io::Write, val: i64) -> std::io::Result<usize> ### Description Write `val` to the `std::io::Write` stream `w` as a signed LEB128 value. ``` -------------------------------- ### Calculate signed LEB128 byte length Source: https://docs.rs/leb128/0.2.7/leb128/write/fn.signed_len.html Returns the number of bytes needed to encode a signed 64-bit integer as a signed LEB128 value. ```rust pub fn signed_len(val: i64) -> usize ``` -------------------------------- ### unsigned_len Source: https://docs.rs/leb128/0.2.7/leb128/write/index.html Calculates the number of bytes required to encode an unsigned integer as LEB128. ```APIDOC ## unsigned_len(value: u64) -> usize ### Description Return the number of bytes needed to encode `value` as unsigned LEB128. ``` -------------------------------- ### signed_len Source: https://docs.rs/leb128/0.2.7/leb128/write/index.html Calculates the number of bytes required to encode a signed integer as LEB128. ```APIDOC ## signed_len(value: i64) -> usize ### Description Return the number of bytes needed to encode `value` a signed LEB128. ``` -------------------------------- ### Calculate unsigned LEB128 byte length Source: https://docs.rs/leb128/0.2.7/leb128/write/fn.unsigned_len.html Returns the number of bytes needed to encode a given u64 value as unsigned LEB128. ```rust pub fn unsigned_len(val: u64) -> usize ``` -------------------------------- ### leb128::write::signed Source: https://docs.rs/leb128 Writes a signed integer to a type implementing std::io::Write using LEB128 encoding. ```APIDOC ## leb128::write::signed ### Description Writes a signed integer to a provided writer using LEB128 encoding. ### Signature `pub fn signed<W: Write>(w: &mut W, value: i64) -> Result<usize>` ### Parameters - **w** (W: Write) - The destination writer. - **value** (i64) - The signed integer to encode. ``` -------------------------------- ### leb128::write::unsigned Source: https://docs.rs/leb128 Writes an unsigned integer to a type implementing std::io::Write using LEB128 encoding. ```APIDOC ## leb128::write::unsigned ### Description Writes an unsigned integer to a provided writer using LEB128 encoding. ### Signature `pub fn unsigned<W: Write>(w: &mut W, value: u64) -> Result<usize>` ### Parameters - **w** (W: Write) - The destination writer. - **value** (u64) - The unsigned integer to encode. ``` -------------------------------- ### signed Source: https://docs.rs/leb128/0.2.7/leb128/read/index.html Reads a signed LEB128-encoded number from the provided std::io::Read stream. ```APIDOC ## signed ### Description Read a signed LEB128-encoded number from the `std::io::Read` stream `r`. ### Signature `pub fn signed<R: Read>(r: &mut R) -> Result<i128, Error>` ``` -------------------------------- ### unsigned function signature Source: https://docs.rs/leb128/0.2.7/leb128/write/fn.unsigned.html The function signature for writing an unsigned LEB128 value to a writer. ```rust pub fn unsigned<W>(w: &mut W, val: u64) -> Result<usize, Error> where W: ?Sized + Write, ``` -------------------------------- ### unsigned Source: https://docs.rs/leb128/0.2.7/leb128/read/index.html Reads an unsigned LEB128-encoded number from the provided std::io::Read stream. ```APIDOC ## unsigned ### Description Read an unsigned LEB128-encoded number from the `std::io::Read` stream `r`. ### Signature `pub fn unsigned<R: Read>(r: &mut R) -> Result<u128, Error>` ``` -------------------------------- ### Function signature for signed LEB128 writing Source: https://docs.rs/leb128/0.2.7/leb128/write/fn.signed.html The function requires a mutable reference to a type implementing std::io::Write and returns the number of bytes written or an error. ```rust pub fn signed<W>(w: &mut W, val: i64) -> Result<usize, Error> where W: ?Sized + Write, ``` -------------------------------- ### leb128::signed_len Source: https://docs.rs/leb128/0.2.7/leb128/write/fn.signed_len.html Calculates the byte length of a signed LEB128 encoded integer. ```APIDOC ## Function: signed_len ### Description Returns the number of bytes needed to encode a given `i64` value as a signed LEB128 integer. ### Signature `pub fn signed_len(val: i64) -> usize` ### Parameters - **val** (i64) - The signed 64-bit integer to evaluate. ### Returns - **usize** - The number of bytes required for the LEB128 representation. ``` -------------------------------- ### Read signed LEB128 integer Source: https://docs.rs/leb128/0.2.7/leb128/read/fn.signed.html Reads a signed LEB128-encoded number from a stream implementing std::io::Read. ```rust pub fn signed<R>(r: &mut R) -> Result<i64, Error> where R: ?Sized + Read, ``` -------------------------------- ### leb128::unsigned Source: https://docs.rs/leb128/0.2.7/leb128/read/fn.unsigned.html Reads an unsigned LEB128-encoded number from the provided reader. ```APIDOC ## pub fn unsigned<R>(r: &mut R) -> Result<u64, Error> ### Description Read an unsigned LEB128-encoded number from the `std::io::Read` stream `r`. On success, return the number. ### Parameters - **r** (&mut R) - Required - A mutable reference to a type implementing `std::io::Read`. ### Returns - **Result<u64, Error>** - Returns the decoded unsigned 64-bit integer on success, or an `Error` if the read fails or the encoding is invalid. ``` -------------------------------- ### Define the Error enum Source: https://docs.rs/leb128/0.2.7/leb128/read/enum.Error.html The Error enum represents failures during LEB128 decoding, including underlying IO issues and value overflows. ```rust pub enum Error { IoError(Error), Overflow, } ``` -------------------------------- ### Read unsigned LEB128 number Source: https://docs.rs/leb128/0.2.7/leb128/read/fn.unsigned.html Reads an unsigned LEB128-encoded number from a std::io::Read stream. ```rust pub fn unsigned<R>(r: &mut R) -> Result<u64, Error> where R: ?Sized + Read, ```