1use nom::error::{ErrorKind, FromExternalError, ParseError};
2use thiserror::Error;
3
4#[derive(Error, Debug, Clone, Eq, PartialEq)]
6#[allow(variant_size_differences)] pub enum Error<'a> {
8 #[error("Out of bounds")]
10 OutOfBounds,
11
12 #[error("Invalid reference")]
14 InvalidReference(u16),
15
16 #[error("Unsupported tag")]
18 UnsupportedType(u8),
19
20 #[error("Nom internal error")]
22 Nom(&'a [u8], ErrorKind),
23
24 #[error("Packet has too many headers or messages")]
26 PacketTooLarge,
27
28 #[error("Object not in reference table")]
30 ObjectMissingFromReferenceTable(u64),
31
32 #[error("IO error: {0}")]
34 IoError(String, std::io::ErrorKind),
35}
36
37impl<'a> ParseError<&'a [u8]> for Error<'a> {
38 fn from_error_kind(input: &'a [u8], kind: ErrorKind) -> Self {
39 Error::Nom(input, kind)
40 }
41
42 fn append(_: &[u8], _: ErrorKind, other: Self) -> Self {
43 other
44 }
45}
46
47impl<'a, E> FromExternalError<&'a [u8], E> for Error<'a> {
48 fn from_external_error(input: &'a [u8], kind: ErrorKind, _e: E) -> Self {
49 Error::Nom(input, kind)
50 }
51}