pub struct ObjectFramer { /* private fields */ }Expand description
Frames a unidirectional MoQT data stream into individually addressable objects while preserving the exact wire bytes.
Feed it the raw bytes of one stream, in order, from the stream’s first
byte. Drain poll after each feed until
it returns FramerOut::NeedMore. The concatenation of every raw
and Passthrough payload it yields equals the concatenation of every
chunk fed to it, unless note_elided has been
called — see Self::poll.
Implementations§
Source§impl ObjectFramer
impl ObjectFramer
Sourcepub fn with_recorder(
stream_type: DataStreamType,
draft: DraftVersion,
config: FramerConfig,
counters: Arc<Recorder>,
) -> Self
pub fn with_recorder( stream_type: DataStreamType, draft: DraftVersion, config: FramerConfig, counters: Arc<Recorder>, ) -> Self
A framer whose slow-path counters go to counters.
The only constructor session.rs may use. The counters are
session-scoped, and a framer that cannot reach its session’s
Recorder would leave framers_created, framer_header_polls,
framer_object_polls, objects_not_addressable and
object_ids_rewritten at zero for every real session — which is a
passing Interest::NONE proof obtained by measuring nothing.
Self::new is kept, unchanged, for tests and downstream callers
that construct a framer to parse bytes rather than to forward them;
it is equivalent to passing a fresh Recorder whose counts nobody
reads. That is why this is an addition and not a signature
change.
Sourcepub fn with_fetch_group_orders(self, orders: Arc<FetchGroupOrders>) -> Self
pub fn with_fetch_group_orders(self, orders: Arc<FetchGroupOrders>) -> Self
Read this stream’s fetch Objects against the order its FETCH asked for.
Only drafts 18 and 19 need it — see FetchGroupOrders — and only a
fetch stream consults it; a subgroup framer given one ignores it. A
framer built without it on a draft that needs one reports
BypassReason::FetchGroupOrderUnknown and forwards the stream
uninterpreted, which is what every caller outside a session gets and
what the session itself gets for a stream naming a request it never
saw asked for.
Sourcepub fn new(
stream_type: DataStreamType,
draft: DraftVersion,
config: FramerConfig,
) -> Self
pub fn new( stream_type: DataStreamType, draft: DraftVersion, config: FramerConfig, ) -> Self
Create a framer for a stream of the given kind on the given draft, discarding its counters.
Increments go to a private Recorder nothing can read, so a
caller that wants a session’s counters to move must use
Self::with_recorder. Retained for callers that parse bytes
rather than forward them, where the counts are not the point.
Sourcepub fn elide_cursor(&self) -> ElideCursor
pub fn elide_cursor(&self) -> ElideCursor
The state an elide has left behind on this stream.
Read-only, and read-anytime: the framer applies the fix-up itself, so nothing outside has to act on this.
Sourcepub fn note_elided(&mut self, meta: &ObjectMeta)
pub fn note_elided(&mut self, meta: &ObjectMeta)
Record that the object the framer emitted most recently was not forwarded.
Call exactly once, immediately after deciding to drop an object,
and before the next Self::poll. meta must be the meta the
framer handed out for that object; it is debug_asserted against
the framer’s own record, because calling this out of order is the
one way to corrupt a stream silently.
On drafts 07-13 subgroup streams and on drafts 07-14 fetch streams this only suppresses the cursor advance — those Object IDs are absolute, so the bytes of every later object already say the truth. Elsewhere it also arms a fix-up: the leading Object ID varint on a drafts 14-19 subgroup stream, and the whole framing of the next frame on a drafts 15-19 fetch stream, where it additionally puts the fetch writer back to where the last forwarded frame left it.
Sourcepub fn is_bypassed(&self) -> bool
pub fn is_bypassed(&self) -> bool
true once the framer has stopped parsing this stream and is
forwarding bytes uninterpreted.
Sourcepub fn finish(&mut self) -> Option<Bytes>
pub fn finish(&mut self) -> Option<Bytes>
Flush any buffered bytes at end of stream.
Called when the source signals FIN. Returns whatever the framer still holds — a truncated final object, or bytes buffered behind an incomplete framing — so the caller can forward them before finishing the destination stream. Forgetting this call turns a clean FIN into silent truncation.
Sourcepub fn poll(&mut self) -> FramerOut
pub fn poll(&mut self) -> FramerOut
Produce the next item, or FramerOut::NeedMore.
§Invariant
Concatenating the raw field of every Header
and Object and the payload of every
Passthrough, in the order produced,
reproduces the fed bytes exactly — on every draft, including
streams that fall back to bypass — unless
Self::note_elided has been called, which deliberately removes
an object’s bytes and may rewrite one leading varint.
That exception is the only one, and it is opt-in per stream: a
framer used as a pure observer never calls note_elided, so its
output stays byte-identical to its input. When note_elided has
been called on a drafts 14-19 subgroup stream, the next object the
framer emits has its leading Object ID varint re-encoded against
the last object actually forwarded — one field, in one object, and
every byte after it copied verbatim. Everything else, on every
other stream, still concatenates back to the source exactly.
FramerOut::Bypassed and FramerOut::NeedMore carry no bytes
and so contribute nothing to the reconstruction either way.