pub async fn read_to_cap<R: RecvStream>(
recv: &mut R,
cap: usize,
) -> Result<Bytes>Expand description
Read an entire stream into [Bytes], capping the total at cap bytes.
Uses [RecvStream::read_chunk] (a defaulted trait method): quinn and iroh
override it to return Bytes referencing the QUIC receive buffer, so a
control message that arrives as a single chunk (the common case) is
returned fully zero-copy — no allocation, no copy. The UDS impl inherits
the trait’s one-copy default (local socket, fine). Multi-chunk frames pay at
most one concatenation. Errors out if the peer sends more than cap bytes
before FIN (RecvStream::read_all is unbounded — a hostile peer could
exhaust memory with it).
This is the control plane (MAX_FRAME_BYTES = 4 MiB). Bulk/tensor
payloads ride the streaming plane, where moq-net already yields Bytes.