pub struct Encoder<E, W> { /* private fields */ }Expand description
Streaming encoder for one segment: writes the header on construction, then appends entries, carrying the cross-entry state (timestamp base, UUID dictionary) that delta- and dictionary-encoding need.
Implementations§
Source§impl<E: Op, W: Write> Encoder<E, W>
impl<E: Op, W: Write> Encoder<E, W>
Sourcepub fn new(sink: W, magic: &[u8], server_mode: bool) -> Result<Self, CodecError>
pub fn new(sink: W, magic: &[u8], server_mode: bool) -> Result<Self, CodecError>
Create a new encoder.
magic is the segment’s leading identity bytes — it is not defined
by this library. Each application must supply its own stable, app-unique
value (the same bytes its decoder expects) so that one app’s segments are
never mistaken for another’s when they share a sync location. Use a
distinct value per app, and prefer same-length magics across apps so one
cannot be a prefix of another.
Sourcepub fn entry_index(&self) -> usize
pub fn entry_index(&self) -> usize
Number of entries written so far in this segment.
Sourcepub fn encode_entry(
&mut self,
op: &E,
timestamp: Timestamp,
server_user_id: Option<Uuid>,
) -> Result<usize, CodecError>
pub fn encode_entry( &mut self, op: &E, timestamp: Timestamp, server_user_id: Option<Uuid>, ) -> Result<usize, CodecError>
Encode one log entry. Takes parts by ref/value rather than a full
LogEntry<E> so callers iterating &[E] can avoid cloning each op
just to satisfy a &LogEntry<E> argument.
The UUID dictionary and last timestamp are persistent, cross-entry state; they are committed only once the entry’s bytes are written. A failure partway through leaves the encoder exactly as it was, so a partly-built entry can never leave behind a UUID definition (or an advanced clock) that the flushed bytes don’t account for.