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 endianis supported.
Re-exports
pub use bytes_reader::TBytesReader;pub use bytes_reader::TBytesReaderBackend;pub use bytes_reader::TBytesReaderFor;pub use bytes_writer::BytesWriterFor;pub use bytes_writer::TBytesWriter;pub use bytes_writer::TBytesWriterBackend;
Modules
- Bytes reader.
- Bytes writer.
- Errors.