tbytes 0.1.0-alpha1

A tiny library for reading and writing typed data into buffers
Documentation

T-Bytes

T-Bytes is a tiny library for reading and writing typed data into bytes buffers. It is designed mainly for no-std, no-alloc targets or crates which consider to support no-std.

Documentation can be found here.

Installation

cargo add tbytes

Usage

Read bytes typed data from buffer:

use tbytes::{TBytesReader, TBytesReaderFor};

fn main() {
    let buffer = [128, 255, 1, 1u8, 1, 255];
    let reader = TBytesReader::from(buffer.as_slice());
    
    // Read byte as `u8`
    let val: u8 = reader.read().unwrap();
    assert_eq!(val, 128);
    
    // Read byte as `i8`
    let val: i8 = reader.read().unwrap();
    assert_eq!(val, -1);
    
    // Read two bytes as `u16`  
    let val: u16 = reader.read().unwrap();
    assert_eq!(val, 257);
    
    // Read two bytes as `u8` array
    let val: [u8; 2] = reader.read_array().unwrap();
    assert_eq!(val, [1, 255]);
}

See examples for advanced usage.

Examples

  • basic — basic read/write.
    cargo run --example basic
    

License

Here we simply comply with the suggested dual licensing according to Rust API Guidelines (C-PERMISSIVE).

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.