#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DecodeError {
UnexpectedEof {
needed: usize,
remaining: usize,
},
InvalidBool(u8),
InvalidChar(u32),
InvalidUtf8,
CollectionTooLarge {
len: u32,
limit: u32
},
UnknownVariant(u32),
}
impl core::fmt::Display for DecodeError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::UnexpectedEof { needed, remaining } => write!(f, "unexpected end of file: need {needed} bytes, {remaining} left"),
Self::InvalidBool(b) => write!(f, "invalid boolean byte: 0x{b:02X}"),
Self::InvalidChar(c) => write!(f, "invalid character: U+{c:04X}"),
Self::InvalidUtf8 => write!(f, "invalid UTF-8 in string field"),
Self::CollectionTooLarge { len, limit } => write!(f, "collection length {len} exceeds safety limit {limit}"),
Self::UnknownVariant(idx) => write!(f, "unknown variant index: {idx}")
}
}
}
impl core::error::Error for DecodeError {}