Enum capnp::serialize::NoAllocSliceSegments
source · pub enum NoAllocSliceSegments<'b> {
SingleSegment {
segment: &'b [u8],
},
MultipleSegments {
message: &'b [u8],
},
}
Expand description
Segments read from a buffer, useful for when you have the message in a buffer and don’t want the
extra copy of read_message
.
NoAllocSliceSegments
is similar to crate::serialize::SliceSegments
but optimized for
low memory embedded environment. It does not do heap allocations and consumes only one fat
pointer worth of memory.
Performance considerations
Due to lack of heap allocations, NoAllocSliceSegments
does not cache segments offset and
length and has to parse message header every time NoAllocSliceSegments::get_segment
is called.
The parsing has O(N) complexity where N is total number of segments in the message.
NoAllocSliceSegments
has optimization for single segment messages: if message has only one
segment, it will be parsed only once during creation and no parsing will be required on get_segment
calls
Variants§
Implementations§
source§impl<'b> NoAllocSliceSegments<'b>
impl<'b> NoAllocSliceSegments<'b>
sourcepub fn try_new(slice: &mut &'b [u8], options: ReaderOptions) -> Result<Self>
pub fn try_new(slice: &mut &'b [u8], options: ReaderOptions) -> Result<Self>
Reads a serialized message (including a segment table) from a buffer and takes ownership, without copying.
The slice is allowed to extend beyond the end of the message. On success, updates slice
to point
to the remaining bytes beyond the end of the message.
ALIGNMENT: If the “unaligned” feature is enabled, then there are no alignment requirements on buffer
.
Otherwise, buffer
must be 8-byte aligned (attempts to read the message will trigger errors).