use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[cfg(feature = "std")]
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Invalid magic number: {0}")]
InvalidMagic(u32),
#[error("Invalid version: {0}")]
InvalidVersion(u16),
#[error("Unsupported format: {0}")]
UnsupportedFormat(String),
#[error("Parse error at offset {offset}: {message}")]
Parse {
offset: usize,
message: String,
},
#[error("Invalid link type: {0}")]
InvalidLinkType(u16),
#[error("Invalid packet length: {0}")]
InvalidPacketLength(usize),
#[error("Truncated data: expected {expected} bytes, got {actual}")]
Truncated {
expected: usize,
actual: usize,
},
#[error("Invalid timestamp: {0}")]
InvalidTimestamp(String),
#[error("No such interface: {0}")]
NoSuchInterface(u16),
#[error("Unknown block type: {0}")]
UnknownBlockType(u32),
#[error("Dissection error: {0}")]
Dissection(String),
}
impl Error {
pub fn parse(offset: usize, message: impl Into<String>) -> Self {
Self::Parse {
offset,
message: message.into(),
}
}
pub fn truncated(expected: usize, actual: usize) -> Self {
Self::Truncated { expected, actual }
}
}