dvb_t2mi/error.rs
1//! Error type returned by every parser in this crate.
2
3use thiserror::Error;
4
5/// Crate-wide result alias.
6pub type Result<T> = core::result::Result<T, Error>;
7
8/// Error variants that parsers + builders can return.
9///
10/// Spec references inside `#[error(...)]` strings quote clauses from
11/// ETSI TS 102 773 v1.4.1 where applicable.
12#[derive(Debug, Error, PartialEq, Eq)]
13#[non_exhaustive]
14pub enum Error {
15 /// Input buffer was shorter than the smallest valid encoding for the type.
16 #[error("buffer too short: need {need} bytes, have {have} (while parsing {what})")]
17 BufferTooShort {
18 /// Bytes required to proceed.
19 need: usize,
20 /// Bytes actually available.
21 have: usize,
22 /// Human-readable name of the type or field being parsed.
23 what: &'static str,
24 },
25
26 /// `packet_type` byte is not in Table 1 (0x00..=0x02, 0x10..=0x12, 0x20..=0x21, 0x30..=0x33).
27 #[error("invalid T2-MI packet_type {found:#04x} — reserved per ETSI TS 102 773 Table 1")]
28 InvalidPacketType {
29 /// Byte value actually read.
30 found: u8,
31 },
32
33 /// A reserved bit was not in the expected state.
34 #[error("reserved bits violation in {field}: {reason}")]
35 ReservedBitsViolation {
36 /// Where.
37 field: &'static str,
38 /// Why.
39 reason: &'static str,
40 },
41
42 /// Write buffer passed to `serialize_into` was smaller than `serialized_len()`.
43 #[error("serialize: output buffer too small — need {need}, have {have}")]
44 OutputBufferTooSmall {
45 /// Required size.
46 need: usize,
47 /// Actual size.
48 have: usize,
49 },
50
51 /// Payload length declared more bits than remaining bytes.
52 #[error(
53 "payload length mismatch: {declared_bits} bits declared, {remaining_bytes} bytes remaining"
54 )]
55 PayloadLengthMismatch {
56 /// Declared payload_len_bits from header.
57 declared_bits: u16,
58 /// Actual remaining bytes.
59 remaining_bytes: usize,
60 },
61
62 /// CRC-32 validation failed.
63 #[error("CRC-32 mismatch: computed {computed:#010x}, expected {expected:#010x}")]
64 CrcMismatch {
65 /// CRC we calculated over the payload bytes.
66 computed: u32,
67 /// CRC carried at the end of the packet.
68 expected: u32,
69 },
70}