pub struct MsgQueue<'a, const LEN: usize> { /* private fields */ }
Expand description
An abstraction for interpreting messages based on a specific format, using ByteQueue
as the underlying communication mechanism.
Implementations§
source§impl<'a, const LEN: usize> MsgQueue<'a, LEN>
impl<'a, const LEN: usize> MsgQueue<'a, LEN>
sourcepub fn new(byte_queue: ByteQueue, prefix: &'a [u8], rx_buf: [u8; LEN]) -> Self
pub fn new(byte_queue: ByteQueue, prefix: &'a [u8], rx_buf: [u8; LEN]) -> Self
Initializes a message queue for interpreting messages with the specified prefix, using the
provided rx_buf
as storage for incoming messages. The size of rx_buf
determines how
many messages can be stored before they need to be consumed or read.
sourcepub fn nb_read_msg(&mut self) -> Result<&[u8], MsgQueueError>
pub fn nb_read_msg(&mut self) -> Result<&[u8], MsgQueueError>
Attempts to read a message from the queue in non-blocking mode.
Returns a slice of the message data or an error if no complete message is available.
sourcepub fn blocking_read_msg(&mut self) -> Result<&[u8], MsgQueueError>
pub fn blocking_read_msg(&mut self) -> Result<&[u8], MsgQueueError>
Attempts to read a message, blocking until a message is successfully read or an error occurs.
sourcepub fn nb_write_msg(&mut self, msg_data: &[u8]) -> Result<(), MsgQueueError>
pub fn nb_write_msg(&mut self, msg_data: &[u8]) -> Result<(), MsgQueueError>
Attempts to write a message to the queue in non-blocking mode.
Returns an error if the message is too large to fit in the receive buffer (MqMsgTooBig
),
or if there is insufficient space in the ByteQueue
(MqFull
).
Otherwise, the message is written successfully.
sourcepub fn blocking_write_msg(
&mut self,
msg_data: &[u8],
) -> Result<(), MsgQueueError>
pub fn blocking_write_msg( &mut self, msg_data: &[u8], ) -> Result<(), MsgQueueError>
Attempts to write a message to the queue in blocking mode.
Returns an error if the message is too large to fit into the receive buffer (MqMsgTooBig
).
If there is insufficient space in the ByteQueue
, this function will block until space becomes
available.
Once space is available, the message is written successfully.