mctp_rs/medium/
mod.rs

1use crate::error::MctpPacketResult;
2
3pub mod smbus_espi;
4mod util;
5
6pub trait MctpMedium: Sized {
7    /// the medium specific header and trailer for the packet
8    type Frame: MctpMediumFrame<Self>;
9
10    /// the error type for deserialization of the medium specific header
11    type Error: core::fmt::Debug + Copy + Clone + PartialEq + Eq;
12
13    // the type used for the data needed to send a reply to a request
14    type ReplyContext: core::fmt::Debug + Copy + Clone + PartialEq + Eq;
15
16    /// the maximum transmission unit for the medium
17    fn max_message_body_size(&self) -> usize;
18
19    /// deserialize the packet into the medium specific header and remainder of the packet -
20    /// this includes the mctp transport header, and mctp packet payload
21    fn deserialize<'buf>(
22        &self,
23        packet: &'buf [u8],
24    ) -> MctpPacketResult<(Self::Frame, &'buf [u8]), Self>;
25
26    /// serialize the packet into the medium specific header and the payload
27    fn serialize<'buf, F>(
28        &self,
29        reply_context: Self::ReplyContext,
30        buffer: &'buf mut [u8],
31        message_writer: F,
32    ) -> MctpPacketResult<&'buf [u8], Self>
33    where
34        F: for<'a> FnOnce(&'a mut [u8]) -> MctpPacketResult<usize, Self>;
35}
36
37pub trait MctpMediumFrame<M: MctpMedium>: Clone + Copy {
38    fn packet_size(&self) -> usize;
39    fn reply_context(&self) -> M::ReplyContext;
40}