2 releases

Uses new Rust 2024

new 0.0.2 Apr 16, 2025
0.0.1 Apr 15, 2025

#29 in #access

Download history 88/week @ 2025-04-09

88 downloads per month

MIT/Apache

15KB
276 lines

bytecord

License

This project is dual-licensed under:


lib.rs:

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.

No runtime deps