pub struct Stream<const N: usize> { /* private fields */ }Expand description
Byte-oriented stream buffer with compile-time buffer size.
Wraps ove_stream_t for passing variable-length byte data between
threads or between ISR and thread contexts. N is the buffer size in bytes.
Implementations§
Source§impl<const N: usize> Stream<N>
impl<const N: usize> Stream<N>
Sourcepub fn new(trigger: usize) -> Result<Self>
pub fn new(trigger: usize) -> Result<Self>
Create a stream via heap allocation (only in heap mode).
Sourcepub fn send(&self, data: &[u8], timeout_ms: u32) -> Result<usize>
pub fn send(&self, data: &[u8], timeout_ms: u32) -> Result<usize>
Send bytes into the stream, blocking up to timeout_ms if the buffer is full.
Returns the number of bytes actually sent, which may be less than data.len()
if the stream fills before the timeout.
§Errors
Returns Error::Timeout if no bytes could be sent within timeout_ms.
Sourcepub fn receive(&self, buf: &mut [u8], timeout_ms: u32) -> Result<usize>
pub fn receive(&self, buf: &mut [u8], timeout_ms: u32) -> Result<usize>
Receive bytes from the stream into buf, blocking up to timeout_ms.
Returns the number of bytes actually received. Blocks until at least the
trigger byte count (set at creation time) is available, or timeout_ms expires.
§Errors
Returns Error::Timeout if no bytes could be received within timeout_ms.
Sourcepub fn send_from_isr(&self, data: &[u8]) -> Result<usize>
pub fn send_from_isr(&self, data: &[u8]) -> Result<usize>
Send bytes from an ISR context (non-blocking, returns immediately).
Returns the number of bytes sent; may be less than data.len() if the buffer fills.
§Errors
Returns an error if the stream is full.
Sourcepub fn receive_from_isr(&self, buf: &mut [u8]) -> Result<usize>
pub fn receive_from_isr(&self, buf: &mut [u8]) -> Result<usize>
Receive bytes from an ISR context (non-blocking, returns immediately).
Returns the number of bytes received; may be zero if no data is available.
§Errors
Returns an error if the stream is empty.
Sourcepub fn reset(&self) -> Result<()>
pub fn reset(&self) -> Result<()>
Reset the stream, discarding all currently buffered data.
§Errors
Returns an error if the underlying RTOS call fails.
Sourcepub fn bytes_available(&self) -> usize
pub fn bytes_available(&self) -> usize
Return the number of bytes currently available for reading.