Skip to main content

CodecFileWriter

Struct CodecFileWriter 

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

Streaming writer for a Level-2 TQCV corpus file.

The file is opened with TQCX (tentative) magic and finalized to TQCV once all records have been written and the count is known.

Implementations§

Source§

impl CodecFileWriter

Source

pub fn create( path: &Path, config_hash: &str, dimension: u32, bit_width: u8, residual: bool, metadata: &[u8], ) -> Result<Self, IoError>

Create a new TQCV corpus file at path and write the tentative header.

§Errors

Returns IoError if the file cannot be created, or if any header field value is invalid.

Source

pub fn append(&mut self, cv: &CompressedVector) -> Result<(), IoError>

Append one CompressedVector as a length-prefixed Level-1 record.

§Errors

Returns IoError if the vector cannot be serialized or written.

Source

pub fn finalize(self) -> Result<(), IoError>

Finalize the file: sync body, back-patch vector_count, flip magic to TQCV, sync again.

After calling finalize, the writer is consumed and the file is closed.

§Errors

Returns IoError if any seek, write, or sync operation fails.

Source

pub const fn vector_count(&self) -> u64

Number of vectors written so far.

Source

pub fn config_hash(&self) -> &str

Config hash used when creating the file.

Source

pub const fn dimension(&self) -> u32

Dimension declared in the header.

Source

pub const fn bit_width(&self) -> u8

Bit width declared in the header.

Source

pub const fn residual(&self) -> bool

Whether the file was created with the residual flag set.

Source

pub fn body_offset( config_hash: &str, metadata_len: usize, ) -> Result<usize, IoError>

Compute the byte offset of the first record body in the file.

This mirrors the body_offset formula from [encode_header]: the header is padded to an 8-byte boundary after the variable prefix.

§Errors

Returns IoError::InvalidHeader if the parameters would produce an invalid header (same constraints as [encode_header]).

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V