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

source

pub fn new( msg_type: MessageType, msg_length: u8, msg_payload: Vec<u8> ) -> Message

Create a new message.

source

pub fn new_request(msg_payload: Vec<u8>) -> Message

Create a new message in MessageType::REQUEST type.

source

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.

source

pub fn get_payload(&self) -> &Vec<u8>

Get the payload of the message in Vec<Byte>.

source

pub fn get_type(&self) -> &MessageType

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V