bytecode

Crates.iobytecode
lib.rsbytecode
version0.3.0
sourcesrc
created_at2022-11-16 13:17:30.945236
updated_at2022-11-17 19:46:36.771901
descriptionThis library provides the ability to read bytecode.
homepage
repositoryhttps://github.com/NaokiM03/bytecode
max_upload_size
id716396
size42,249
(NaokiM03)

documentation

https://docs.rs/bytecode

README

bytecode

This library provides the ability to read bytecode.

Usage

Add this to your Cargo.toml:

bytecode = "0.1.0"

and this to your source code:

use bytecode::ByteCode;

Example

use bytecode::ByteCode;

fn main() {
    {
        let mut bytes = ByteCode::new(&[0, 1, 2, 3, 4, 5, 6, 7]);

        bytes += 3;

        let _first = bytes[0];
        let _second = bytes[1];

        let _subslice = &bytes[2..5];
    }

    {
        let mut bytes = ByteCode::new(&[0, 1, 2, 3, 4, 5, 6, 7]);

        match bytes.peek(3) {
            // omitted
            _ => {}
        }

        if bytes.starts_with("foo".as_bytes()) {
            // omitted
        }

        bytes.skip(2);

        let _subslice = bytes.take(4);
    }

    {
        let mut bytes = ByteCode::new(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x66, 0x6f, 0x6f]);

        let _u8 = bytes.take_into_u8();   //  u8::MAX
        let _u16 = bytes.take_into_u16(); // u16::MAX
        let _u32 = bytes.take_into_u32(); // u32::MAX

        let _string = bytes.take_into_string(3); // "foo".to_owned()
    }
}
use std::fs::File;
use std::io::Read;

use bytecode::ByteCode;

fn main() {
    let mut f = File::open("./examples/puts.mrb").unwrap();
    let mut buffer = Vec::new();
    f.read_to_end(&mut buffer).unwrap();

    let mut mrb = ByteCode::new(&buffer);

    let _header = mrb.take(20);
    dbg!(&mrb);
}

examples/debug.png

License

bytecode is released under the MIT License.

Commit count: 42

cargo fmt