dvb_ule/error.rs
1//! Error type for ULE (RFC 4326 / RFC 5163) parsing and serialization.
2
3/// Result alias for ULE parsing.
4pub type Result<T> = core::result::Result<T, Error>;
5
6/// A ULE parse / serialize error.
7#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10 /// Input shorter than required.
11 #[error("buffer too short: need {need}, have {have} ({what})")]
12 BufferTooShort {
13 /// Bytes required.
14 need: usize,
15 /// Bytes available.
16 have: usize,
17 /// What was being parsed.
18 what: &'static str,
19 },
20 /// The output buffer passed to `serialize_into` was too small.
21 #[error("output buffer too small: need {need}, have {have}")]
22 OutputBufferTooSmall {
23 /// Bytes required.
24 need: usize,
25 /// Bytes available.
26 have: usize,
27 },
28 /// The SNDU `Length` field is inconsistent with the available bytes.
29 ///
30 /// `Length` counts from the byte after the Type field up to and including
31 /// the CRC (RFC 4326 §4.2).
32 #[error("invalid SNDU length {length}: {reason}")]
33 InvalidLength {
34 /// The `Length` field value.
35 length: u16,
36 /// Why it is invalid.
37 reason: &'static str,
38 },
39 /// The 32-bit CRC trailer did not match the recomputed value (RFC 4326 §4.6).
40 #[error("SNDU CRC mismatch: computed {computed:#010X}, found {found:#010X}")]
41 CrcMismatch {
42 /// CRC recomputed over the SNDU.
43 computed: u32,
44 /// CRC read from the trailer.
45 found: u32,
46 },
47 /// A field value did not fit in its wire bit-width.
48 #[error("field {what} value {value} does not fit in {bits} bits")]
49 FieldTooWide {
50 /// The over-wide field name.
51 what: &'static str,
52 /// The offending value.
53 value: u32,
54 /// The field width on the wire.
55 bits: u32,
56 },
57 /// An extension header was malformed (bad H-LEN/H-Type or truncated body).
58 #[error("invalid extension header: {reason}")]
59 InvalidExtensionHeader {
60 /// Why the extension header is invalid.
61 reason: &'static str,
62 },
63 /// A TS packet payload was the wrong size or carried an invalid Payload
64 /// Pointer (RFC 4326 §6/§7).
65 #[error("TS mapping error: {reason}")]
66 TsMapping {
67 /// Why the TS payload could not be processed.
68 reason: &'static str,
69 },
70}