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, and whether an extension block sits inside 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
impl Datagram
Sourcepub fn is_status(&self) -> bool
pub fn is_status(&self) -> bool
Whether this datagram states an Object Status instead of carrying a payload.
Sourcepub fn datagram_type(&self) -> DatagramType
pub fn datagram_type(&self) -> DatagramType
The type field this value writes.
The extensions bit is taken from the extension bytes themselves rather than from the declared length beside them, which is what keeps the type and the body from contradicting each other: a datagram whose type announces extensions and then declares a length of 0 closes the session on receipt, and one that announces none has nowhere to put them. The end of group bit has no home in the body at all, so it comes from the header flag and goes nowhere else.
Sourcepub fn decode(buf: &mut impl Buf) -> Result<Self, CodecError>
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 datagram table
does not assign the leading type, which this draft answers with a close.
datagram_type_error settles it against that table alone — 0x05 is
assigned in both tables here and means different things in each.
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, 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.