Skip to main content

mpeg_pes/
error.rs

1//! Error type for PES parsing.
2
3/// Result alias for PES parsing.
4pub type Result<T> = core::result::Result<T, Error>;
5
6/// A PES parse 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    /// `packet_start_code_prefix` was not `0x000001`.
21    #[error("invalid packet_start_code_prefix: {0:#08X} (expected 0x000001)")]
22    BadStartCode(u32),
23    /// A required `marker_bit` was not `1` in a PTS/DTS field.
24    #[error("bad timestamp marker bit in {0}")]
25    BadTimestampMarker(&'static str),
26    /// The PTS/DTS leading 4-bit prefix did not match the expected `0010`/`0011`/`0001`.
27    #[error("bad timestamp prefix in {0}")]
28    BadTimestampPrefix(&'static str),
29    /// `optional_fields` exceeds the 255-byte `PES_header_data_length` limit
30    /// (an 8-bit field) — cannot be serialized.
31    #[error("optional_fields too large to serialize: {0} bytes (max 255)")]
32    OptionalFieldsTooLarge(usize),
33}