MCPcopy Index your code
hub / github.com/andylokandy/byte

github.com/andylokandy/byte @0.2.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.2.3 ↗ · + Follow
48 symbols 85 edges 8 files 5 documented · 10%

Browse by type

Functions 38 Types & classes 10
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Byte

build status crates.io docs.rs

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:

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

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 19
Method 19
Enum 4
Class 3
Interface 3

Languages

Rust100%

Modules by API surface

src/lib.rs13 symbols
benches/lib.rs13 symbols
tests/lib.rs11 symbols
src/ctx/str.rs4 symbols
src/ctx/bytes.rs3 symbols
src/ctx/num.rs2 symbols
src/ctx/bool.rs2 symbols

For agents

$ claude mcp add byte \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page