pub struct DatagramHeader {
pub datagram_type: u8,
pub track_alias: VarInt,
pub group_id: VarInt,
pub object_id: VarInt,
pub publisher_priority: Option<u8>,
pub extension_headers: Vec<u8>,
pub object_status: Option<ObjectStatus>,
}Fields§
§datagram_type: u8§track_alias: VarInt§group_id: VarInt§object_id: VarInt§publisher_priority: Option<u8>Publisher priority — None when the DEFAULT_PRIORITY flag is set and
the priority is inherited from the subscription’s control message.
extension_headers: Vec<u8>Opaque extension-headers blob (only when flag 0x01 is set).
object_status: Option<ObjectStatus>Object status (only when the 0x20 status flag is set).
The wire field is a varint and can carry any value up to 2^62-1;
draft-16 Section 10.2.1.1 assigns three of them and says a peer SHOULD
treat the rest as a protocol error. This field is typed to the assigned
set, so it cannot hold 0x1, 0x2 or anything from 0x5 up —
Self::encode therefore needs no check and cannot emit a datagram
that Self::decode would reject.
None while the status flag is set encodes as
ObjectStatus::Normal: once the flag is set the field is present on
the wire, so there is nothing for None to mean but the default.
Implementations§
Source§impl DatagramHeader
impl DatagramHeader
pub fn has_extensions(&self) -> bool
pub fn is_end_of_group(&self) -> bool
pub fn has_object_id(&self) -> bool
Sourcepub fn has_default_priority(&self) -> bool
pub fn has_default_priority(&self) -> bool
When set, publisher_priority is omitted on the wire and inherited from the subscription / control-message context.
pub fn is_status(&self) -> bool
Sourcepub fn extensions_permitted(&self) -> bool
pub fn extensions_permitted(&self) -> bool
Whether this datagram’s status is allowed to carry the extension headers it has.
The same rule the subgroup form obeys — draft-16 Section 10.3.1 builds
the datagram’s Extensions field out of the structure Section 10.2.1.2
defines, and that section is where the rule sits. See
SubgroupObject::extensions_permitted for why Self::decode
reports this instead of refusing it.
The block is on the wire only when the type byte sets the EXTENSIONS bit, so contents held here with the bit clear are not written and do not count against the rule.
Sourcepub fn encode_checked(&self, buf: &mut impl BufMut) -> Result<(), CodecError>
pub fn encode_checked(&self, buf: &mut impl BufMut) -> Result<(), CodecError>
Encode the datagram header, refusing a status the framing cannot carry.
A datagram states a status only when its type byte sets the STATUS bit
(0x20). With the bit clear there is no status field on the wire, so an
object_status of anything but ObjectStatus::Normal has nowhere to
go: Self::encode drops it, and the datagram parses back as an
ordinary payload object. An End of Group marker written that way does
not arrive late or malformed — it does not arrive at all, and the
receiver sees a normal object in its place.
Draft-16 Section 10.3.1 puts the framing side plainly — “The STATUS bit (0x20) indicates whether the datagram contains an Object Status or Object Payload” — and Section 10.2.1.1 the conformance side: “Any object with a status code other than zero MUST have an empty payload.” Between them there is no datagram that carries a non-zero status and a payload, so the pair being refused here is not one this encoder merely declines to spell.
ObjectStatus::Normal with the bit clear is not that case and is
accepted. It is the status the encoding elides for every datagram that
carries a payload, so stating it asks for exactly the bytes leaving it
out asks for, and nothing is lost.
Errors with CodecError::InvalidField on the lossy combination,
before any byte is written, so a refused header leaves buf untouched.
Three further refusals, each of them a datagram this codec would otherwise emit and then decline to read back:
- A Type value Section 10.3.1 lists as invalid. See
validate_datagram_type. - An EXTENSIONS bit set over an empty extension block. Section 10.3.1:
“If an endpoint receives a datagram with the EXTENSIONS bit set and an
Extension Headers Length of 0, it MUST close the session with a
PROTOCOL_VIOLATION.”
Self::encodewrites the length prefix from the block’s own length, so it spells exactly the datagram the peer must close the session over. This is a datagram rule only: on a subgroup stream the same section says “Objects with no extensions set Extension Headers Length to 0”, because the Type byte is fixed for the whole stream and an Object with no extensions has no other way to say so. - Extensions on an Object whose status is not Normal (Section 10.2.1.2).
Sourcepub fn encode(&self, buf: &mut impl BufMut)
pub fn encode(&self, buf: &mut impl BufMut)
Encode the datagram header to buf.
When the type byte sets the status flag the status field is written
unconditionally, defaulting to ObjectStatus::Normal. Omitting it
would truncate the datagram: Self::decode reads a status whenever
the flag is set, and answers CodecError::UnexpectedEnd when the
bytes stop first.
The type byte is taken as the authority on framing, which is what makes
this infallible — and what makes it lossy when the struct disagrees with
itself. An object_status set while the type byte leaves the STATUS bit
clear is discarded here without a word. Prefer Self::encode_checked,
which refuses that combination instead of resolving it.
Sourcepub fn decode(buf: &mut impl Buf) -> Result<Self, CodecError>
pub fn decode(buf: &mut impl Buf) -> Result<Self, CodecError>
Decode a datagram header, Type field included.
A Type spelled in more than one byte is refused first, for the reason
given on SubgroupHeader::decode.
Trait Implementations§
Source§impl Clone for DatagramHeader
impl Clone for DatagramHeader
Source§fn clone(&self) -> DatagramHeader
fn clone(&self) -> DatagramHeader
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more