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 NonAsciiAddress,
19}
20
21impl core::fmt::Display for FrameError {
22 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
23 match self {
24 Self::Empty => write!(f, "empty input"),
25 Self::InvalidPrefix(c) => write!(f, "invalid prefix '{c}', expected '$' or '!'"),
26 Self::MalformedChecksum => write!(f, "checksum is not valid hexadecimal"),
27 Self::BadChecksum { expected, computed } => {
28 write!(
29 f,
30 "checksum mismatch: expected {expected:02X}, computed {computed:02X}"
31 )
32 }
33 Self::MalformedTagBlock => write!(f, "malformed IEC 61162-450 tag block"),
34 Self::TooShort => write!(f, "sentence too short"),
35 Self::NonAsciiAddress => write!(f, "address field contains non-ASCII bytes"),
36 }
37 }
38}
39
40impl std::error::Error for FrameError {}