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