Skip to main content

MctpMedium

Trait MctpMedium 

Source
pub trait MctpMedium: Sized {
    type Frame: MctpMediumFrame<Self>;
    type Error: Debug + Copy + Clone + PartialEq + Eq;
    type ReplyContext: Debug + Copy + Clone + PartialEq + Eq;
    type Encoding: BufferEncoding;

    // Required methods
    fn max_message_body_size(&self) -> usize;
    fn deserialize<'buf>(
        &self,
        packet: &'buf [u8],
    ) -> MctpPacketResult<(Self::Frame, EncodingDecoder<'buf, Self::Encoding>), Self>;
    fn serialize<'buf, F>(
        &self,
        reply_context: Self::ReplyContext,
        buffer: &'buf mut [u8],
        message_writer: F,
    ) -> MctpPacketResult<&'buf [u8], Self>
       where F: for<'a> FnOnce(&mut EncodingEncoder<'a, Self::Encoding>) -> MctpPacketResult<(), Self>;
}

Required Associated Types§

Source

type Frame: MctpMediumFrame<Self>

the medium specific header and trailer for the packet

Source

type Error: Debug + Copy + Clone + PartialEq + Eq

the error type for deserialization of the medium specific header

Source

type ReplyContext: Debug + Copy + Clone + PartialEq + Eq

Source

type Encoding: BufferEncoding

the byte-stuffing transform used by this medium when (de)serializing wire bytes. Stateless — see [crate::buffer_encoding]. Most media use PassthroughEncoding (no transform); media that need byte-stuffing (e.g., DSP0253 serial) supply their own impl.

Required Methods§

Source

fn max_message_body_size(&self) -> usize

the maximum transmission unit for the medium

Source

fn deserialize<'buf>( &self, packet: &'buf [u8], ) -> MctpPacketResult<(Self::Frame, EncodingDecoder<'buf, Self::Encoding>), Self>

Deserialize a packet into the medium-specific header (frame) and an EncodingDecoder that wraps the inner stuffed-region bytes. Higher layers (e.g., parse_transport_header, the payload copy loop in MctpPacketContext) read decoded bytes through the returned decoder and physically cannot bypass the medium’s encoding by slicing the underlying buffer directly.

Source

fn serialize<'buf, F>( &self, reply_context: Self::ReplyContext, buffer: &'buf mut [u8], message_writer: F, ) -> MctpPacketResult<&'buf [u8], Self>
where F: for<'a> FnOnce(&mut EncodingEncoder<'a, Self::Encoding>) -> MctpPacketResult<(), Self>,

Serialize a packet by allowing the caller’s message_writer closure to write decoded bytes into the medium’s stuffed region through an EncodingEncoder. The medium owns its outer framing (e.g., SMBus header + PEC, DSP0253 start/end flags + FCS) and inspects the encoder’s wire_position after the closure returns to size headers/trailers and compute checksums.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§