pub struct SubgroupObjectReader { /* private fields */ }Expand description
Stateful reader for the object fields on a subgroup stream.
Object IDs on a subgroup stream are delta-encoded against the
previous Object ID, and whether extension headers are present is
fixed by the enclosing SubgroupHeader’s stream type. This reader
carries that context across successive read_object calls.
Implementations§
Source§impl SubgroupObjectReader
impl SubgroupObjectReader
Sourcepub fn new(header: &SubgroupHeader) -> Self
pub fn new(header: &SubgroupHeader) -> Self
Create a reader from a parsed subgroup header.
Sourcepub fn read_object(
&mut self,
buf: &mut impl Buf,
) -> Result<SubgroupObject, CodecError>
pub fn read_object( &mut self, buf: &mut impl Buf, ) -> Result<SubgroupObject, CodecError>
Decode the next object from buf. Caller is responsible for
ensuring the buffer contains a complete object (draft-14 objects
are length-delimited by the payload-length field, so the buffer
boundary is known once the header portion has been consumed).
Sourcepub fn read_object_meta(
&mut self,
buf: &mut impl Buf,
) -> Result<SubgroupObjectMeta, CodecError>
pub fn read_object_meta( &mut self, buf: &mut impl Buf, ) -> Result<SubgroupObjectMeta, CodecError>
Decode the next object’s framing without copying its payload.
Consumes exactly the bytes Self::read_object consumes and leaves
the same delta state behind, so the two are interchangeable on a
given stream.
Sourcepub fn write_object(
&mut self,
object: &SubgroupObject,
buf: &mut impl BufMut,
) -> Result<(), CodecError>
pub fn write_object( &mut self, object: &SubgroupObject, buf: &mut impl BufMut, ) -> Result<(), CodecError>
Serialize a subgroup object using the reader’s delta state. Intended
for senders that want to build a stream incrementally — tracks
prev_object_id so successive calls produce correct deltas.
Returns an error if object.object_id <= prev_object_id, which
would produce an invalid delta.
It also refuses the three shapes the stream cannot carry, rather than writing whichever half fits and dropping the rest:
- A non-empty payload beside a status other than Normal. Section 10.2.1.1: “Any object with a status code other than zero MUST have an empty payload.” A truncated payload is worse than a refusal — the receiver has no way to tell that anything was there.
- Extension headers on an object whose stream type says the subgroup has none. The type byte is fixed for the whole stream by the header, so this object cannot opt in, and its extensions would simply vanish.
- Extension headers on an Object Does Not Exist status, per Section 10.2.1.2.
Normal beside a non-empty payload is not one of those and is written as an ordinary payload-bearing object: it is the status such an object already has, so naming it asks for the bytes leaving it out asks for. Normal beside an empty payload keeps the explicit status form, which is the only way to send a zero-length object at all.
Trait Implementations§
Source§impl Clone for SubgroupObjectReader
impl Clone for SubgroupObjectReader
Source§fn clone(&self) -> SubgroupObjectReader
fn clone(&self) -> SubgroupObjectReader
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more