Skip to main content

Encoder

Struct Encoder 

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

Encoder that serializes Values into Crous binary format.

§Example

use crous_core::{Encoder, Value};

let mut enc = Encoder::new();
enc.encode_value(&Value::UInt(42)).unwrap();
let bytes = enc.finish().unwrap();
assert!(bytes.len() > 8); // header + block

Implementations§

Source§

impl Encoder

Source

pub fn new() -> Self

Create a new encoder with default settings.

Source

pub fn with_limits(limits: Limits) -> Self

Create an encoder with custom limits.

Source

pub fn enable_dedup(&mut self)

Enable string deduplication. Repeated strings within a block will be encoded as Reference wire types pointing to the dictionary.

Source

pub fn set_compression(&mut self, comp: CompressionType)

Set the compression type for subsequent blocks.

Source

pub fn set_flags(&mut self, flags: u8)

Set the file header flags.

Source

pub fn encode_value(&mut self, value: &Value) -> Result<()>

Encode a single Value into the current block buffer.

This is the main entry point for encoding. Values are accumulated in the block buffer; call finish() to flush and produce the final bytes.

Source

pub fn flush_block(&mut self) -> Result<usize>

Flush the current block buffer into a framed block and append to output. Returns the number of bytes in the flushed block.

When dedup_strings is enabled and the per-block string dictionary is non-empty, a StringDict block is emitted before the data block. The dictionary entries are sorted and stored using prefix-delta compression for compactness.

When compression is set to something other than None, the block payload is compressed before framing. The checksum is always computed on the uncompressed payload so the decoder can verify integrity after decompression. The block_len field reflects the compressed size written to the wire.

Source

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

Finish encoding: flush remaining data and return the complete binary output.

The output includes: file header + data blocks + file trailer checksum.

Source

pub fn current_size(&self) -> usize

Get the current size of the output buffer (including unflushed block data).

Source

pub fn block_buffer(&self) -> &[u8]

Get access to the raw block buffer (for testing/inspection).

Trait Implementations§

Source§

impl Default for Encoder

Source§

fn default() -> Self

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.