Struct capnp::serialize::SegmentLengthsBuilder
source · pub struct SegmentLengthsBuilder { /* private fields */ }
Expand description
Helper object for constructing an OwnedSegments
or a SliceSegments
.
Implementations§
source§impl SegmentLengthsBuilder
impl SegmentLengthsBuilder
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new SegmentsLengthsBuilder
, initializing the segment_indices vector with
Vec::with_capacitiy(capacity)
. capacity
should equal the number of times that push_segment()
is expected to be called.
sourcepub fn try_push_segment(&mut self, length_in_words: usize) -> Result<()>
pub fn try_push_segment(&mut self, length_in_words: usize) -> Result<()>
Pushes a new segment length. The n
th time (starting at 0) this is called specifies the length of
the segment with ID n
. If the segment overflows the total word count, then this returns
a MessageSizeOverflow error.
sourcepub fn into_owned_segments(self) -> OwnedSegments
pub fn into_owned_segments(self) -> OwnedSegments
Constructs an OwnedSegments
, allocating a single buffer of 8-byte aligned memory to hold
all segments.
sourcepub fn into_slice_segments(
self,
slice: &[u8],
segment_table_bytes_len: usize
) -> BufferSegments<&'_ [u8]>
pub fn into_slice_segments( self, slice: &[u8], segment_table_bytes_len: usize ) -> BufferSegments<&'_ [u8]>
Constructs a SliceSegments
.
slice
contains the full message (including the segment header).
sourcepub fn total_words(&self) -> usize
pub fn total_words(&self) -> usize
Returns the sum of the lengths of the segments pushed so far.
sourcepub fn to_segment_indices(self) -> Vec<(usize, usize)>
pub fn to_segment_indices(self) -> Vec<(usize, usize)>
Returns the vector of segment indices. Each entry is a pair (start_word_index, end_word_index). This method primarily exists to enable testing.