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
impl AnySubgroupObjectWriter
Sourcepub fn new(header: &AnySubgroupHeader) -> Result<Self, CodecError>
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.
Sourcepub fn draft(&self) -> DraftVersion
pub fn draft(&self) -> DraftVersion
The draft this writer encodes.
Sourcepub fn write_object(
&mut self,
object: &AnySubgroupObject,
buf: &mut impl BufMut,
) -> Result<(), CodecError>
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
impl Clone for AnySubgroupObjectWriter
Source§fn clone(&self) -> AnySubgroupObjectWriter
fn clone(&self) -> AnySubgroupObjectWriter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more