pub struct Assembler { /* private fields */ }Expand description
A buffer (re)assembler.
Currently, up to a hardcoded limit of 4 or 32 holes can be tracked in the buffer.
Implementations§
Source§impl Assembler
impl Assembler
pub fn clear(&mut self)
Sourcepub fn peek_front(&self) -> usize
pub fn peek_front(&self) -> usize
Return length of the front contiguous range without removing it from the assembler
Sourcepub fn add(
&mut self,
offset: usize,
size: usize,
) -> Result<(), TooManyHolesError>
pub fn add( &mut self, offset: usize, size: usize, ) -> Result<(), TooManyHolesError>
Add a new contiguous range to the assembler,
or return Err(TooManyHolesError) if too many discontinuities are already recorded.
Sourcepub fn remove_front(&mut self) -> usize
pub fn remove_front(&mut self) -> usize
Remove a contiguous range from the front of the assembler. If no such range, return 0.
Sourcepub fn add_then_remove_front(
&mut self,
offset: usize,
size: usize,
) -> Result<usize, TooManyHolesError>
pub fn add_then_remove_front( &mut self, offset: usize, size: usize, ) -> Result<usize, TooManyHolesError>
Add a segment, then remove_front.
This is equivalent to calling add then remove_front individually,
except it’s guaranteed to not fail when offset = 0.
This is required for TCP: we must never drop the next expected segment, or
the protocol might get stuck.
Sourcepub fn iter_data(&self) -> impl Iterator<Item = (usize, usize)> + '_
pub fn iter_data(&self) -> impl Iterator<Item = (usize, usize)> + '_
Iterate over all of the contiguous data ranges.
Returns (offset, size) tuples for each contiguous data range, where
offset is relative to the start of the assembler.
Data Hole Data |— 100 —|— 200 —|— 100 —|
Would return the ranges: (0, 100), (300, 400)