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-18 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.
§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.
Implementations§
Source§impl FetchObjectWriter
impl FetchObjectWriter
Sourcepub fn new(group_order: GroupOrder) -> Self
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.
Sourcepub fn header_for(
&self,
frame: &FetchObject,
) -> Result<FetchObjectHeader, CodecError>
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.
§Errors
CodecError::InvalidField for a frame that cannot be encoded against
the current predecessor; see the type’s own documentation for the list.
Sourcepub fn write_object_header(
&mut self,
frame: &FetchObject,
out: &mut impl BufMut,
) -> Result<FetchObjectHeader, CodecError>
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.
§Errors
CodecError::InvalidField for a frame with no encoding against the
current predecessor. The writer is left untouched when this happens.
Sourcepub fn advance(&mut self, frame: &FetchObject)
pub fn advance(&mut self, frame: &FetchObject)
Record frame as the predecessor of whatever is written next.
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.
Trait Implementations§
Source§impl Clone for FetchObjectWriter
impl Clone for FetchObjectWriter
Source§fn clone(&self) -> FetchObjectWriter
fn clone(&self) -> FetchObjectWriter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more