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-15 Section 10.4.4 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-15 puts on the wire is the absolute value rather than a difference — the deltas arrive at draft-18. What is stateful is the omission, and that alone makes removal a re-encode rather than a deletion.
§Why this is not a general encoder
Every Object it writes came off a stream, so the caller holds the Object’s own header with both its resolved values and the flags it arrived under. Those flags are 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
impl FetchObjectWriter
Sourcepub fn new() -> Self
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.
Sourcepub fn header_for(
&self,
original: &FetchObjectHeader,
) -> Result<FetchObjectHeader, CodecError>
pub fn header_for( &self, original: &FetchObjectHeader, ) -> Result<FetchObjectHeader, CodecError>
The header that encodes original’s resolved values 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 flags byte with an unassigned bit.
Sourcepub fn write_object_header(
&mut self,
original: &FetchObjectHeader,
out: &mut impl BufMut,
) -> Result<FetchObjectHeader, CodecError>
pub fn write_object_header( &mut self, original: &FetchObjectHeader, out: &mut impl BufMut, ) -> Result<FetchObjectHeader, CodecError>
Encode original’s resolved values against everything written so far
and advance.
Writes the framing only. The payload is payload_length bytes and is
the caller’s to copy, unchanged.
§Errors
CodecError::InvalidField for a flags byte with an unassigned bit;
the writer is left untouched when this happens.
Sourcepub fn advance(&mut self, written: &FetchObjectHeader)
pub fn advance(&mut self, written: &FetchObjectHeader)
Record what was written as the predecessor of whatever comes next.
Every field draft-15 puts on a fetch object’s wire is the absolute value, so this reads them straight off the header rather than resolving anything.
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
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