moq_net/model/datagram.rs
1//! A datagram is a single unreliable payload delivered on a track, parallel to groups.
2//!
3//! Unlike a group (an ordered stream of frames over a QUIC stream), a datagram is one self-contained
4//! payload carried in a single QUIC datagram: best-effort, unordered, and never retransmitted. It
5//! shares the track's monotonic sequence-number namespace with groups but is otherwise independent,
6//! produced via [`super::track::Producer::append_datagram`] / [`super::track::Producer::write_datagram`]
7//! and consumed via [`super::track::Subscriber::recv_datagram`].
8//!
9//! Delivery is best-effort per hop: a session drops (with a debug log) any datagram whose encoded
10//! body exceeds the transport's datagram size, and sessions that can't carry datagrams at all
11//! (IETF moq-transport, moq-lite before 05, or stream-only transports like WebSocket) never
12//! deliver them.
13//!
14//! Wire counterpart: [`crate::lite::Datagram`].
15
16use bytes::Bytes;
17
18use crate::Timestamp;
19
20/// Hard ceiling on a datagram payload, matching the QUIC DATAGRAM frame limit.
21///
22/// This only bounds buffering; the real limit is per hop. Each session drops a datagram whose
23/// encoded body exceeds the transport's current datagram size (roughly the path MTU minus QUIC
24/// and MoQ header overhead), so callers should keep payloads well below the minimum path MTU
25/// of 1200 bytes (e.g. a single audio frame).
26pub(crate) const MAX_DATAGRAM_PAYLOAD: usize = u16::MAX as usize;
27
28/// A single unreliable payload on a track: a sequence number, a presentation timestamp, and the bytes.
29///
30/// The sequence number is drawn from the same namespace as the track's groups, so a relay can forward
31/// a datagram while preserving the origin's numbering (see [`super::track::Producer::write_datagram`]).
32#[derive(Clone, Debug, PartialEq, Eq)]
33pub struct Datagram {
34 /// Per-track sequence number, shared with the group namespace.
35 pub sequence: u64,
36 /// Presentation timestamp in the track's timescale.
37 pub timestamp: Timestamp,
38 /// The datagram payload.
39 pub payload: Bytes,
40}