8 releases

0.2.7 Feb 7, 2024
0.2.6 Apr 11, 2021
0.2.4 Jun 23, 2019
0.2.3 Mar 2, 2018
0.2.1 Jun 28, 2017

#500 in Parser implementations

Download history 1820/week @ 2024-08-15 2084/week @ 2024-08-22 2796/week @ 2024-08-29 2475/week @ 2024-09-05 2162/week @ 2024-09-12 2297/week @ 2024-09-19 1551/week @ 2024-09-26 1211/week @ 2024-10-03 1481/week @ 2024-10-10 1275/week @ 2024-10-17 1382/week @ 2024-10-24 1704/week @ 2024-10-31 1588/week @ 2024-11-07 1507/week @ 2024-11-14 2019/week @ 2024-11-21 770/week @ 2024-11-28

6,197 downloads per month
Used in 18 crates (10 directly)

MIT/Apache

27KB
362 lines

Byte

build status crates.io docs.rs

A low-level, zero-copy and panic-free binary serializer and deserializer.

Documentation

Usage

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.

Overview

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.

Example

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

Contribution

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.

License

Licensed under MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

No runtime deps