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 [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
SingleSegment
Fields
segment: &'b [u8]
MultipleSegments
Fields
message: &'b [u8]
Implementations
sourceimpl<'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).
Trait Implementations
sourceimpl<'b> ReaderSegments for NoAllocSliceSegments<'b>
impl<'b> ReaderSegments for NoAllocSliceSegments<'b>
Auto Trait Implementations
impl<'b> RefUnwindSafe for NoAllocSliceSegments<'b>
impl<'b> Send for NoAllocSliceSegments<'b>
impl<'b> Sync for NoAllocSliceSegments<'b>
impl<'b> Unpin for NoAllocSliceSegments<'b>
impl<'b> UnwindSafe for NoAllocSliceSegments<'b>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more