#pack #struct #unpack #reader-writer #binary-data #binary

byteorder-pack

A binary data reader and writer that is similar to Python's struct module

1 unstable release

0.1.0 Apr 24, 2022

#2473 in Encoding

Download history 1/week @ 2024-11-13 7/week @ 2024-11-20 13/week @ 2024-11-27 19/week @ 2024-12-04 16/week @ 2024-12-11 8/week @ 2024-12-18 2/week @ 2025-01-08 6/week @ 2025-01-15 14/week @ 2025-02-05 16/week @ 2025-02-12 24/week @ 2025-02-26

54 downloads per month
Used in 2 crates

MIT license

13KB
204 lines

byteorder-pack

A binary data reader and writer that is similar to Python's struct module, but makes use of Rust's typing system.

Example

use std::io::Cursor;
use byteorder_pack::UnpackFrom;

let mut cursor = Cursor::new(vec![0x01, 0x02, 0x00, 0x03, 0x00, 0x04]);

let (a, b, cd) = <(u8, u8, [u16; 2])>::unpack_from_be(&mut cursor).unwrap();

assert_eq!(a, 1);
assert_eq!(b, 2);
assert_eq!(cd, [3, 4]);

lib.rs:

byteorder-pack

A binary data reader and writer that is similar to Python's struct module, but makes use of Rust's typing system.

Example

use std::io::Cursor;
use byteorder_pack::UnpackFrom;

let mut cursor = Cursor::new(vec![0x01, 0x02, 0x00, 0x03, 0x00, 0x04]);

let (a, b, cd) = <(u8, u8, [u16; 2])>::unpack_from_be(&mut cursor).unwrap();

assert_eq!(a, 1);
assert_eq!(b, 2);
assert_eq!(cd, [3, 4]);

Dependencies

~125KB