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 + blockImplementations§
Source§impl Encoder
impl Encoder
Sourcepub fn with_limits(limits: Limits) -> Self
pub fn with_limits(limits: Limits) -> Self
Create an encoder with custom limits.
Sourcepub fn enable_dedup(&mut self)
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.
Sourcepub fn set_compression(&mut self, comp: CompressionType)
pub fn set_compression(&mut self, comp: CompressionType)
Set the compression type for subsequent blocks.
Sourcepub fn encode_value(&mut self, value: &Value) -> Result<()>
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.
Sourcepub fn flush_block(&mut self) -> Result<usize>
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.
Sourcepub fn finish(self) -> Result<Vec<u8>>
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.
Sourcepub fn current_size(&self) -> usize
pub fn current_size(&self) -> usize
Get the current size of the output buffer (including unflushed block data).
Sourcepub fn block_buffer(&self) -> &[u8] ⓘ
pub fn block_buffer(&self) -> &[u8] ⓘ
Get access to the raw block buffer (for testing/inspection).