1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24#[cfg_attr(feature = "serde", derive(serde::Serialize))]
25#[non_exhaustive]
26pub enum RunningStatus {
27 Undefined,
29 NotRunning,
31 StartsInAFewSeconds,
33 Pausing,
35 Running,
37 ServiceOffAir,
39 Reserved(u8),
41}
42
43impl RunningStatus {
44 #[must_use]
46 pub fn from_u8(v: u8) -> Self {
47 match v & 0x07 {
48 0 => Self::Undefined,
49 1 => Self::NotRunning,
50 2 => Self::StartsInAFewSeconds,
51 3 => Self::Pausing,
52 4 => Self::Running,
53 5 => Self::ServiceOffAir,
54 r => Self::Reserved(r),
55 }
56 }
57
58 #[must_use]
60 pub fn to_u8(self) -> u8 {
61 match self {
62 Self::Undefined => 0,
63 Self::NotRunning => 1,
64 Self::StartsInAFewSeconds => 2,
65 Self::Pausing => 3,
66 Self::Running => 4,
67 Self::ServiceOffAir => 5,
68 Self::Reserved(v) => v & 0x07,
69 }
70 }
71
72 #[must_use]
74 pub fn name(self) -> &'static str {
75 match self {
76 Self::Undefined => "undefined",
77 Self::NotRunning => "not running",
78 Self::StartsInAFewSeconds => "starts in a few seconds",
79 Self::Pausing => "pausing",
80 Self::Running => "running",
81 Self::ServiceOffAir => "service off-air",
82 Self::Reserved(_) => "reserved",
83 }
84 }
85}
86
87#[cfg(test)]
88mod running_status_tests {
89 use super::*;
90
91 #[test]
92 fn from_u8_maps_known_values() {
93 assert_eq!(RunningStatus::from_u8(0), RunningStatus::Undefined);
94 assert_eq!(RunningStatus::from_u8(1), RunningStatus::NotRunning);
95 assert_eq!(
96 RunningStatus::from_u8(2),
97 RunningStatus::StartsInAFewSeconds
98 );
99 assert_eq!(RunningStatus::from_u8(3), RunningStatus::Pausing);
100 assert_eq!(RunningStatus::from_u8(4), RunningStatus::Running);
101 assert_eq!(RunningStatus::from_u8(5), RunningStatus::ServiceOffAir);
102 assert_eq!(RunningStatus::from_u8(6), RunningStatus::Reserved(6));
103 assert_eq!(RunningStatus::from_u8(7), RunningStatus::Reserved(7));
104 }
105
106 #[test]
107 fn to_u8_from_u8_round_trips_all_byte_values() {
108 for v in 0u8..=0xFFu8 {
109 assert_eq!(RunningStatus::to_u8(RunningStatus::from_u8(v)), v & 0x07);
110 }
111 }
112
113 #[test]
114 fn name_returns_known_strings() {
115 assert_eq!(RunningStatus::Undefined.name(), "undefined");
116 assert_eq!(RunningStatus::NotRunning.name(), "not running");
117 assert_eq!(RunningStatus::Running.name(), "running");
118 assert_eq!(RunningStatus::ServiceOffAir.name(), "service off-air");
119 assert_eq!(RunningStatus::Reserved(6).name(), "reserved");
120 }
121
122 #[test]
123 fn running_status_wire_to_name() {
124 assert_eq!(RunningStatus::from_u8(4).name(), "running");
125 assert_eq!(RunningStatus::from_u8(2).name(), "starts in a few seconds");
126 assert_eq!(RunningStatus::from_u8(0).name(), "undefined");
127 }
128}
129
130pub(crate) const SECTION_B1_FLAGS_PSI: u8 = 0xB0;
136
137pub(crate) const SECTION_B1_FLAGS_DVB: u8 = 0xF0;
143
144pub(crate) const SECTION_B1_SSI: u8 = 0x80;
146
147pub(crate) const SECTION_B1_RESERVED_HI: u8 = 0x30;
149
150pub(crate) const SECTION_B1_FLAGS_SHORT: u8 = 0x70;
155
156pub(crate) fn check_section_length(
166 bytes_len: usize,
167 header_len: usize,
168 section_length: usize,
169 min_total: usize,
170) -> crate::Result<usize> {
171 let total = header_len + section_length;
172 if bytes_len < total || total < min_total {
173 return Err(crate::error::Error::SectionLengthOverflow {
174 declared: section_length,
175 available: bytes_len.saturating_sub(header_len),
176 });
177 }
178 Ok(total)
179}
180
181pub mod any;
182pub use any::AnyTableSection;
183
184pub mod registry;
185pub use registry::{TableObject, TableRegistry};
186
187pub mod ait;
188pub mod bat;
189pub mod cat;
190pub mod cit;
191pub mod container;
192pub mod dit;
193pub mod downloadable_font_info;
194pub mod dsmcc;
195pub mod eit;
196pub mod int;
197pub mod mpe;
198pub mod mpe_fec;
199pub mod mpe_ifec;
200pub mod nit;
201pub mod pat;
202pub mod pmt;
203pub mod protection_message;
204pub mod rct;
205pub mod rnt;
206pub mod rst;
207pub mod sat;
208pub mod sdt;
209pub mod sit;
210pub mod st;
211pub mod tdt;
212pub mod tot;
213pub mod tsdt;
214pub mod unt;