pub struct SubgroupObjectReader {
extensions_present: bool,
prev_object_id: Option<u64>,
group_id: u64,
group_gap: Option<u64>,
}Expand description
Stateful reader/writer for draft-16 subgroup objects. Mirrors the draft-15 semantics (delta-encoded object IDs and header-typed extension presence).
Fields§
§extensions_present: bool§prev_object_id: Option<u64>§group_id: u64§group_gap: Option<u64>Implementations§
Source§impl SubgroupObjectReader
impl SubgroupObjectReader
pub fn new(header: &SubgroupHeader) -> Self
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 whole, payload included.
Refuses, with CodecError::InvalidField, extension headers on an
object whose status is not Normal: Section 10.2.1.2, “If an endpoint
receives extension headers on Objects with status that is not Normal, it
MUST close the session with a PROTOCOL_VIOLATION.”
Self::read_object_meta frames such an object without judging it.
Refuses, with CodecError::MalformedTrack, the Prior Group ID Gap and
Prior Object ID Gap conditions of Section 11.3 and Section 11.4 this stream
shows: those PriorGaps::from_properties refuses, and “A Group contains
more than one Object with different values for Prior Group ID Gap”. It does
not refuse “An endpoint receives an Object with a Prior Object ID Gap
covering an Object it previously received”: draft-16 Section 2.1 says of an
Object known to exist, “From this state, it can transition to not existing,
but not vice versa”, so whether such a gap makes the Track malformed is
ambiguous. Self::read_object_meta does not read extension headers and
applies none of them.
fn check_stream_gaps(&mut self, gaps: PriorGaps) -> Result<(), CodecError>
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 an object, producing the correct delta encoding.
Errors with CodecError::InvalidField when object.object_id is
not strictly greater than the previously written object’s ID, since
no valid delta exists for that case.
A zero payload_length makes this a status object, and the status
field is then mandatory on the wire: an absent
SubgroupObject::object_status is written as
ObjectStatus::Normal. The code written is always one draft-16
assigns, because the field cannot hold any other, so the bytes this
produces are always bytes SubgroupObjectReader::read_object accepts.
Errors with CodecError::InvalidField when payload_length is not
exactly payload.len(). The declared length is written ahead of the
payload, so a mismatch is a frame Self::read_object cannot parse
and one no caller could fix by appending bytes.