Skip to main content

IltpCodec

Struct IltpCodec 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn output_pending(&self) -> bool

Whether accepted output has bytes the writer has not taken.

Source

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.

Source

pub fn complete_read(&mut self, read: RecordRead) -> Result<(), IltpError>

Return a RecordRead that output_bytes handed out, after running it.

Source

pub fn advance_output(&mut self, written: usize)

Accept written bytes of the current output_bytes.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn finish(&mut self) -> Result<(), IltpError>

Finalize decoding at EOF: boundary EOF needs an item boundary and the direction’s encoding at its end. Every event must have been decoded.

Trait Implementations§

Source§

impl Debug for IltpCodec

Source§

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

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

impl Default for IltpCodec

Source§

fn default() -> Self

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.