1pub type Result<T> = core::result::Result<T, Error>;
5
6#[derive(Debug, thiserror::Error, PartialEq, Eq)]
10#[non_exhaustive]
11pub enum Error {
12 #[error("buffer too short: need {need} bytes, have {have} (while parsing {what})")]
14 BufferTooShort {
15 need: usize,
17 have: usize,
19 what: &'static str,
21 },
22
23 #[error("invalid MODE: {mode} (must be 0 or 1 per EN 302 755 §5.1.7)")]
25 InvalidMode {
26 mode: u8,
28 },
29
30 #[error("unsupported TS/GS: 0x{ts_gs:02X}")]
32 UnsupportedTsGs {
33 ts_gs: u8,
35 },
36
37 #[error("serialize: output buffer too small — need {need}, have {have}")]
39 OutputBufferTooSmall {
40 need: usize,
42 have: usize,
44 },
45
46 #[error("invalid ISSY form: {reason} (EN 302 755 Annex C)")]
48 InvalidIssyForm {
49 reason: &'static str,
51 },
52
53 #[error(
57 "DFL={dfl} bits exceeds maximum {max} bits (EN 302 307-1 §5.1.4 S2 normal frame; \
58 DVB-T2 tighter per EN 302 755 Table 2)"
59 )]
60 DflOutOfRange {
61 dfl: u16,
63 max: u16,
65 },
66}
67
68#[cfg(test)]
69mod tests {
70 use super::*;
71
72 #[test]
73 fn buffer_too_short_message_contains_values() {
74 let err = Error::BufferTooShort {
75 need: 10,
76 have: 5,
77 what: "BBHEADER",
78 };
79 let msg = format!("{err}");
80 assert!(msg.contains("10") && msg.contains("5") && msg.contains("BBHEADER"));
81 }
82
83 #[test]
84 fn invalid_mode_message_contains_clause_ref() {
85 let err = Error::InvalidMode { mode: 3 };
86 let msg = format!("{err}");
87 assert!(msg.contains("5.1.7"));
88 }
89}