OrderedMessageBuffer

Struct OrderedMessageBuffer 

Source
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

Source

pub fn new() -> OrderedMessageBuffer

Source

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.

Source

pub fn can_read_until(&self, target: u64) -> bool

Checks whether the buffer contains enough contiguous regions to read until the specified target sequence.

Source

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.

Trait Implementations§

Source§

impl Debug for OrderedMessageBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for OrderedMessageBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.