nrbf_parser/error.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
17use std::io;
18use thiserror::Error;
19
20/// Result type for NRBF parsing.
21pub type Result<T> = std::result::Result<T, Error>;
22
23#[derive(Error, Debug)]
24
25pub enum Error {
26 #[error("IO error: {0}")]
27 Io(#[from] io::Error),
28
29 #[error("Invalid record type: {0}")]
30 InvalidRecordType(u8),
31
32 #[error("Invalid binary type: {0}")]
33 InvalidBinaryType(u8),
34
35 #[error("Invalid primitive type: {0}")]
36 InvalidPrimitiveType(u8),
37
38 #[error("Invalid UTF-8 string")]
39 InvalidUtf8(#[from] std::string::FromUtf8Error),
40
41 #[error("Invalid length-prefixed string: {0}")]
42 InvalidStringLength(i32),
43
44 #[error("Custom error: {0}")]
45 Custom(String),
46}