2 releases

Uses new Rust 2024

0.0.2 Apr 16, 2025
0.0.1 Apr 15, 2025

#711 in Network programming

Download history 217/week @ 2025-04-11 55/week @ 2025-04-18 1/week @ 2025-04-25 6/week @ 2025-05-02 5/week @ 2025-05-09

104 downloads per month

MIT/Apache

54KB
330 lines

bytecord

Provides zero-copy access to byte data with guaranteed alignment and bounds checking. Designed for parsing binary formats, network protocols, and memory-mapped I/O.

Features

  • Alignment-aware operations (align=1|2|4|8|16|...)
  • Bounds-checked access
  • Zero-copy views into data
  • Supports both owned and borrowed buffers

Examples

reading:

use bytecord::{ByteCord, ByteCordReader};

let data = vec![0u8; 1024];
let cord = ByteCord::new(data);

// Read with 4-byte alignment
let mut reader = cord.read_with_alignment(4);
let header = reader.next_n(16).unwrap();

building:

use bytecord::ByteCordBuilder;

// a new builer with alignment of 1 byte (meaning no alignment)
let mut data = ByteCordBuilder::new(1);
data.append_le_u32(1111);
data.append_u8(1);
data.append_le_i64(-3919);
let slice = data.into_boxed_slice();

Safety

All operations are bounds-checked. Unsafe code is strictly contained and documented.


bytecord icon

A lightweight utility library for reading and building binary data with alignment.


Usage

Add this library to your project by:

cargo add bytecord

Example

reading:

use bytecord::ByteCord;

let data = vec![0u8; 1024];
let cord = ByteCord::new(data);

// Read with 4-byte alignment
let mut reader = cord.read_with_alignment(4);
let a = cord.next_be_u32().unwrap();
let b = cord.next_n(a).unwrap();

building:

use bytecord::ByteCordBuilder;

// a new builer with alignment of 1 byte (meaning no alignment)
let mut data = ByteCordBuilder::new(1);
data.append_le_u32(1111);
data.append_u8(1);
data.append_le_i64(-3919);
let slice = data.into_boxed_slice();

License

This project is dual-licensed under:

No runtime deps