Skip to main content

DatagramHeader

Struct DatagramHeader 

Source
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

Source

pub fn has_extensions(&self) -> bool

Source

pub fn is_end_of_group(&self) -> bool

Source

pub fn has_object_id(&self) -> bool

Source

pub fn has_default_priority(&self) -> bool

When set, publisher_priority is omitted on the wire and inherited from the subscription / control-message context.

Source

pub fn is_status(&self) -> bool

Source

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.

Source

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::encode writes 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).
Source

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.

Source

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

Source§

fn clone(&self) -> DatagramHeader

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DatagramHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for DatagramHeader

Source§

impl PartialEq for DatagramHeader

Source§

fn eq(&self, other: &DatagramHeader) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DatagramHeader

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.