pub struct Header {
pub packet_type: PacketType,
pub packet_count: u8,
pub superframe_idx: u8,
pub t2mi_stream_id: u8,
pub payload_len_bits: u16,
}Expand description
T2-MI packet header (6 bytes / 48 bits) per §5.1.
Layout:
- byte 0: packet_type (8 bits) — Table 1
- byte 1: packet_count (8 bits) — wraps 0xFF→0x00, arbitrary start
- byte 2
[7:4]: superframe_idx (4 bits) - byte 2
[3]: rfu (1 bit) — must be 0 - byte 2
[2:0]: t2mi_stream_id (3 bits) - byte 3: rfu (8 bits) — must be 0
- byte 4-5: payload_len (16 bits, unit = bits)
Fields§
§packet_type: PacketTypeTable 1 packet type.
packet_count: u8Wraps 0xFF→0x00; arbitrary start value.
superframe_idx: u8Super-frame index [0..=15].
t2mi_stream_id: u8T2-MI stream ID [0..=7].
payload_len_bits: u16Payload length in bits (not bytes).
Implementations§
Source§impl Header
impl Header
Sourcepub fn payload_len_bytes(&self) -> usize
pub fn payload_len_bytes(&self) -> usize
Compute payload length in bytes (ceil(bits / 8)).
Sourcepub fn total_bytes(&self) -> usize
pub fn total_bytes(&self) -> usize
Total packet size including header + payload + CRC-32 trailer, in bytes.
= 6 (header) + ceil(payload_len_bits / 8) (payload + padding) + 4 (CRC).
Sourcepub fn raw_payload_bytes(packet: &[u8]) -> Result<&[u8], Error>
pub fn raw_payload_bytes(packet: &[u8]) -> Result<&[u8], Error>
Slice the payload bytes out of a raw T2-MI packet buffer without
requiring the packet_type byte to be a known PacketType.
Reads payload_len_bits from bytes [4..6], computes
ceil(payload_len_bits / 8), and returns
packet[HEADER_LEN..HEADER_LEN + payload_len_bytes].
§Errors
Returns Error::BufferTooShort
if packet.len() < HEADER_LEN.
Returns Error::PayloadLengthMismatch
if the buffer is too short for the declared payload_len_bits.
Sourcepub fn payload_bytes<'a>(&self, packet: &'a [u8]) -> Result<&'a [u8], Error>
pub fn payload_bytes<'a>(&self, packet: &'a [u8]) -> Result<&'a [u8], Error>
Slice the payload bytes out of the full packet buffer this header was
parsed from (the 6 header bytes, then payload_len_bytes() of payload,
then the 4-byte CRC trailer).
Errors with Error::PayloadLengthMismatch when the buffer is too
short for the declared payload_len_bits.
Trait Implementations§
impl Copy for Header
impl Eq for Header
Source§impl Serialize for Header
impl Serialize for Header
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.