use std::time::Duration;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum PcapError {
#[error(transparent)]
Parse(#[from] PcapParseError),
#[error(transparent)]
Read(#[from] PcapReadError),
#[error(transparent)]
Write(#[from] PcapWriteError),
#[error(transparent)]
Validation(#[from] PcapValidationError),
}
#[derive(Debug, Error)]
pub enum PcapParseError {
#[error("The buffer too small: need {0}B, got {1}B")]
IncompleteBuffer(usize, usize),
#[error(transparent)]
Validation(#[from] PcapValidationError),
}
#[derive(Debug, Error)]
pub enum PcapReadError {
#[error("I/O error while reading the pcap")]
Io(#[source] std::io::Error),
#[error(transparent)]
Validation(#[from] PcapValidationError),
}
#[derive(Debug, Error)]
pub enum PcapWriteError {
#[error("I/O error while writing the pcap")]
Io(#[source] std::io::Error),
#[error("I/O error while writing the field {0}")]
FieldWriteFailed(&'static str, #[source] std::io::Error),
#[error(transparent)]
Validation(#[from] PcapValidationError),
}
#[derive(Debug, Error)]
pub enum PcapValidationError {
#[error("Invalid magic number: {0:#X}")]
InvalidMagicNumber(u32),
#[error("Ts_frac micro too big: {0} >= 1_000_000 us")]
TsFracMicroTooBig(u32),
#[error("Ts_frac nano too big: {0} >= 1_000_000_000 ns")]
TsFracNanoTooBig(u32),
#[error("Timestamp too big: {0:?} > 2^32 seconds")]
TimestampTooBig(Duration),
#[error("included_len > snap_len: {0} > {1}")]
IncludedLenTooBig(u32, u32),
#[error("origin_len < included_len: {0} < {1}")]
OriginLenTooSmall(u32, u32),
#[error("data length too big: {0} > u32::MAX")]
DataTooBig(usize),
#[error("Packet length > snap_len: {0} > {1}")]
PacketLenTooBig(u32, u32),
}