Skip to main content

Header

Struct Header 

Source
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: PacketType

Table 1 packet type.

§packet_count: u8

Wraps 0xFF→0x00; arbitrary start value.

§superframe_idx: u8

Super-frame index [0..=15].

§t2mi_stream_id: u8

T2-MI stream ID [0..=7].

§payload_len_bits: u16

Payload length in bits (not bytes).

Implementations§

Source§

impl Header

Source

pub fn payload_len_bytes(&self) -> usize

Compute payload length in bytes (ceil(bits / 8)).

Source

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).

Source

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§

Source§

impl Clone for Header

Source§

fn clone(&self) -> Header

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Header

Source§

impl Debug for Header

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Header

Source§

impl<'a> Parse<'a> for Header

Source§

type Error = Error

The error type this implementer returns. Typically the enclosing crate’s Error enum.
Source§

fn parse(bytes: &'a [u8]) -> Result<Self, Error>

Parse bytes as Self. Returns Err(Self::Error) on any protocol violation or buffer underrun.
Source§

impl PartialEq for Header

Source§

fn eq(&self, other: &Header) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Header

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Serialize for Header

Source§

type Error = Error

The error type this implementer returns (usually the same as the corresponding Parse impl, but need not be).
Source§

fn serialized_len(&self) -> usize

Number of bytes serialize_into will write.
Source§

fn serialize_into(&self, buf: &mut [u8]) -> Result<usize, Error>

Write the serialised form into buf. Returns the number of bytes written (always equal to serialized_len()).
Source§

fn to_bytes(&self) -> Vec<u8>
where Self::Error: Debug,

Convenience: allocate a Vec and serialise into it. Panics only if serialize_into misreports serialized_len() — a contract every implementer is responsible for upholding.
Source§

impl StructuralPartialEq for Header

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.