pub struct Section<'a> {
pub table_id: u8,
pub section_syntax_indicator: bool,
pub private_indicator: bool,
pub extension_id: u16,
pub version_number: u8,
pub current_next_indicator: bool,
pub section_number: u8,
pub last_section_number: u8,
pub payload: &'a [u8],
pub byte1_reserved: u8,
pub byte5_reserved: u8,
/* private fields */
}Expand description
A parsed PSI/SI section header, borrowing the raw input buffer for payload.
Created via Section::parse(bytes). Does not validate the CRC on
construction — call Section::validate_crc (or the raw-byte
validate_crc) explicitly.
Fields§
§table_id: u8Table identifier.
section_syntax_indicator: boolWhen true the section uses the long-form syntax (has extension header
and CRC). When false only the 3-byte header is present (short form,
e.g. TDT — but see the module docs for the TOT exception: SSI=0 yet
CRC present; parse TOT via tables::tot, not this path).
private_indicator: boolPrivate indicator bit (meaning is table-specific).
extension_id: u16Table ID extension (aka table_id_extension). Present only for
long-form sections; zero for short-form.
version_number: u8Version number (5 bits). Present only for long-form sections.
current_next_indicator: boolcurrent_next_indicator flag. Present only for long-form sections.
section_number: u8Section number within the table sub-table.
last_section_number: u8Number of the last section in the table sub-table.
payload: &'a [u8]Section payload: excludes the header bytes and the trailing CRC for
long-form sections. For short-form sections this is bytes
3..(section_length + 3).
byte1_reserved: u8The 2 reserved bits of byte 1 (spec convention 0b11) — kept so a
section that does not use the convention still round-trips.
byte5_reserved: u8The 2 reserved bits of byte 5 (spec convention 0b11); only
meaningful for long-form sections.
Implementations§
Source§impl<'a> Section<'a>
impl<'a> Section<'a>
Sourcepub fn serialize(&self) -> Result<Vec<u8>>
pub fn serialize(&self) -> Result<Vec<u8>>
The section as its own bytes: header, payload and, for a long-form section, a freshly computed CRC_32.
§Errors
Error::FieldOverflow when a header field does not fit its wire
width (see section_length).
Sourcepub fn payload(&self) -> &'a [u8] ⓘ
pub fn payload(&self) -> &'a [u8] ⓘ
Return the payload slice (same as the payload field — convenience
getter for code that has a &Section reference).
Sourcepub fn section_length(&self) -> usize
pub fn section_length(&self) -> usize
section_length implied by payload and the syntax
indicator (ISO/IEC 13818-1 §2.4.4.1): the byte count after the 3-byte
header.
Sourcepub fn crc32(&self) -> Option<u32>
pub fn crc32(&self) -> Option<u32>
The CRC_32 the section carried when it was parsed; None for
short-form sections.
Sourcepub fn validate_crc(&self) -> Result<()>
pub fn validate_crc(&self) -> Result<()>
Validate the CRC_32 this section currently carries, recomputed from its fields.
The CRC is never stored: Serialize always recomputes it, so this
is the value a serialized section will carry, even after the payload
was edited.
§Errors
Returns Error::CrcMismatch when the recomputed CRC is not the one
the section was parsed from (only possible for bytes that carried a
wrong CRC). Always Ok(()) for short-form sections.
Trait Implementations§
impl<'a> Eq for Section<'a>
Source§impl<'a> Parse<'a> for Section<'a>
impl<'a> Parse<'a> for Section<'a>
Source§fn parse(bytes: &'a [u8]) -> Result<Self>
fn parse(bytes: &'a [u8]) -> Result<Self>
Parse a complete section from bytes.
§Errors
Error::BufferTooShort— fewer than 3 bytes supplied.Error::SectionLengthOverflow—section_lengthfield declares more data thanbytescontains.
Source§impl Serialize for Section<'_>
impl Serialize for Section<'_>
Source§type Error = Error
type Error = Error
Parse impl, but need not be).Source§fn serialized_len(&self) -> usize
fn serialized_len(&self) -> usize
serialize_into will write.Source§fn serialize_into(&self, buf: &mut [u8]) -> Result<usize>
fn serialize_into(&self, buf: &mut [u8]) -> Result<usize>
buf. Returns the number of bytes
written (always equal to serialized_len()).Source§fn try_to_bytes(&self) -> Result<Vec<u8>, Self::Error>
fn try_to_bytes(&self) -> Result<Vec<u8>, Self::Error>
Vec and serialize into it, returning the serializer’s error instead of
panicking. This is the only
allocate-and-serialize entry point: there is deliberately no panicking
to_bytes (hand-built values, or values assembled from damaged wire data,
can violate a wire constraint, so the error must reach the caller).