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](https://docs.rs/tbytes/latest/tbytes/).
Installation
------------
```shell
cargo add tbytes
```
Usage
-----
Read bytes typed data from buffer:
```rust
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](#examples) for advanced usage.
Examples
--------
- [`basic`](./examples/basic.rs) — basic read/write.
```shell
cargo run --example basic
```
License
-------
> Here we simply comply with the suggested dual licensing according to
> [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/about.html) (C-PERMISSIVE).
Licensed under either of
* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
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.