#binary #parser #bytes #scroll #no-std

no-std byte

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

7 releases

Uses old Rust 2015

0.2.6 Apr 11, 2021
0.2.5 Apr 11, 2021
0.2.4 Jun 23, 2019
0.2.3 Mar 2, 2018
0.2.1 Jun 28, 2017

#347 in Encoding

Download history 314/week @ 2022-12-07 223/week @ 2022-12-14 191/week @ 2022-12-21 206/week @ 2022-12-28 136/week @ 2023-01-04 222/week @ 2023-01-11 208/week @ 2023-01-18 466/week @ 2023-01-25 343/week @ 2023-02-01 203/week @ 2023-02-08 443/week @ 2023-02-15 589/week @ 2023-02-22 323/week @ 2023-03-01 605/week @ 2023-03-08 540/week @ 2023-03-15 440/week @ 2023-03-22

1,928 downloads per month
Used in 17 crates (8 directly)

MIT/Apache

26KB
361 lines

Byte

build status crates.io docs.rs

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

Documentation

Usage

First, add the following to your Cargo.toml:

[dependencies]
byte = "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 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 serialize into or deserialize 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.

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

No runtime deps