Crates.io | byte |
lib.rs | byte |
version | 0.2.7 |
source | src |
created_at | 2017-06-27 16:32:36.173534 |
updated_at | 2024-02-07 05:07:48.918739 |
description | A low-level, zero-copy and panic-free serializer and deserializer for binary. |
homepage | https://github.com/andylokandy/byte |
repository | https://github.com/andylokandy/byte |
max_upload_size | |
id | 20967 |
size | 42,093 |
Byte
A low-level, zero-copy and panic-free binary serializer and deserializer.
Add the following to your Cargo.toml
:
[dependencies]
byte = "0.2"
Byte
is a no_std
library; it can be used in any #![no_std]
situation or crate.
Byte
is designed to encode or decode binary data in a fast and low-level way.
A classical use case is I2C communication en/decoding.
Byte
provides two core traits TryRead
and TryWrite
.
Types that implement these traits can be serialized into or deserialized from byte slices.
The library is meant to be simple, and it will always be.
use byte::*;
let bytes: &[u8] = &[0xde, 0xad, 0xbe, 0xef];
let offset = &mut 0;
let num = bytes.read_with::<u32>(offset, BE).unwrap();
assert_eq!(num, 0xdeadbeef);
assert_eq!(*offset, 4);
use byte::*;
use byte::ctx::{Str, NULL};
let bytes: &[u8] = b"hello, world!\0dump";
let offset = &mut 0;
let str = bytes.read_with::<&str>(offset, Str::Delimiter(NULL)).unwrap();
assert_eq!(str, "hello, world!");
assert_eq!(*offset, 14);
All kinds of contribution are welcomed.
Issues. 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.
Licensed under MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)