pub trait FrameEncoder {
    // Required methods
    fn can_fit(&self, len: usize) -> bool;
    fn reset(&mut self);
    fn add_envelope(&mut self, envelope: Vec<u8>);
    fn finalize_self_contained(&mut self) -> &[u8] ;
    fn finalize_non_self_contained(&mut self, envelope: &[u8]) -> (usize, &[u8]);
    fn has_envelopes(&self) -> bool;
}
Expand description

An encoder for frames. Since protocol v5, frames became “envelopes” and a frame now can contain multiple complete envelopes (self-contained frame) or a part of one bigger envelope.

Encoders are stateful and can either:

  1. Have multiple self-contained envelopes added.
  2. Have a single non self-contained envelope added.

In either case, the encoder is assumed to have the buffer ready to accept envelopes before adding the first one or after calling [reset_buffer]. At some point, the frame can become finalized (which is the only possible case when adding a non self-contained envelope) and the returned buffer is assumed to be immutable and ready to be sent.

Required Methods§

source

fn can_fit(&self, len: usize) -> bool

Determines if payload of given size can fit in current frame buffer.

source

fn reset(&mut self)

Resets the internal state and prepares it for encoding envelopes.

source

fn add_envelope(&mut self, envelope: Vec<u8>)

Adds a self-contained envelope to current frame.

source

fn finalize_self_contained(&mut self) -> &[u8]

Finalizes a self-contained encoded frame in the buffer.

source

fn finalize_non_self_contained(&mut self, envelope: &[u8]) -> (usize, &[u8])

Appends a large envelope and finalizes non self-contained encoded frame in the buffer. Copies as much envelope data as possible and returns new envelope buffer start.

source

fn has_envelopes(&self) -> bool

Checks if current frame contains any envelopes.

Implementors§