#[repr(C)]pub struct MessageHeader {
pub length: u32,
pub msg_type: u16,
pub version: u8,
pub flags: u8,
}Expand description
Zero-copy message header for length-prefixed protocols
Fields§
§length: u32Total message length including header
msg_type: u16Message type identifier
version: u8Protocol version
flags: u8Flags/reserved
Implementations§
Source§impl MessageHeader
impl MessageHeader
Sourcepub const fn new(length: u32, msg_type: u16, version: u8, flags: u8) -> Self
pub const fn new(length: u32, msg_type: u16, version: u8, flags: u8) -> Self
Create a new message header
Sourcepub const fn payload_length(&self) -> u32
pub const fn payload_length(&self) -> u32
Get the payload length (total length minus header size)
Sourcepub const fn has_valid_length(&self) -> bool
pub const fn has_valid_length(&self) -> bool
Check if the header has valid length
Sourcepub const fn is_message_type(&self, msg_type: u16) -> bool
pub const fn is_message_type(&self, msg_type: u16) -> bool
Check if this is a specific message type
Source§impl MessageHeader
impl MessageHeader
Sourcepub fn from_bytes(bytes: &[u8]) -> Option<&Self>
pub fn from_bytes(bytes: &[u8]) -> Option<&Self>
Create from bytes
Trait Implementations§
Source§impl Clone for MessageHeader
impl Clone for MessageHeader
Source§fn clone(&self) -> MessageHeader
fn clone(&self) -> MessageHeader
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MessageHeader
impl Debug for MessageHeader
impl Copy for MessageHeader
impl Pod for MessageHeader
Auto Trait Implementations§
impl Freeze for MessageHeader
impl RefUnwindSafe for MessageHeader
impl Send for MessageHeader
impl Sync for MessageHeader
impl Unpin for MessageHeader
impl UnwindSafe for MessageHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
If this function returns true, then it must be valid to reinterpret
bits
as &Self.