Trait cassandra_protocol::frame::frame_encoder::FrameEncoder
source · 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:
- Have multiple self-contained envelopes added.
- 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§
sourcefn can_fit(&self, len: usize) -> bool
fn can_fit(&self, len: usize) -> bool
Determines if payload of given size can fit in current frame buffer.
sourcefn add_envelope(&mut self, envelope: Vec<u8>)
fn add_envelope(&mut self, envelope: Vec<u8>)
Adds a self-contained envelope to current frame.
sourcefn finalize_self_contained(&mut self) -> &[u8] ⓘ
fn finalize_self_contained(&mut self) -> &[u8] ⓘ
Finalizes a self-contained encoded frame in the buffer.
sourcefn finalize_non_self_contained(&mut self, envelope: &[u8]) -> (usize, &[u8])
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.
sourcefn has_envelopes(&self) -> bool
fn has_envelopes(&self) -> bool
Checks if current frame contains any envelopes.