Skip to main content

FetchObjectWriter

Struct FetchObjectWriter 

Source
pub struct FetchObjectWriter { /* private fields */ }
Expand description

Re-encodes resolved fetch Objects onto one FETCH stream.

The exact inverse of FetchObjectReader, and it exists for one caller: something that has read a stream and is writing a different stream from the same Objects. Draft-16 Section 10.4.4.1 lets an Object leave out its Group ID, Object ID, Subgroup ID and Priority and take the prior Object’s, so removing an Object changes what the Objects after it are read against: a field the survivor left off has to appear, and a flag bit with it.

Every field draft-16 puts on the wire here is the absolute value rather than a difference — the deltas arrive at draft-18. What is stateful is the omission, and that is enough to make removal a re-encode.

§Why this is not a general encoder

Every Object it writes came off a stream, so the caller holds the Object’s own FetchObjectHeader beside its resolved FetchObjectLocation. The header is used as the preference: wherever the original shape still says the same thing against the new predecessor it is kept, so a stream with nothing removed is reproduced byte for byte.

Implementations§

Source§

impl FetchObjectWriter

Source

pub fn new() -> Self

A writer positioned before the first Object of a fetch stream, with no prior Object for anything to be written against.

Source

pub fn header_for( &self, original: &FetchObjectHeader, location: &FetchObjectLocation, ) -> Result<FetchObjectHeader, CodecError>

The header that encodes location against everything written so far, starting from the shape original arrived in.

Does not advance the writer — Self::write_object_header is the call that does both.

§Errors

CodecError::InvalidField for an Object with neither a Subgroup ID nor the Datagram bit, and where a value does not fit a variable-length integer.

Source

pub fn write_object_header( &mut self, original: &FetchObjectHeader, location: &FetchObjectLocation, out: &mut impl BufMut, ) -> Result<FetchObjectHeader, CodecError>

Encode location against everything written so far and advance.

Writes the header only. The payload is original.payload_length bytes and is the caller’s to copy, unchanged.

§Errors

CodecError::InvalidField for an Object with no encoding; the writer is left untouched when this happens.

Source

pub fn advance( &mut self, written: &FetchObjectHeader, location: &FetchObjectLocation, )

Record what was written as the predecessor of whatever comes next.

Mirrors FetchObjectReader::resolve exactly, including the two places draft-16 differs from the drafts after it: a Datagram-forwarded Object clears the running Subgroup ID rather than leaving it standing, and an Object that states no Priority leaves the running one alone.

Public because a re-emitting caller has a second way of putting a frame on the wire: when the framing it arrived in still encodes the same meaning against the frame before it, its own bytes are forwarded untouched — no header is produced and nothing is copied. The writer still has to move, or the frame after it is encoded against a predecessor one frame stale. written is then the Object’s own header, which is what was put on the wire.

Trait Implementations§

Source§

impl Clone for FetchObjectWriter

Source§

fn clone(&self) -> FetchObjectWriter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FetchObjectWriter

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for FetchObjectWriter

Source§

fn default() -> FetchObjectWriter

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, !>

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.