pub enum ChannelBuffer {
Lossy(RingBuffer),
Reliable(Queue),
}Expand description
A channel buffer that is either lossy (RingBuffer) or reliable
(Queue).
The push method returns Ok(usize) — the number of
older frames evicted (always 0 for reliable channels). Use
push_checked for a richer PushOutcome.
Variants§
Lossy(RingBuffer)
Lossy mode: oldest frames are silently dropped when the byte budget is exceeded.
Reliable(Queue)
Reliable mode: pushes are rejected with
Error::ChannelFull when the byte budget
is exceeded.
Implementations§
Source§impl ChannelBuffer
impl ChannelBuffer
Sourcepub fn push(&self, frame: &[u8]) -> Result<usize, Error>
pub fn push(&self, frame: &[u8]) -> Result<usize, Error>
Push a frame into the channel.
For lossy channels, returns Ok(usize) — the number of older frames
evicted to make room (or 0 if the frame was too large and silently
discarded). For reliable channels, returns Ok(0) on success or
Err(Error::ChannelFull) if the byte
budget would be exceeded.
Sourcepub fn push_checked(&self, frame: &[u8]) -> Result<PushOutcome, Error>
pub fn push_checked(&self, frame: &[u8]) -> Result<PushOutcome, Error>
Push a frame with a richer outcome report.
Like push, but returns PushOutcome for lossy
channels, distinguishing between accepted frames and frames that were
too large to ever fit.
Sourcepub fn drain_all(&self) -> Vec<u8> ⓘ
pub fn drain_all(&self) -> Vec<u8> ⓘ
Drain all buffered frames into a single binary blob and clear the buffer.
The wire format is identical for both variants — see
RingBuffer::drain_all for details.
Sourcepub fn try_pop(&self) -> Option<Vec<u8>>
pub fn try_pop(&self) -> Option<Vec<u8>>
Read one frame from the front of the buffer (FIFO).
Returns None if the buffer is empty.
Sourcepub fn frame_count(&self) -> usize
pub fn frame_count(&self) -> usize
Number of frames currently buffered.
Sourcepub fn bytes_used(&self) -> usize
pub fn bytes_used(&self) -> usize
Number of bytes currently used (including per-frame length prefixes).
Sourcepub fn is_ordered(&self) -> bool
pub fn is_ordered(&self) -> bool
Returns true if this channel uses reliable (guaranteed-delivery)
buffering.