pub struct SubgroupHeader {
pub header_type: u8,
pub track_alias: VarInt,
pub group_id: VarInt,
pub subgroup_id: VarInt,
pub publisher_priority: Option<u8>,
}Fields§
§header_type: u8§track_alias: VarInt§group_id: VarInt§subgroup_id: VarInt§publisher_priority: Option<u8>Implementations§
Source§impl SubgroupHeader
impl SubgroupHeader
pub fn has_extensions(&self) -> bool
Sourcepub fn subgroup_id_from_first_object(&self) -> bool
pub fn subgroup_id_from_first_object(&self) -> bool
Whether SUBGROUP_ID_MODE is 1: the Subgroup ID is the first object’s Object ID and is not transmitted on the wire.
Reads the two bits as the one field Section 10.4.2 defines, rather than
as the single bit 0x02. The single-bit reading answered true for a
Type naming the reserved mode 3, where 0x02 and 0x04 are both set —
so this predicate and Self::has_explicit_subgroup_id answered true
together, for a state one two-bit field cannot be in.
Sourcepub fn has_explicit_subgroup_id(&self) -> bool
pub fn has_explicit_subgroup_id(&self) -> bool
Whether SUBGROUP_ID_MODE is 2: an explicit Subgroup ID field follows the Group ID.
Self::decode refuses the reserved mode before reading any field, so
on a decoded header this agrees with the single-bit 0x04 reading it
replaces. The two differ only on a header built by hand, which is the
only way to hold a reserved-mode Type at all.
pub fn has_end_of_group(&self) -> bool
pub fn has_priority(&self) -> bool
Sourcepub fn encode(&self, buf: &mut impl BufMut)
pub fn encode(&self, buf: &mut impl BufMut)
Serialize the header exactly as its Type byte describes it.
Infallible, and so willing to write a Type draft-16 Section 10.4.2 tells
an endpoint to reject — including a reserved-mode Type this module’s own
Self::decode refuses to read back. Prefer Self::encode_checked,
which refuses those Types instead.
A reserved-mode Type gets no Subgroup ID field, because mode 3 defines
none: the draft says what the other three modes put on the wire and
nothing about this one. Writing the field there was an artifact of
reading 0x04 on its own, and it disagreed with every neighbouring
draft — 15, 17, 18 and 19 all leave it off.
Every field is driven by the Type byte, because that is the only thing
Self::decode and the peer have to go on — the Priority byte
included. Driving that one off publisher_priority being Some
instead desyncs the stream: a Type with DEFAULT_PRIORITY (0x20) set
beside a Some writes a stray byte the reader takes for the first
Object’s Object ID Delta, and a Type with the bit clear beside a None
leaves the reader taking that Delta for the priority. Either way every
later field shifts — which is precisely the disagreement
Self::encode_checked’s doc comment says this pair must not have.
A None under a Type whose bit is clear therefore writes 128 rather
than dropping the byte. Draft-16 Section 11.1.1.1: “A subscription has
Publisher Priorty 128 if this extension is omitted”, so 128 is this
draft’s own name for an unstated priority and not an invented filler.
Drafts 17-21 write the same value in the same place. Use
Self::encode_checked to be told about the disagreement rather than
having it resolved silently.
Sourcepub fn encode_checked(&self, buf: &mut impl BufMut) -> Result<(), CodecError>
pub fn encode_checked(&self, buf: &mut impl BufMut) -> Result<(), CodecError>
Serialize the header, refusing a Type value draft-16 forbids.
Errors with CodecError::InvalidField for exactly the Types Section
10.4.2 lists as invalid — the same set Self::decode refuses — before
any byte is written, so a refused header leaves buf untouched.
The check belongs on this side as well because the two halves would
otherwise disagree about which streams exist: a reserved-mode header
written by Self::encode cannot be read back by Self::decode, and
a codec used to rewrite captured traffic would emit a stream it could not
then parse.
That argument covers the Priority byte too. publisher_priority
disagreeing with the Type byte’s DEFAULT_PRIORITY bit (0x20) is the
same failure one field along: a header that does not mean what it says,
whose bytes the peer reads under framing its writer never asked for.
Self::encode does not desync the stream over it — the byte follows
the Type byte — but resolving the disagreement is not the same as being
told about it, and the caller who set the wrong half is the only one who
can fix it. Same check, same reason, as draft-15 Section 10.4.2’s
encoder.
Sourcepub fn decode(buf: &mut impl Buf) -> Result<Self, CodecError>
pub fn decode(buf: &mut impl Buf) -> Result<Self, CodecError>
Decode a subgroup header, Type field included.
A Type spelled in more than one byte is refused before it is narrowed,
by wide_type_refusal. Every Type draft-16 assigns fits a single
byte, so a wider spelling is either a Type this draft does not have or a
non-minimal spelling of one it does, and both have to be refused rather
than truncated into a Type that happens to be valid.