Skip to main content

Datagram

Enum Datagram 

Source
pub enum Datagram {
    Payload(DatagramHeader),
    Status(DatagramStatusHeader),
}
Expand description

One datagram, of whichever shape its type field names.

A MoQT datagram opens with a variable-length integer naming its type, and that integer is what says which of the layouts above follows it. Neither DatagramHeader nor DatagramStatusHeader reads or writes it, so neither can be handed the first byte of a datagram a peer sent, and neither produces bytes a peer can read. This is the entry point that does both.

The payload of a payload-bearing datagram runs to the end of the QUIC datagram, so it is not part of this value: Self::decode stops at the end of the header and leaves the payload in the buffer, and a caller appends the payload after Self::encode.

Variants§

§

Payload(DatagramHeader)

An object carrying a payload.

§

Status(DatagramStatusHeader)

An object stating a status, with no payload.

Implementations§

Source§

impl Datagram

Source

pub fn is_status(&self) -> bool

Whether this datagram states an Object Status instead of carrying a payload.

Draft-08 can say it two ways: on the dedicated status message, and on the payload message with a declared payload length of zero, which draft-09 removed.

Source

pub fn datagram_type(&self) -> StreamType

The type field this value writes.

Source

pub fn decode(buf: &mut impl Buf) -> Result<Self, CodecError>

Decode a datagram from its first byte, type field included.

Errors with CodecError::UnknownDatagramType when the leading type is one the datagram table does not assign, which this draft answers with a close, and with CodecError::InvalidField for the stream types, which it does assign but not to a datagram. datagram_type_error draws that line.

Source

pub fn encode(&self, buf: &mut impl BufMut)

Encode the datagram, type field included.

Source

pub fn encode_checked(&self, buf: &mut impl BufMut) -> Result<(), CodecError>

Encode the datagram, refusing a header the framing it names cannot carry.

The body is built before anything reaches buf, so a refused datagram leaves buf untouched rather than a type field with no body under it.

Trait Implementations§

Source§

impl Clone for Datagram

Source§

fn clone(&self) -> Datagram

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 Datagram

Source§

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

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

impl Eq for Datagram

Source§

impl PartialEq for Datagram

Source§

fn eq(&self, other: &Datagram) -> 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 Datagram

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.