pub struct Encoder<T> { /* private fields */ }Expand description
Encodes JSON records into frame payloads, sharing one DEFLATE window across the log.
The track-free core of Producer. Unlike
snapshot::Encoder there are no group boundaries to report: a log is
an unbroken sequence of self-contained records, so every payload is simply the next frame.
The window spans everything encoded so far, so payloads must reach the wire in order and be
decoded in the same order. If the caller does roll a group, call reset so the
next record starts a cold window that the new group’s decoder can follow.
Implementations§
Source§impl<T> Encoder<T>
impl<T> Encoder<T>
Sourcepub fn new(config: ProducerConfig) -> Self
pub fn new(config: ProducerConfig) -> Self
Create an encoder with a cold window.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Start a cold DEFLATE window, for a caller that has just rolled a group.
This is also how a caller clears an Error::Desync: roll a new group so the consumer starts
its own cold window, then reset.
Source§impl<T: Serialize> Encoder<T>
impl<T: Serialize> Encoder<T>
Sourcepub fn encode(&mut self, value: &T) -> Result<Pending<'_, T>>
pub fn encode(&mut self, value: &T) -> Result<Pending<'_, T>>
Encode one record into the next frame payload.
The record comes back as a Pending the caller writes and then
commits. Errors with Error::Desync if a previous compressed record
was left uncommitted, since every frame after it would be undecodable.