Skip to main content

AnySubgroupObjectWriter

Struct AnySubgroupObjectWriter 

Source
pub struct AnySubgroupObjectWriter { /* private fields */ }
Expand description

Serializer for the objects on a subgroup data stream, for any enabled draft.

Mirrors AnySubgroupObjectReader. On drafts 14-19 it tracks the previous Object ID so successive writes produce correct deltas; on drafts 07-13 object IDs are absolute and the same state only enforces that they increase.

§Eliding objects

To remove an object from a stream, read it and then simply do not write it. The writer’s delta state advances only when write_object succeeds, so the next object written re-derives its delta against the last retained object automatically. See Self::write_object for the exact invariant.

Implementations§

Source§

impl AnySubgroupObjectWriter

Source

pub fn new(header: &AnySubgroupHeader) -> Result<Self, CodecError>

Create a writer for a stream with the given header.

The header fixes the extension-presence and (on drafts 11-13) stream type used for every object written, exactly as it does for AnySubgroupObjectReader::new.

Source

pub fn draft(&self) -> DraftVersion

The draft this writer encodes.

Source

pub fn write_object( &mut self, object: &AnySubgroupObject, buf: &mut impl BufMut, ) -> Result<(), CodecError>

Encode one object, advancing the delta state.

§Invariant

Let a stream’s objects decode to absolute IDs a_0, a_1, .., a_n. Feeding any strictly-increasing subsequence of those objects through one writer, in order, produces a byte stream that decodes back to exactly that subsequence of absolute IDs, on every draft 07-19.

Concretely: dropping a_2 from 0,1,2,3,4 yields a stream decoding to 0,1,3,4 — not 0,1,2,3.

§Errors

CodecError::InvalidField when object.object_id is not strictly greater than the previously written object’s ID (two objects on a subgroup stream can never share an ID, so no valid delta exists), when a computed delta or length exceeds the varint range, when the object carries extension bytes that a stream without an extension block cannot represent, or when a non-empty payload is paired with a status.

Also CodecError::InvalidField when object.status holds a code the draft being written does not assign. AnySubgroupObject::status is a raw wire code because it crosses drafts, and the assigned set moves between them, so a status read off one draft’s stream is not necessarily writable onto another’s: forwarding a draft-15 Object Does Not Exist (0x1) onto a draft-16 or later stream is refused here rather than emitted as a byte the peer must close the session over.

Trait Implementations§

Source§

impl Clone for AnySubgroupObjectWriter

Source§

fn clone(&self) -> AnySubgroupObjectWriter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AnySubgroupObjectWriter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, <T as TryFrom<U>>::Error>

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.