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>

source

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]>

source

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>

source

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).

Trait Implementations§

source§

impl<T: AsRef<[u8]>> ReaderSegments for NoAllocBufferSegments<T>

source§

fn get_segment(&self, idx: u32) -> Option<&[u8]>

Gets the segment with index idx. Returns None if idx is out of range. Read more
source§

fn len(&self) -> usize

Gets the number of segments.
source§

fn is_empty(&self) -> bool

Auto Trait Implementations§

§

impl<T> Freeze for NoAllocBufferSegments<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for NoAllocBufferSegments<T>
where T: RefUnwindSafe,

§

impl<T> Send for NoAllocBufferSegments<T>
where T: Send,

§

impl<T> Sync for NoAllocBufferSegments<T>
where T: Sync,

§

impl<T> Unpin for NoAllocBufferSegments<T>
where T: Unpin,

§

impl<T> UnwindSafe for NoAllocBufferSegments<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.