Byte
A low-level, zero-copy, panic-free, binary serializer and deserializer
This crate is inspired by m4b/scroll
Documentation
Usage
First, add the following to your Cargo.toml
:
[]
= "0.2"
Next, add this to your crate root:
extern crate byte;
Byte
is no_std
library; it can directly be used in a #![no_std]
situation or crate.
Overview
Byte
is mainly used to encode and decode binary data with standard or protocol,
such as network TCP packages and hardware communication packages.
It's similar to crate nom
but more ligthweight and specialized for operating binary in low-level and hardware programing.
Byte
delivers two core traits TryRead
and TryWrite
.
Types implement these traits can be serialize into or deserialize from byte slices.
Byte slices [u8]
derives methods read()
and write()
to serialize, deserialize and handle offset.
Small and general is kept in mind in this library.
For example, Byte
can take byte slice from MMap to read binary file,
or take heap-allocated byte buffer from Bytes.
Example
use *;
let bytes: & = &;
let offset = &mut 0;
let num = bytes..unwrap;
assert_eq!;
assert_eq!;
use *;
use ;
let bytes: & = b"hello, world!\0dump";
let offset = &mut 0;
let str = bytes..unwrap;
assert_eq!;
assert_eq!;
Contribution
All kinds of contribution are welcomed.
- Issus. Feel free to open an issue when you find typos, bugs, or have any question.
- Pull requests. New collection, better implementation, more tests, more documents and typo fixes are all welcomed.
License
Licensed under MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)