pub struct MsgQueue<'a, const LEN: usize> { /* private fields */ }
Expand description
The MsgQueue
queue type using ByteQueue
as the underlying communication mechanism. Read the
crate and module documentation for further information and usage examples.
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 read_or_fail(&mut self) -> Result<&[u8], MqError>
pub fn read_or_fail(&mut self) -> Result<&[u8], MqError>
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 read_blocking(&mut self) -> Result<&[u8], MqError>
pub fn read_blocking(&mut self) -> Result<&[u8], MqError>
Attempts to read a message, blocking until a message is successfully read or an error occurs.
Sourcepub fn write_or_fail(&mut self, msg_data: &[u8]) -> Result<(), MqError>
pub fn write_or_fail(&mut self, msg_data: &[u8]) -> Result<(), MqError>
Attempts to write a message to the queue in non-blocking mode.
Returns an error if the message is too large to fit into the ByteQueue
buffer (MqMsgTooBig
),
or if there is insufficient space in the ByteQueue
(MqFull
).
Otherwise, the message is written successfully.
Sourcepub fn write_blocking(&mut self, msg_data: &[u8]) -> Result<(), MqError>
pub fn write_blocking(&mut self, msg_data: &[u8]) -> Result<(), MqError>
Writes a message to the queue in blocking mode.
Returns an error if the message is too large to fit into the ByteQueue
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.