Struct capnp::serialize::NoAllocBufferSegments
source · pub struct NoAllocBufferSegments<T> { /* private fields */ }
Expand description
NoAllocBufferSegments
is similar to crate::serialize::BufferSegments
but optimized for
low memory embedded environment. It does not do heap allocations.
§Performance considerations
Due to lack of heap allocations, NoAllocBufferSegments
does not cache segments offset and
length and has to parse message header every time NoAllocBufferSegments::get_segment
is called.
The parsing has O(N) complexity where N is total number of segments in the message.
NoAllocBufferSegments
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
Implementations§
source§impl<T> NoAllocBufferSegments<T>
impl<T> NoAllocBufferSegments<T>
sourcepub fn from_segment_table_info(buffer: T, info: NoAllocSegmentTableInfo) -> Self
pub fn from_segment_table_info(buffer: T, info: NoAllocSegmentTableInfo) -> Self
Constructs a NoAllocBufferSegments from a buffer and a NoAllocSegmentTableInfo
.
This method is used internally by NoAllocBufferSegments::from_slice()
and NoAllocBufferSegments::from_buffer()
. It has been made public to allow for
situations where the segment table is read by nonstandard means.
source§impl<'b> NoAllocBufferSegments<&'b [u8]>
impl<'b> NoAllocBufferSegments<&'b [u8]>
sourcepub fn from_slice(slice: &mut &'b [u8], options: ReaderOptions) -> Result<Self>
pub fn from_slice(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 buffer 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 slice
.
Otherwise, slice
must be 8-byte aligned (attempts to read the message will trigger errors).
source§impl<T: AsRef<[u8]>> NoAllocBufferSegments<T>
impl<T: AsRef<[u8]>> NoAllocBufferSegments<T>
sourcepub fn from_buffer(buffer: T, options: ReaderOptions) -> Result<Self>
pub fn from_buffer(buffer: T, options: ReaderOptions) -> Result<Self>
Reads a serialized message (including a segment table) from a buffer and takes ownership, without copying. The buffer is allowed to extend 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).