dvb_vbi/error.rs
1//! Error type for VBI (ETSI EN 301 775) PES data-field parsing and serialization.
2
3/// Result alias for VBI parsing.
4pub type Result<T> = core::result::Result<T, Error>;
5
6/// A VBI 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 /// A `data_unit_length` field did not match the bytes the typed payload
29 /// occupies (EN 301 775 §4.4, Table 1).
30 #[error("invalid data_unit_length {length} for data_unit_id {id:#04X}: {reason}")]
31 InvalidDataUnitLength {
32 /// The `data_unit_length` value.
33 length: u8,
34 /// The `data_unit_id` it applied to.
35 id: u8,
36 /// Why it is invalid.
37 reason: &'static str,
38 },
39 /// A field value did not fit in its wire bit-width (e.g. `line_offset`
40 /// beyond 5 bits, `first_pixel_position` beyond 16 bits).
41 #[error("field {what} value {value} does not fit in {bits} bits")]
42 FieldTooWide {
43 /// The over-wide field name.
44 what: &'static str,
45 /// The offending value.
46 value: u32,
47 /// The field width on the wire.
48 bits: u32,
49 },
50 /// A field value violated a spec constraint (e.g. `n_pixels` must be > 0,
51 /// ETSI EN 301 775 §4.9.2).
52 #[error("invalid field {what}: {reason}")]
53 InvalidField {
54 /// The field name.
55 what: &'static str,
56 /// Why it is invalid.
57 reason: &'static str,
58 },
59}