Skip to main content

Encoder

Struct Encoder 

Source
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>

Source

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.

Source

pub fn sink_mut(&mut self) -> &mut W

Mutable access to the underlying writer (e.g. for fsync).

Source

pub fn entry_index(&self) -> usize

Number of entries written so far in this segment.

Source

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.

Source

pub fn size(&self) -> usize

Total entry bytes written so far (the segment header is not counted), for deciding when to roll over to a new segment.

Auto Trait Implementations§

§

impl<E, W> Freeze for Encoder<E, W>
where W: Freeze,

§

impl<E, W> RefUnwindSafe for Encoder<E, W>

§

impl<E, W> Send for Encoder<E, W>
where W: Send, E: Send,

§

impl<E, W> Sync for Encoder<E, W>
where W: Sync, E: Sync,

§

impl<E, W> Unpin for Encoder<E, W>
where W: Unpin, E: Unpin,

§

impl<E, W> UnsafeUnpin for Encoder<E, W>
where W: UnsafeUnpin,

§

impl<E, W> UnwindSafe for Encoder<E, W>
where W: UnwindSafe, E: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.