Skip to main content

FileBuilder

Struct FileBuilder 

Source
pub struct FileBuilder { /* private fields */ }
Expand description

Build a complete generation-1 .verit file in memory.

No I/O, deterministic output: the same records added in the same order always produce the same bytes. That makes it the reference writer the golden file corpus and the ports’ conformance suites are checked against (spec §11.5). For incremental, crash-safe mutation of a file on disk, use FileWriter.

Implementations§

Source§

impl FileBuilder

Source

pub fn new() -> FileBuilder

Source

pub fn with_record_checksums(self) -> FileBuilder

Record a CRC-32 per record, setting OPT_RECORD_CRC in the header.

The footer’s CRC proves a commit was not torn; it says nothing about the record bytes. For a file meant to be read years from now, this is the difference between detecting bit rot and trusting it. Costs four bytes per record, and readers without the feature are unaffected.

Must be called before the first record.

Source

pub fn append(&mut self, schema: &Schema, value: &Value) -> Result<u64>

Encode value against schema and append it as the next record, returning its record id. The message is written hash-only — the schema goes to the file’s schema section once, however many records use it.

Source

pub fn append_message(&mut self, schema: &Schema, bytes: &[u8]) -> Result<u64>

Append an already-encoded message together with its writer schema, returning its record id. Accepts hash-only and inline-schema messages alike; the schema id in the message must match schema.

Source

pub fn append_message_with_id( &mut self, schema: &Schema, bytes: &[u8], id: u64, ) -> Result<u64>

Append a record under an explicit id — the compaction path, where ids must be preserved, not reassigned. Ids must be handed over strictly ascending.

Source

pub fn append_self_describing(&mut self, bytes: &[u8]) -> Result<u64>

Append a self-describing (inline-schema) message, lifting its schema out of the message itself. The record is stored verbatim, inline schema and all — use append_message to store it hash-only.

Source

pub fn reserve_next_record_id(&mut self, n: u64) -> &mut Self

Ensure the finished file’s next_record_id is at least n.

Compaction uses this to carry a writer’s id counter across a rewrite: removing the highest-id record must not let that id be handed out again.

Source

pub fn len(&self) -> usize

Number of records added so far.

Source

pub fn is_empty(&self) -> bool

Source

pub fn finish(self) -> Result<Vec<u8>>

Finish the file: append the schema section, the index, and the generation-1 footer, and return the complete image.

Trait Implementations§

Source§

impl Default for FileBuilder

Source§

fn default() -> FileBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.