Skip to main content

Encoder

Struct Encoder 

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

Binary encoder with RLE bit packing.

Implementations§

Source§

impl Encoder

Source

pub fn new() -> Self

Create a new encoder.

Source

pub fn encode<F, R>(f: F) -> R
where F: FnOnce(&mut Encoder) -> R,

Encode using a thread-local encoder for optimal performance. This avoids allocation overhead by reusing the encoder across calls.

Source

pub fn push_string(&mut self, val: &str)

Push a string value with dictionary deduplication.

Source

pub fn push_int(&mut self, val: i64)

Source

pub fn push_bounded_int(&mut self, val: i64, min: i64)

Source

pub fn push_uint(&mut self, val: u64)

Source

pub fn push_float(&mut self, val: f32)

Source

pub fn push_float_quantized(&mut self, val: f32, precision: f32)

Source

pub fn push_boolean(&mut self, val: bool)

Source

pub fn push_enum(&mut self, val: u32, num_bits: u8)

Source

pub fn push_bit_packed_int( &mut self, val: i64, min: i64, max: i64, num_bits: u8, )

Source

pub fn push_string_diff(&mut self, a: &str, b: &str)

Source

pub fn push_int_diff(&mut self, _a: i64, b: i64)

Source

pub fn push_uint_diff(&mut self, _a: u64, b: u64)

Source

pub fn push_bounded_int_diff(&mut self, _a: i64, b: i64, min: i64)

Source

pub fn push_float_diff(&mut self, _a: f32, b: f32)

Source

pub fn push_float_quantized_diff(&mut self, _a: f32, b: f32, precision: f32)

Source

pub fn push_boolean_diff(&mut self, a: bool, b: bool)

Source

pub fn push_enum_diff(&mut self, _a: u32, b: u32, num_bits: u8)

Source

pub fn push_bit_packed_int_diff( &mut self, _a: i64, b: i64, min: i64, max: i64, num_bits: u8, )

Source

pub fn push_object_diff<T, E, F>( &mut self, a: &T, b: &T, equals: E, encode_diff: F, )
where E: FnOnce(&T, &T) -> bool, F: FnOnce(&mut Self),

Source

pub fn push_field_diff<T, E, F>( &mut self, a: &T, b: &T, equals: E, encode_diff: F, )
where E: FnOnce(&T, &T) -> bool, F: FnOnce(&mut Self, &T, &T),

Source

pub fn push_array<T, F>(&mut self, arr: &[T], inner_write: F)
where F: FnMut(&mut Self, &T),

Encode an array by writing length followed by each element.

Source

pub fn push_array_diff<T, FW, FD, E>( &mut self, a: &[T], b: &[T], equals: E, inner_write: FW, inner_diff: FD, )
where FW: FnMut(&mut Self, &T), FD: FnMut(&mut Self, &T, &T), E: FnMut(&T, &T) -> bool,

Encode array diff by comparing lengths and elements. Caller handles change bit.

Source

pub fn push_optional<T, F>(&mut self, opt: &Option<T>, inner_write: F)
where F: FnMut(&mut Self, &T),

Encode an optional value by writing presence flag followed by value if present.

Source

pub fn push_optional_diff<T, FW, FD>( &mut self, a: &Option<T>, b: &Option<T>, inner_write: FW, inner_diff: FD, )
where FW: FnMut(&mut Self, &T), FD: FnMut(&mut Self, &T, &T),

Encode optional diff, matching TS/C# format. Optimization: if a was None, we know b must be Some (else unchanged). So skip the present bit in None→Some case.

Source

pub fn push_record<K, V, FK, FV>( &mut self, map: &IndexMap<K, V>, key_write: FK, val_write: FV, )
where K: Hash + Eq, FK: FnMut(&mut Self, &K), FV: FnMut(&mut Self, &V),

Encode a record (map) by writing length followed by key-value pairs.

Source

pub fn push_record_diff<K, V, FK, FV, FVD, E>( &mut self, a: &IndexMap<K, V>, b: &IndexMap<K, V>, equals: E, key_write: FK, val_write: FV, val_diff: FVD, )
where K: Clone + Hash + Eq, FK: FnMut(&mut Self, &K), FV: FnMut(&mut Self, &V), FVD: FnMut(&mut Self, &V, &V), E: FnMut(&V, &V) -> bool,

Encode record diff, matching TS/C# format. Caller handles change bit.

Source

pub fn finish(&mut self) -> Vec<u8>

Finish encoding and return the buffer.

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.