| Crates.io | bytes_parser |
| lib.rs | bytes_parser |
| version | 0.1.5 |
| created_at | 2023-01-09 23:32:00.55961+00 |
| updated_at | 2024-05-20 07:58:33.419948+00 |
| description | A simple wrapper to parse primitive Rust types from a slice of bytes |
| homepage | https://github.com/detro/bytes_parser |
| repository | https://github.com/detro/bytes_parser |
| max_upload_size | |
| id | 754856 |
| size | 44,974 |
A simple wrapper to parse primitive Rust types from a slice of bytes [u8]
This is the crate for you, if all you need is to parse a bespoke binary protocol. You provide a reference slice of bytes, and assuming you know what those bytes represent, read the original values out of it.
The core of this crate is BytesParser, built with few principles in mind:
&str and sub-slice of &[u8].ParsingEndian).BytesParserError).use bytes_parser::{BytesParser, ParsingEndian};
let input: &[u8] = /* a slice of bytes from somewhere */;
// Crate a parser from a given slice of bytes
let mut parser = BytesParser::from(input);
// Will use Big-Endian parsing
assert_eq!(parser.endian(), ParsingEndian::BE);
assert_eq!(ParsingEndian::BE, ParsingEndian::default());
// Parse a string length and the string itself
let str_len = parser.parse_usize()?;
let str = parser.parse_str_utf8(str_len)?;
assert_eq!(str, "Forza Napoli Sempre!");
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.