pub struct TsPacket<'a> {
pub header: TsHeader,
pub payload: Option<&'a [u8]>,
pub raw: &'a [u8; 188],
/* private fields */
}Expand description
Borrowed view into one 188-byte TS packet.
Serde: Serialize-only (re-parse from wire bytes to reconstruct). raw is
excluded from the serialized form because it is redundant once the header
has been parsed.
Fields§
§header: TsHeaderParsed header fields.
payload: Option<&'a [u8]>Slice into the packet’s payload, or None when has_payload == false
or the adaptation field consumed the whole packet body.
raw: &'a [u8; 188]The raw 188 bytes of the packet — kept for cheap forwarding.
Implementations§
Source§impl<'a> TsPacket<'a>
impl<'a> TsPacket<'a>
Sourcepub fn parse(buf: &'a [u8]) -> Result<Self>
pub fn parse(buf: &'a [u8]) -> Result<Self>
Parse a single 188-byte TS packet from a buffer.
Returns Err(Error::InvalidSyncByte) if the first byte is not 0x47,
Err(Error::BufferTooShort) if fewer than 188 bytes, or Ok with
the parsed packet otherwise.
Examples found in repository?
27fn main() {
28 let pkt = TsPacket::parse(&PAT_PACKET).expect("hardcoded packet must parse");
29 println!(
30 "TS packet: pid=0x{:04X} pusi={} has_payload={}",
31 pkt.header.pid, pkt.header.pusi, pkt.header.has_payload
32 );
33
34 let mut reasm = SectionReassembler::default();
35
36 if let Some(payload) = pkt.payload {
37 reasm.feed(payload, pkt.header.pusi);
38 }
39
40 while let Some(section) = reasm.pop_section() {
41 println!(
42 "section: {} bytes, table_id=0x{:02X}",
43 section.len(),
44 section[0]
45 );
46 // The PAT section bytes: table_id=0x00, transport_stream_id at bytes 3-4.
47 if section.len() >= 5 {
48 let ts_id = u16::from_be_bytes([section[3], section[4]]);
49 println!(" transport_stream_id={}", ts_id);
50 }
51 }
52}Sourcepub fn adaptation_field(&self) -> Option<Result<AdaptationField>>
pub fn adaptation_field(&self) -> Option<Result<AdaptationField>>
Decode the adaptation field, if present.
Returns None when the packet carries no adaptation field, and
Some(Err(..)) when a present field is truncated. Layout per
ISO/IEC 13818-1:2007 §2.4.3.4 (docs/iso_13818_1_systems.md).