cursor_binary_parser/
lib.rs

1//! A binary parsing utility that provides a cursor-like interface for reading binary data.
2//! 
3//! This module provides a `BinaryCursor` type that wraps a `std::io::Cursor<T>` where T implements `AsRef<[u8]>`
4//! and adds functionality for parsing various types of binary data, as well as managing a location stack
5//! for temporary position changes.
6//! 
7//! This project is heavily inspired by nom, but with the intention of not consuming the input data.
8//! 
9//! # Examples
10//! 
11//! ```rust
12//! use cursor_binary_parser::binary_cursor::{BinaryCursor, BinaryCursorJump};
13//! 
14//! // Can be used with Vec<u8>
15//! let data = vec![0x42, 0x24, 0x00, 0x01];
16//! let mut cursor = BinaryCursor::new(&data);
17//! 
18//! // Parse a u8
19//! let value = cursor.parse_u8().unwrap();
20//! assert_eq!(value, 0x42);
21//! 
22//! // Can also be used with &[u8]
23//! let slice: &[u8] = &[0x42, 0x24, 0x00, 0x01];
24//! let mut cursor = BinaryCursor::new(slice);
25//! 
26//! // Use BinaryCursorJump for temporary position changes
27//! {
28//!     let mut jump = BinaryCursorJump::new(&mut cursor);
29//!     jump.jump(2).unwrap();
30//!     let value = jump.cursor.parse_u16_le().unwrap();
31//!     assert_eq!(value, 0x0100);
32//! }
33//! // Position is automatically restored after jump
34//! ```
35
36pub mod binary_cursor;