Skip to main content

MapEncodeBuffer

Struct MapEncodeBuffer 

Source
pub struct MapEncodeBuffer {
    pub data: Vec<u8>,
    pub entries: Vec<(i64, usize, usize)>,
}
Available on crate feature cbor only.
Expand description

A collector of CBOR map entries in a single shared buffer, recording (key, start, end) offsets. This avoids per-field allocation: all encoded values are written contiguously into data.

Fields§

§data: Vec<u8>

Encoded values, written back to back.

§entries: Vec<(i64, usize, usize)>

Key and the value’s byte range within data, one per entry.

Implementations§

Source§

impl MapEncodeBuffer

Source

pub fn new(capacity: usize) -> Self

Creates a new buffer pre-sized for the expected number of entries.

Source

pub fn push<T: Encode>(&mut self, key: i64, value: &T) -> Result<(), Error>

Encodes a required field directly into the shared buffer.

Source

pub fn push_optional<T: Encode>( &mut self, key: i64, value: &Option<T>, ) -> Result<(), Error>

Encodes an optional field; omits the entry entirely when None.

Source

pub fn finish_to(self, out: &mut Vec<u8>) -> Result<(), Error>

Assembles the final CBOR map into the provided buffer. Sorts entries by CBOR key order if not already sorted, then verifies no duplicate keys.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V