Coder Social home page Coder Social logo

redrield / leb128 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gimli-rs/leb128

0.0 2.0 0.0 567 KB

Read and write DWARF's "Little Endian Base 128" variable length integer encoding

Home Page: http://gimli-rs.github.io/leb128/leb128/index.html

License: Apache License 2.0

Rust 95.96% Shell 4.04%

leb128's Introduction

leb128

Build Status Coverage Status

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.

Install

Either

$ cargo add leb128

or add this to your Cargo.toml:

[dependencies]
leb128 = "0.2.1"

Example

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

Documentation

Documentation

Read-Eval-Print-Loop for LEB128

This crate comes with a leb128-repl program that you can use after cargo install leb128 or by running cargo run in clone of this repository.

$ leb128-repl
LEB128 Read-Eval-Print-Loop!

Converts numbers to signed and unsigned LEB128 and displays the results in
base-10, hex, and binary.

> 42
# unsigned LEB128
[42]
[2a]
[00101010]

# signed LEB128
[42]
[2a]
[00101010]

> -42
# unsigned LEB128
error

# signed LEB128
[86]
[56]
[01010110]

> 9001
# unsigned LEB128
[169, 70]
[a9, 46]
[10101001, 01000110]

# signed LEB128
[169, 198, 0]
[a9, c6, 0]
[10101001, 11000110, 00000000]

> -9001
# unsigned LEB128
error

# signed LEB128
[215, 185, 127]
[d7, b9, 7f]
[11010111, 10111001, 01111111]

>

License

Licensed under either of

at your option.

Contribution

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.

leb128's People

Contributors

fitzgen avatar philipc avatar redrield avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.