Skip to main content

Frame

Struct Frame 

Source
pub struct Frame {
    pub session_id: u32,
    pub channel_id: u16,
    pub seq: u8,
    pub frame_type: FrameType,
    pub payload: Vec<u8>,
}
Expand description

Wire representation of a parsed UART protocol frame emitted by crate::FrameParser.

While Frame represents an in-memory parsed frame, encode_frame is the primary zero-allocation serializer for transmitting byte slices over the wire.

Fields§

§session_id: u32

32-bit session identifier negotiated during handshake.

§channel_id: u16

Logical channel identifier (Channel 0 is reserved for control).

§seq: u8

8-bit Go-Back-N sequence number.

§frame_type: FrameType

Protocol frame type indicator.

§payload: Vec<u8>

Raw un-encoded payload bytes.

Implementations§

Source§

impl Frame

Source

pub fn new( session_id: u32, channel_id: u16, seq: u8, frame_type: FrameType, payload: Vec<u8>, ) -> Result<Self, FrameError>

Creates a new validated protocol frame.

§Errors

Returns FrameError::PayloadTooLarge if payload.len() > MAX_PAYLOAD_SIZE.

Source

pub fn encode(&self) -> Result<Vec<u8>, FrameError>

Serializes and encodes this frame with header, header checksum, and trailing CRC-32.

§Errors

Returns FrameError::PayloadTooLarge if self.payload.len() > MAX_PAYLOAD_SIZE.

Source

pub fn wire_len(&self) -> usize

Returns the total wire length of this frame in bytes when encoded.

Trait Implementations§

Source§

impl Clone for Frame

Source§

fn clone(&self) -> Self

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 Debug for Frame

Source§

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

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

impl Eq for Frame

Source§

impl PartialEq for Frame

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Frame

Auto Trait Implementations§

§

impl Freeze for Frame

§

impl RefUnwindSafe for Frame

§

impl Send for Frame

§

impl Sync for Frame

§

impl Unpin for Frame

§

impl UnsafeUnpin for Frame

§

impl UnwindSafe for Frame

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.