Skip to main content

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("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 `data_identifier` was not the required `0x20`.
21    #[error("bad data_identifier: {0:#04X} (expected 0x20)")]
22    BadDataIdentifier(u8),
23    /// The `sync_byte` was not the required `0x0F`.
24    #[error("bad sync_byte: {0:#04X} (expected 0x0F)")]
25    BadSyncByte(u8),
26    /// The `end_of_PES_data_field_marker` was not `0xFF`.
27    #[error("bad end_of_PES_data_field_marker: {0:#04X} (expected 0xFF)")]
28    BadEndOfPesMarker(u8),
29    /// An unrecognised or invalid segment_type was encountered.
30    #[error("unknown segment_type: {0:#04X}")]
31    UnknownSegmentType(u8),
32    /// An unrecognised or invalid data_type in a pixel-data sub-block.
33    #[error("unknown data_type: {0:#04X}")]
34    UnknownDataType(u8),
35    /// An unrecognised or invalid object_coding_method.
36    #[error("unknown object_coding_method: {0:#02X}")]
37    UnknownObjectCodingMethod(u8),
38    /// Stuffing byte was not 0x00.
39    #[error("non-zero stuffing byte: {0:#04X} (expected 0x00)")]
40    BadStuffingByte(u8),
41    /// Segment length too large for parsed data.
42    #[error("segment too large to serialize: segment_length oversized")]
43    SegmentTooLarge,
44}