Skip to main content

Module datagram

Module datagram 

Source
Expand description

HTTP Datagram payload coding (RFC 9297) and QUIC varints (RFC 9000 §16).

An HTTP/3 datagram carried in a QUIC DATAGRAM frame is:

Quarter Stream ID (varint) | Context ID (varint) | payload

The Quarter Stream ID is the request stream’s id divided by four (RFC 9297 §2.1) — not the stream id itself. Getting this wrong is the failure mode that makes every UDP session after the first on a connection misroute, which is exactly the h3-datagram 0.0.2 bug this crate avoids by encoding datagrams here instead. The unit tests below pin the relationship.

For CONNECT-UDP the Context ID is 0, meaning “the payload is a raw UDP datagram” (RFC 9298 §4).

Structs§

Datagram
A decoded HTTP/3 datagram.

Enums§

DecodeError
Why a datagram could not be decoded.

Constants§

CONTEXT_ID_UDP_PAYLOAD
Context ID for an unmodified UDP payload (RFC 9298 §4).
MAX_QUARTER_STREAM_ID
Largest legal Quarter Stream ID (RFC 9297 §2.1).
MAX_UDP_PAYLOAD
Largest UDP payload that can be represented (RFC 9298 §5).
VARINT_MAX
Largest value a QUIC varint can hold (RFC 9000 §16).

Functions§

decode
Decodes an HTTP/3 datagram, sharing the payload buffer rather than copying.
encode
Encodes an HTTP/3 datagram.
encode_udp_payload
Encodes a datagram for quarter_stream_id carrying a raw UDP payload.
encoded_len
The number of bytes encode will produce.
peek_varint
Decodes the varint at the start of buf, returning it and its byte length.
put_varint
Appends value as a QUIC varint.
quarter_stream_id
The Quarter Stream ID identifying the session on stream_id.
take_varint
Reads a QUIC varint from the front of buf, consuming it.
varint_len
Encoded length of value as a QUIC varint.