use thiserror::Error;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, Error, PartialEq, Eq)]
pub enum Error {
#[error("buffer too short: need {need} bytes, have {have} (while parsing {what})")]
BufferTooShort {
need: usize,
have: usize,
what: &'static str,
},
#[error("invalid T2-MI packet_type {found:#04x} — reserved per ETSI TS 102 773 Table 1")]
InvalidPacketType {
found: u8,
},
#[error("reserved bits violation in {field}: {reason}")]
ReservedBitsViolation {
field: &'static str,
reason: &'static str,
},
#[error("serialize: output buffer too small — need {need}, have {have}")]
OutputBufferTooSmall {
need: usize,
have: usize,
},
#[error(
"payload length mismatch: {declared_bits} bits declared, {remaining_bytes} bytes remaining"
)]
PayloadLengthMismatch {
declared_bits: u16,
remaining_bytes: usize,
},
#[error("buffer too short for CRC validation")]
Truncated,
#[error("CRC-32 mismatch: expected {expected:#010x}, computed {computed:#010x}")]
InvalidCrc {
expected: u32,
computed: u32,
},
}