pub struct IltpCodec { /* private fields */ }Expand description
Encodes accepted output batches and decodes peer bytes for one connected carrier. Prefaces pass raw; the two prefaces of each logical session select and install both directions’ 065 stream encodings.
Output is one accepted batch at a time, produced progressively into chunks
of at most the codec’s chunk size: the writer takes
output_bytes, reports what it wrote with
advance_output, and asks again until the batch is
complete. Each batch’s bytes end with the encoding’s flush.
Implementations§
Source§impl IltpCodec
impl IltpCodec
Sourcepub fn new(chunk_bytes: usize) -> Self
pub fn new(chunk_bytes: usize) -> Self
A codec whose output chunks and retained decoded input are at most
chunk_bytes.
§Panics
If chunk_bytes is below MIN_CHUNK_BYTES.
Sourcepub fn accept_output(&mut self, items: Vec<IltpItem>) -> Result<(), IltpError>
pub fn accept_output(&mut self, items: Vec<IltpItem>) -> Result<(), IltpError>
Accept one machine output batch, validated completely before any of its bytes are produced. A preface first ends the previous logical session’s encoded stream with its end mark.
Sourcepub fn accept_end(&mut self) -> Result<(), IltpError>
pub fn accept_end(&mut self) -> Result<(), IltpError>
Accept the end of the outgoing encoded stream: a compressed encoding’s end mark. Only a fresh preface may be accepted afterwards.
Sourcepub fn output_pending(&self) -> bool
pub fn output_pending(&self) -> bool
Whether accepted output has bytes the writer has not taken.
Sourcepub fn output_bytes(&mut self) -> Result<OutputBytes<'_>, IltpError>
pub fn output_bytes(&mut self) -> Result<OutputBytes<'_>, IltpError>
The next bytes of the accepted output, produced when the previous ones are taken, or the record read their production needs.
Sourcepub fn complete_read(&mut self, read: RecordRead) -> Result<(), IltpError>
pub fn complete_read(&mut self, read: RecordRead) -> Result<(), IltpError>
Return a RecordRead that output_bytes
handed out, after running it.
Sourcepub fn advance_output(&mut self, written: usize)
pub fn advance_output(&mut self, written: usize)
Accept written bytes of the current output_bytes.
Sourcepub fn discard_output(&mut self)
pub fn discard_output(&mut self)
Drop accepted output the peer can no longer receive. The outgoing encoding is unusable afterwards; only terminal retirement follows.
Sourcepub fn drain_output(&mut self, out: &mut Vec<u8>) -> Result<(), IltpError>
pub fn drain_output(&mut self, out: &mut Vec<u8>) -> Result<(), IltpError>
Append every remaining byte of the accepted output to out,
performing record reads on the calling thread.
Sourcepub fn decode<'a>(
&'a mut self,
input: &'a [u8],
) -> Result<(usize, Option<Decoded<'a>>), IltpError>
pub fn decode<'a>( &'a mut self, input: &'a [u8], ) -> Result<(usize, Option<Decoded<'a>>), IltpError>
Decode a prefix of input through at most one Decoded event and
return the consumed length. Raw input after the event stays with the
caller; decoded bytes after it stay in the codec, so call again, with
empty input if none remains, until no event is returned.
A record item is not retained: its owner writes the prefix of
Decoded::RecordStart and every Decoded::RecordData to its
record sink before decoding continues, and only
Decoded::RecordEnd proves the bytes valid.
Sourcepub fn awaits_local_preface(&self) -> bool
pub fn awaits_local_preface(&self) -> bool
Whether decoding waits for the local preface: the peer preface is decoded and the session’s encodings install once the local one is written.