#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FrameError {
Empty,
InvalidPrefix(char),
MalformedChecksum,
BadChecksum { expected: u8, computed: u8 },
MalformedTagBlock,
TooShort,
}
impl core::fmt::Display for FrameError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Empty => write!(f, "empty input"),
Self::InvalidPrefix(c) => write!(f, "invalid prefix '{c}', expected '$' or '!'"),
Self::MalformedChecksum => write!(f, "checksum is not valid hexadecimal"),
Self::BadChecksum { expected, computed } => {
write!(
f,
"checksum mismatch: expected {expected:02X}, computed {computed:02X}"
)
}
Self::MalformedTagBlock => write!(f, "malformed IEC 61162-450 tag block"),
Self::TooShort => write!(f, "sentence too short"),
}
}
}
impl std::error::Error for FrameError {}