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
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum PID {
PAT,
CAT,
TSDT,
NIT,
SDT,
EIT,
RST,
TDT,
NetworkSynchronization,
RNT,
InbandSignalling,
Measurement,
DIT,
SIT,
NULL,
Reserved(u16),
Other(u16),
}
impl PID {
#[inline(always)]
pub fn is_section(self) -> bool {
match self {
PID::Other(..) | PID::NULL | PID::Reserved(..) => false,
_ => true,
}
}
#[inline(always)]
pub fn is_null(self) -> bool {
match self {
PID::NULL => true,
_ => false,
}
}
#[inline(always)]
pub fn is_other(self) -> bool {
match self {
PID::Other(..) => true,
_ => false,
}
}
}
impl From<u16> for PID {
fn from(d: u16) -> Self {
match d {
0x0000 => PID::PAT,
0x0001 => PID::CAT,
0x0002 => PID::TSDT,
0x0003..=0x000F => PID::Reserved(d),
0x0010 => PID::NIT,
0x0011 => PID::SDT,
0x0012 => PID::EIT,
0x0013 => PID::RST,
0x0014 => PID::TDT,
0x0015 => PID::NetworkSynchronization,
0x0016 => PID::RNT,
0x0017..=0x001B => PID::Reserved(d),
0x001C => PID::InbandSignalling,
0x001D => PID::Measurement,
0x001E => PID::DIT,
0x001F => PID::SIT,
0x1FFF => PID::NULL,
_ => PID::Other(d),
}
}
}
impl From<PID> for u16 {
fn from(pid: PID) -> u16 {
match pid {
PID::PAT => 0x0000,
PID::CAT => 0x0001,
PID::TSDT => 0x0002,
PID::NIT => 0x0010,
PID::SDT => 0x0011,
PID::EIT => 0x0012,
PID::RST => 0x0013,
PID::TDT => 0x0014,
PID::NetworkSynchronization => 0x0015,
PID::RNT => 0x0016,
PID::InbandSignalling => 0x001C,
PID::Measurement => 0x001D,
PID::DIT => 0x001E,
PID::SIT => 0x001F,
PID::NULL => 0x1FFF,
PID::Reserved(d) => d,
PID::Other(d) => d,
}
}
}