Skip to main content

FetchObjectWriter

Struct FetchObjectWriter 

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

Re-encodes resolved fetch frames 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 frames. Removing a frame changes what the frames after it are encoded against, and draft-19 Section 11.4.4.1 defines nearly every field against “the prior Object”, so the survivor that follows a removed run cannot keep its original bytes. What has to change is not one field: an Object that carried no Group ID Delta because it shared its predecessor’s group needs one once that predecessor is gone, so a field appears and a flag bit with it.

§Why this is not a general encoder

Every frame it writes came off a stream, so the caller already holds the frame’s own FetchObjectHeader alongside the resolved values. That header is used as the preference: wherever the original shape still encodes the same meaning against the new predecessor, it is kept, so a stream with nothing removed from it is reproduced byte for byte. Only where the original shape would now decode to something else is a different one chosen. An encoder built from the resolved values alone could not do that — it would have to invent a canonical form and would rewrite every frame on a stream that needed no rewriting at all.

§What it refuses

CodecError::InvalidField where no encoding exists rather than picking one: a Group ID that moves against the FETCH’s Group Order, an Object ID that does not advance, an Object with neither a Subgroup ID nor the Datagram bit, and the arithmetic overflows. Each of these is a frame this writer was handed that no draft-19 stream could carry, and inventing a value for it would put a different Object on the wire than the one it was given.

Implementations§

Source§

impl FetchObjectWriter

Source

pub fn new(group_order: GroupOrder) -> Self

A writer for a stream whose Groups are being written in group_order.

The order has to match the one the FETCH was opened with, for the same reason FetchObjectReader::new takes it: it decides whether a Group ID Delta adds or subtracts, and it is not on the data stream.

Source

pub fn header_for( &self, frame: &FetchObject, ) -> Result<FetchObjectHeader, CodecError>

The header that encodes frame against everything written so far.

Does not advance the writer — Self::write_object_header is the call that does both. Separated so that a caller can measure the bytes a re-encode would take before committing to it.

§Errors

CodecError::InvalidField for a frame that cannot be encoded against the current predecessor; see the type’s own documentation for the list.

Source

pub fn write_object_header( &mut self, frame: &FetchObject, out: &mut impl BufMut, ) -> Result<FetchObjectHeader, CodecError>

Encode frame against everything written so far and advance.

Writes the header only. The payload is frame.header.payload_length bytes and is the caller’s to copy, unchanged — nothing about it depends on what preceded the Object.

§Errors

CodecError::InvalidField for a frame with no encoding against the current predecessor. The writer is left untouched when this happens, so a caller that gives up on one frame and carries on with the next is writing against the same predecessor it thought it was.

Source

pub fn advance(&mut self, frame: &FetchObject)

Record frame as the predecessor of whatever is written next.

Split from the write so that a caller re-emitting bytes it already holds can advance without producing a header twice — which is what happens whenever the framing a frame arrived in still encodes the same meaning against the frame before it, and is why this is public.

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

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, <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.