use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
pub enum DecodeError {
ZeroByte {
index: usize,
},
Truncated {
index: usize,
},
OutputTooSmall,
FrameTooLong {
len: usize,
},
}
impl fmt::Display for DecodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ZeroByte { index } => {
write!(f, "zero byte in encoded input at index {index}")
}
Self::Truncated { index } => {
write!(f, "length code at index {index} points past end of input")
}
Self::OutputTooSmall => f.write_str("destination buffer too small"),
Self::FrameTooLong { len } => {
write!(f, "unterminated frame exceeds maximum length ({len} bytes)")
}
}
}
}
impl core::error::Error for DecodeError {}