pub struct OrderedMessageBuffer { /* private fields */ }Expand description
Stores messages and emits them in order.
Only contiguous messages with an index less than or equal to next_index
will be returned - this avoids returning gaps while we wait for the buffer
to fill up with the full sequence.
Implementations§
Source§impl OrderedMessageBuffer
impl OrderedMessageBuffer
pub fn new() -> OrderedMessageBuffer
Sourcepub fn write(
&mut self,
sequence: u64,
data: Vec<u8>,
) -> Result<(), OrderedMessageError>
pub fn write( &mut self, sequence: u64, data: Vec<u8>, ) -> Result<(), OrderedMessageError>
Writes a message to the buffer. messages are sort on insertion, so that later on multiple reads for incomplete sequences don’t result in useless sort work.
Sourcepub fn can_read_until(&self, target: u64) -> bool
pub fn can_read_until(&self, target: u64) -> bool
Checks whether the buffer contains enough contiguous regions to read until the specified target sequence.
Sourcepub fn read(&mut self) -> Option<ReadContiguousData>
pub fn read(&mut self) -> Option<ReadContiguousData>
Returns Option<Vec<u8>> where it’s Some(bytes) if there is gapless
ordered data in the buffer, and None if the buffer is empty or has
gaps in the contained data.
E.g. if the buffer contains messages with indexes 0, 1, 2, and 4, then
a read will return the bytes of messages 0, 1, 2. Subsequent reads will
return None until message 3 comes in, at which point 3, 4, and any
further contiguous messages which have arrived will be returned.