Skip to content

Commit f8a6988

Browse files
committed
feat(mctp-rs): add MctpMessageBuffer::body() + message_type() accessors
Expose the message body slice and message_type byte on MctpMessageBuffer so callers can read raw bytes without going through MctpMessage::parse_as. Use case: a consumer wants to parse a small fixed-layout payload (e.g., 4 little-endian u32 fields for ACPI BST) without defining a full MctpMessageTrait impl just to access self.message_buffer.rest. Pure additive: no public API removed; existing parse_as / can_parse_as paths unchanged.
1 parent b47c07b commit f8a6988

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

mctp-rs/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,22 @@ pub struct MctpMessageBuffer<'buffer> {
211211
rest: &'buffer [u8],
212212
}
213213

214+
impl<'buffer> MctpMessageBuffer<'buffer> {
215+
/// The raw message body bytes (after the message-type byte).
216+
///
217+
/// Use when the caller wants to parse the body without going through
218+
/// `MctpMessage::parse_as` (e.g., when the body is a small fixed-layout
219+
/// payload and a typed `MctpMessageTrait` impl would be overkill).
220+
pub fn body(&self) -> &'buffer [u8] {
221+
self.rest
222+
}
223+
224+
/// The MCTP message-type byte (e.g., `0x7E` for VendorDefinedPci).
225+
pub fn message_type(&self) -> u8 {
226+
self.message_type
227+
}
228+
}
229+
214230
impl<'buffer, M: MctpMedium> MctpMessage<'buffer, M> {
215231
pub fn can_parse_as<P: MctpMessageTrait<'buffer>>(&self) -> bool {
216232
self.message_buffer.message_type == P::MESSAGE_TYPE

0 commit comments

Comments
 (0)