Crate tbytes

source ·
Expand description

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 for no-std.

Usage

It would be easier to start from an example:

use tbytes::{TBytesReader, TBytesReaderFor};

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

Limitations

  • We currently supports only numeric types.
  • At the moment only little endian is supported.

Re-exports

Modules