pub struct QueueStreamed<T: StructSerde>(/* private fields */);Expand description
Queue types for inter-task communication.
Type-safe wrapper around Queue that (de)serializes T instead of
requiring callers to shuffle raw byte slices themselves.
T must implement BytesHasLen + Serialize + Deserialize
(bundled together as StructSerde) - or, with the serde feature
enabled, whatever osal-rs-serde’s derive macros provide instead.
§Examples
use osal_rs::os::*;
#[derive(Clone)]
struct Reading(u32);
impl BytesHasLen for Reading {
fn len(&self) -> usize { core::mem::size_of::<u32>() }
}
impl Serialize for Reading {
fn to_bytes(&self) -> &[u8] {
unsafe {
core::slice::from_raw_parts(&self.0 as *const u32 as *const u8, core::mem::size_of::<u32>())
}
}
}
impl Deserialize for Reading {
fn from_bytes(bytes: &[u8]) -> osal_rs::utils::Result<Self> {
let mut buf = [0u8; 4];
buf.copy_from_slice(&bytes[..4]);
Ok(Reading(u32::from_le_bytes(buf)))
}
}
let queue = QueueStreamed::<Reading>::new(4, 4).unwrap();
queue.post(&Reading(42), 100).unwrap();
let mut out = Reading(0);
queue.fetch(&mut out, 100).unwrap();
assert_eq!(out.0, 42);Implementations§
Source§impl<T> QueueStreamed<T>where
T: StructSerde,
impl<T> QueueStreamed<T>where
T: StructSerde,
Sourcepub fn new(size: UBaseType, message_size: UBaseType) -> Result<Self>
pub fn new(size: UBaseType, message_size: UBaseType) -> Result<Self>
Creates a streamed queue holding up to size messages of
message_size bytes each - same capacity semantics as
Queue::new, just typed as T instead of raw bytes.
See the type-level example for a complete, testable usage.
Methods from Deref<Target = QueueHandle>§
Trait Implementations§
Source§impl<T> Debug for QueueStreamed<T>where
T: StructSerde,
impl<T> Debug for QueueStreamed<T>where
T: StructSerde,
Source§impl<T> Deref for QueueStreamed<T>where
T: StructSerde,
impl<T> Deref for QueueStreamed<T>where
T: StructSerde,
Source§impl<T> Display for QueueStreamed<T>where
T: StructSerde,
impl<T> Display for QueueStreamed<T>where
T: StructSerde,
Source§impl<T> QueueStreamed<T> for QueueStreamed<T>where
T: StructSerde,
Available on crate feature serde only.
impl<T> QueueStreamed<T> for QueueStreamed<T>where
T: StructSerde,
serde only.Source§fn fetch(&self, buffer: &mut T, time: TickType) -> Result<()>
fn fetch(&self, buffer: &mut T, time: TickType) -> Result<()>
Blocks like Queue::fetch, deserializing the received bytes into
buffer via osal-rs-serde.
Source§fn fetch_from_isr(&self, buffer: &mut T) -> Result<()>
fn fetch_from_isr(&self, buffer: &mut T) -> Result<()>
ISR-safe variant of QueueStreamedFn::fetch; see Queue::fetch_from_isr.
Source§fn post(&self, item: &T, time: TickType) -> Result<()>
fn post(&self, item: &T, time: TickType) -> Result<()>
Blocks like Queue::post, serializing item via osal-rs-serde first.
Source§fn post_from_isr(&self, item: &T) -> Result<()>
fn post_from_isr(&self, item: &T) -> Result<()>
ISR-safe variant of QueueStreamedFn::post; see Queue::post_from_isr.
Source§fn delete(&mut self)
fn delete(&mut self)
Destroys the underlying queue; see Queue::delete.