1#[non_exhaustive]
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub enum FrameError {
5 Empty,
7 InvalidPrefix(char),
9 MalformedChecksum,
11 BadChecksum { expected: u8, computed: u8 },
13 MalformedTagBlock,
15 TooShort,
17}
18
19impl core::fmt::Display for FrameError {
20 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21 match self {
22 Self::Empty => write!(f, "empty input"),
23 Self::InvalidPrefix(c) => write!(f, "invalid prefix '{c}', expected '$' or '!'"),
24 Self::MalformedChecksum => write!(f, "checksum is not valid hexadecimal"),
25 Self::BadChecksum { expected, computed } => {
26 write!(
27 f,
28 "checksum mismatch: expected {expected:02X}, computed {computed:02X}"
29 )
30 }
31 Self::MalformedTagBlock => write!(f, "malformed IEC 61162-450 tag block"),
32 Self::TooShort => write!(f, "sentence too short"),
33 }
34 }
35}
36
37impl std::error::Error for FrameError {}