Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kanarus/byte_reader
A minimal byte-by-byte reader for parsing input
https://github.com/kanarus/byte_reader
byte byte-array bytes lightweight minimal no-std parse parser parsing reader simple
Last synced: 18 days ago
JSON representation
A minimal byte-by-byte reader for parsing input
- Host: GitHub
- URL: https://github.com/kanarus/byte_reader
- Owner: kanarus
- License: mit
- Created: 2023-09-19T05:52:35.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-08T21:53:41.000Z (4 months ago)
- Last Synced: 2024-10-06T04:19:04.247Z (about 1 month ago)
- Topics: byte, byte-array, bytes, lightweight, minimal, no-std, parse, parser, parsing, reader, simple
- Language: Rust
- Homepage: https://crates.io/crates/byte_reader
- Size: 41.4 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
byte_reader
A minimal byte-by-byte reader for parsing input.
## Use case
Following situation:> I want to read and parse some input, but it's **not so large-scale** parsing task, so I'd like to avoid adding a *heavyweight* crate like [nom](https://crates.io/crates/nom) or [nom8](https://crates.io/crates/nom8) to my `dependencies` ...
Of course, `byte_reader` supports *no std* environment.
Usage
```rust
use byte_reader::Reader;fn main() {
// Get an input `&[u8]` from a File, standard input, or others
let sample_input = "Hello, byte_reader!".as_bytes();// Create mutable `r` for the input
let mut r = Reader::new(sample_input);// Use some simple operations
// to parse the input
r.consume("Hello").unwrap();
r.consume(",").unwrap();
r.skip_whitespace();
let name = r.read_while(|b| b != &b'!'); // b"byte_reader"
let name = String::from_utf8_lossy(name).to_string();
r.consume("!").unwrap();println!("Greeted to `{name}`.");
}
```
## Operations
- `remaining`
- `read_while`, `read_until`
- `next`, `next_if`
- `peek`, `peek2`, `peek3`
- `advance_by`, `unwind_by`
- `consume`, `consume_oneof`
- `skip_while`, `skip_whitespace`
## Features
### `"location"`
Enable tracking reader's location, **line** and **column** (1-origin), in the input bytes.
### `"text"`
Some utility methods for text-parsing are available:
- `read_quoted_by`
- `read_uint`, `read_int`
- `read_camel`, `read_snake`, `read_kebab`
## License
`byte_reader` is licensed under the MIT License ([LICENSE](https://github.com/kana-rus/byte_reader/blob/main/LICENSE) or [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT)).