Skip to main content

ObjectFramer

Struct ObjectFramer 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn feed(&mut self, chunk: &[u8])

Buffer a chunk of stream bytes.

Source

pub fn buffered(&self) -> usize

Bytes buffered but not yet emitted. Non-zero only mid-object.

Source

pub fn is_bypassed(&self) -> bool

true once the framer has stopped parsing this stream and is forwarding bytes uninterpreted.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for ObjectFramer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more