dvb_subtitle/error.rs
1//! Error type for DVB subtitle parsing.
2
3/// Result alias for DVB subtitle parsing.
4pub type Result<T> = core::result::Result<T, Error>;
5
6/// A DVB subtitle parse or serialize error.
7#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10 /// Input shorter than required.
11 #[error(transparent)]
12 BufferTooShort(#[from] broadcast_common::error::BufferTooShort),
13
14 /// Output buffer smaller than the serialized form requires.
15 #[error(transparent)]
16 OutputBufferTooSmall(#[from] broadcast_common::error::OutputBufferTooSmall),
17
18 /// The `data_identifier` was not the required `0x20`.
19 #[error("bad data_identifier: {0:#04X} (expected 0x20)")]
20 BadDataIdentifier(u8),
21 /// A fixed marker did not match (`sync_byte`, expected `0x0F`).
22 #[error(transparent)]
23 InvalidSync(#[from] broadcast_common::error::InvalidSync),
24 /// The `end_of_PES_data_field_marker` was not `0xFF`.
25 #[error("bad end_of_PES_data_field_marker: {0:#04X} (expected 0xFF)")]
26 BadEndOfPesMarker(u8),
27 /// An unrecognised or invalid segment_type was encountered.
28 #[error("unknown segment_type: {0:#04X}")]
29 UnknownSegmentType(u8),
30 /// Stuffing byte was not 0x00.
31 #[error("non-zero stuffing byte: {0:#04X} (expected 0x00)")]
32 BadStuffingByte(u8),
33 /// Segment length too large for parsed data.
34 #[error("segment too large to serialize: segment_length oversized")]
35 SegmentTooLarge,
36 /// A field value did not fit its wire width (#1129/#1044): compared
37 /// before narrowing, so an over-range value is rejected instead of
38 /// silently masked/wrapped.
39 #[error(transparent)]
40 FieldOverflow(#[from] broadcast_common::len::FieldOverflow),
41 /// A `DisparityRegion` had 0 or more than 4 subregions — the wire
42 /// `number_of_subregions_minus_1` field (Table 29) is 2 bits, so only
43 /// 1..=4 subregions are representable.
44 #[error("invalid subregion count: {0} (must be 1..=4)")]
45 InvalidSubregionCount(usize),
46 /// A `Subregion`'s `subregion_horizontal_position`/`subregion_width`
47 /// presence didn't match the region's subregion count (Table 29: both
48 /// are present for every subregion when, and only when, the region has
49 /// more than one).
50 #[error("subregion position presence inconsistent with subregion count")]
51 SubregionPositionMismatch,
52 /// A repeating-entry loop (Table 31's CLUT entry loop; Table 21's page
53 /// composition region loop) had leftover bytes that don't form a whole
54 /// entry, where the spec's own loop condition never leaves a remainder.
55 #[error("{extra} trailing byte(s) in {what}: not a whole entry ({entry_len} bytes each)")]
56 TrailingEntryBytes {
57 /// What loop this was (e.g. `"alternative_CLUT_segment entries"`).
58 what: &'static str,
59 /// The fixed size of one entry.
60 entry_len: usize,
61 /// How many bytes were left over.
62 extra: usize,
63 },
64 /// A field value does not fit the bits the wire format gives it (e.g. a
65 /// reduced-range CLUT colour component wider than its 6/4/2-bit slot).
66 #[error(transparent)]
67 InvalidValue(#[from] broadcast_common::error::InvalidValue),
68}