pub struct Message {
msg_type: MessageType,
msg_length: u8,
msg_payload: Vec<u8>,
}
Expand description
A protocol message. See the module-level documentation for more details.
Fields§
§msg_type: MessageType
The type (action) of the message, which will be encoded in the first two bits of the message.
msg_length: u8
The length of the entire message, which will be encoded in the following 6 bits of the message.
msg_payload: Vec<u8>
The payload of the message, should always be a multiple of 8 bits (1 byte).
Implementations§
source§impl Message
impl Message
sourcepub fn new(
msg_type: MessageType,
msg_length: u8,
msg_payload: Vec<u8>
) -> Message
pub fn new( msg_type: MessageType, msg_length: u8, msg_payload: Vec<u8> ) -> Message
Create a new message.
sourcepub fn new_request(msg_payload: Vec<u8>) -> Message
pub fn new_request(msg_payload: Vec<u8>) -> Message
Create a new message in MessageType::REQUEST
type.
sourcepub fn get_head(&self) -> u8
pub fn get_head(&self) -> u8
Get the first byte of the message,
which is the first two bits for msg_type
and the following six bits for msg_length
.
sourcepub fn get_payload(&self) -> &Vec<u8>
pub fn get_payload(&self) -> &Vec<u8>
Get the payload of the message in Vec<Byte>
.
pub fn get_type(&self) -> &MessageType
Auto Trait Implementations§
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
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