pub struct Encoder<'a, C: ColumnCursor>where
C::Item: 'a,{
pub len: usize,
pub state: C::State<'a>,
pub writer: SlabWriter<'a, C::Item>,
/* private fields */
}Expand description
A streaming encoder that accumulates values and writes them into a compressed slab.
Encoder<C> buffers incoming values in its EncoderState and periodically flushes
encoded runs to an internal SlabWriter. Use it when you need to build a buffer
incrementally rather than encoding all values at once with ColumnCursor::encode.
§Example
use hexane::{Encoder, StrCursor};
let mut buf = vec![];
let mut encoder: Encoder<'_, StrCursor> = Encoder::default();
for word in ["dog", "book", "bell"] {
encoder.append(word);
}
let range = encoder.save_to(&mut buf);Fields§
§len: usize§state: C::State<'a>§writer: SlabWriter<'a, C::Item>Implementations§
Source§impl<'a, C: ColumnCursor> Encoder<'a, C>where
C::Item: 'a,
impl<'a, C: ColumnCursor> Encoder<'a, C>where
C::Item: 'a,
Sourcepub fn append<M: MaybePackable<'a, C::Item>>(&mut self, value: M) -> usize
pub fn append<M: MaybePackable<'a, C::Item>>(&mut self, value: M) -> usize
Appends a single value (or null) to the encoder.
Accepts any type implementing MaybePackable for C::Item (e.g. &str, String,
Option<&str> for StrCursor).
Returns the number of items appended (always 1).
pub fn append_item(&mut self, value: Option<Cow<'a, C::Item>>) -> usize
pub fn extend<I: Iterator<Item = Option<Cow<'a, C::Item>>>>(&mut self, iter: I)where
<C as ColumnCursor>::Item: 'a,
pub fn append_bytes(&mut self, bytes: Option<Cow<'a, [u8]>>)
pub fn new(single_slab: bool) -> Self
pub fn with_capacity(_cap: usize, single_slab: bool) -> Self
pub fn init(writer: SlabWriter<'a, C::Item>, state: C::State<'a>) -> Self
pub fn copy( &mut self, slab: &'a [u8], range: Range<usize>, lit: usize, size: usize, acc: Acc, bool_state: Option<bool>, )
Sourcepub fn flush(&mut self)
pub fn flush(&mut self)
Flushes any buffered state to the internal writer. Usually called automatically by
save_to / into_column_data; call manually only if you need to finalize the encoder
state before those methods.
Sourcepub fn save_to(self, out: &mut Vec<u8>) -> Range<usize>
pub fn save_to(self, out: &mut Vec<u8>) -> Range<usize>
Flushes and appends the encoded bytes to out, returning the byte range written.
Only valid for encoders created with single_slab = true (i.e. Encoder::default()).
Sourcepub fn save_to_unless_empty(self, out: &mut Vec<u8>) -> Range<usize>
pub fn save_to_unless_empty(self, out: &mut Vec<u8>) -> Range<usize>
Like save_to but writes nothing if all appended values were
null/empty, returning an empty range.
pub fn save_to_and_remap_unless_empty<'b, F>( self, out: &mut Vec<u8>, f: F, ) -> Range<usize>
pub fn save_to_and_remap<'b, F>(self, out: &mut Vec<u8>, f: F) -> Range<usize>
Sourcepub fn into_column_data(self) -> ColumnData<C>
pub fn into_column_data(self) -> ColumnData<C>
Finalizes and converts the encoder into a ColumnData.