1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! Error type returned by every parser and builder in this crate.
use thiserror::Error;
/// Crate-wide result alias.
pub type Result<T> = core::result::Result<T, Error>;
/// Error variants that parsers + builders can return.
///
/// Spec references inside `#[error(...)]` strings quote clauses from
/// ITU-T H.222.0 (= ISO/IEC 13818-1) where applicable.
#[derive(Debug, Error, PartialEq, Eq, Clone)]
#[non_exhaustive]
pub enum Error {
/// Input buffer was shorter than the smallest valid encoding for the type.
#[error(transparent)]
BufferTooShort(#[from] broadcast_core::error::BufferTooShort),
/// CRC-32 validation failed for a table section.
#[error(transparent)]
CrcMismatch(#[from] broadcast_core::error::CrcMismatch),
/// A fixed marker did not match (TS sync byte, expected `0x47`).
#[error(transparent)]
InvalidSync(#[from] broadcast_core::error::InvalidSync),
/// Write buffer passed to `serialize_into` was smaller than `serialized_len()`.
#[error(transparent)]
OutputBufferTooSmall(#[from] broadcast_core::error::OutputBufferTooSmall),
/// A `section_length` declared more bytes than the containing buffer could hold.
#[error("section_length {declared} exceeds remaining buffer ({available} bytes)")]
#[non_exhaustive]
SectionLengthOverflow {
/// Length bytes declared inside the section header.
declared: usize,
/// Bytes actually available after the header.
available: usize,
},
/// A payload was longer than a single TS packet's fixed payload capacity
/// (see `OwnedTsPacket::serialize_with_payload`, #1129).
#[error("payload {len} bytes exceeds the {max}-byte TS packet payload capacity")]
#[non_exhaustive]
PayloadTooLarge {
/// The payload length that did not fit.
len: usize,
/// The maximum payload capacity.
max: usize,
},
/// A PCR or ESCR value did not fit the 27 MHz clock: a base wider than
/// 33 bits, or an extension `>= 300` (the 9-bit wire field can carry
/// `300..=511`).
#[error(transparent)]
ClockOutOfRange(#[from] broadcast_common::clock33::ClockOutOfRange),
/// A length or count field's value does not fit its wire field
/// (see `broadcast_core::len`, #1129).
#[error(transparent)]
FieldOverflow(#[from] broadcast_core::error::FieldOverflow),
/// The packet has no adaptation field, so it has no PCR (and no OPCR)
/// slot to rewrite.
#[error("packet has no adaptation field")]
NoAdaptationField,
/// The adaptation field has no PCR (or OPCR) slot: either it is shorter
/// than the flags byte plus the 6-byte field, or the packet's own flag
/// byte does not set the corresponding flag.
#[error("packet has no {which} slot")]
#[non_exhaustive]
NoClockReference {
/// The missing field: `"PCR"` or `"OPCR"`.
which: &'static str,
},
/// The adaptation field is shorter than the field being written into it.
#[error("adaptation field is {have} bytes, {need} needed")]
#[non_exhaustive]
AdaptationFieldTooShort {
/// Bytes the write needs.
need: usize,
/// `adaptation_field_length` the packet declares.
have: usize,
},
/// A descriptor loop ends with fewer bytes than a `descriptor()` header
/// (ISO/IEC 13818-1 §2.6).
#[error("descriptor header at loop offset {offset} needs {need} bytes, {have} remain")]
#[non_exhaustive]
DescriptorHeaderTruncated {
/// Offset of the truncated header inside the loop.
offset: usize,
/// Bytes the header needs.
need: usize,
/// Bytes left in the loop from that offset.
have: usize,
},
/// A descriptor declares a `descriptor_length` that runs past the end of
/// its loop (ISO/IEC 13818-1 §2.6).
#[error(
"descriptor {tag:#04X} at loop offset {offset} declares {declared} body bytes, {have} remain"
)]
#[non_exhaustive]
DescriptorBodyTruncated {
/// Offset of the descriptor header inside the loop.
offset: usize,
/// Its `descriptor_tag`.
tag: u8,
/// Its declared `descriptor_length`.
declared: usize,
/// Body bytes actually left in the loop.
have: usize,
},
}