nrbf_parser/lib.rs
1// nrbf-parser - A high-performance MS-NRBF binary parser and encoder.
2// Copyright (C) 2026 driedpampas@proton.me
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17//! A high-performance MS-NRBF binary parser and encoder.
18
19pub mod decoder;
20pub mod encoder;
21pub mod error;
22pub mod records;
23
24pub use decoder::Decoder;
25pub use encoder::Encoder;
26pub use error::Error;
27pub use records::Record;
28
29/// Convenience function to parse an NRBF stream from a reader.
30///
31/// Returns an iterator of records.
32pub fn parse<R: std::io::Read>(reader: R) -> impl Iterator<Item = error::Result<Record>> {
33 let mut decoder = Decoder::new(reader);
34 std::iter::from_fn(move || match decoder.decode_next() {
35 Ok(Some(record)) => Some(Ok(record)),
36 Ok(None) => None,
37 Err(e) => Some(Err(e)),
38 })
39}