pub trait FrameEncoder {
    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]Notable traits for &[u8]impl Read for &[u8]impl Write for &mut [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

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

Resets the internal state and prepares it for encoding envelopes.

Adds a self-contained envelope to current frame.

Finalizes a self-contained encoded frame in the buffer.

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.

Checks if current frame contains any envelopes.

Implementors