pub trait Segments {
// Required methods
fn next(&mut self) -> Result<usize>;
fn data_stream(&self) -> &[u8] ⓘ;
fn control_stream(&self) -> &[u8] ⓘ;
}
Expand description
Provides facility for reading segments
Each segment contains elements (integers) in encoded format. Each Segments::next
method call
moves this objects to the next segment.
Motivation
This trait exists to abstract DecodeCursor
from logic of reading segments. If all the segments are
in memory the most efficient way of decoding is decoding [u8]
slices in memory. This maximize the
decoding speed because no memory copy is needed. In case segments data are on the file system,
some logic for reading next segment in a memory buffer is required. In this case it’s more
appropriate to read segments one by one in a memory buffer of a predefined size. Segments
trait
and its 2 base implementations: MemorySegments
and BufReadSegments
are providing those facilities.
Required Methods§
sourcefn next(&mut self) -> Result<usize>
fn next(&mut self) -> Result<usize>
Moves to the next segment and return number of the elements encoded in the segment
sourcefn data_stream(&self) -> &[u8] ⓘ
fn data_stream(&self) -> &[u8] ⓘ
Returns the current segment’s data stream
sourcefn control_stream(&self) -> &[u8] ⓘ
fn control_stream(&self) -> &[u8] ⓘ
Returns the current segment’s control stream