Skip to main content

DeltaEncoder

Struct DeltaEncoder 

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

Delta encoder using bsdiff

Provides delta compression and decompression with intelligent decision logic, with optional media-aware configuration.

Implementations§

Source§

impl DeltaEncoder

Source

pub fn new() -> Self

Create a new delta encoder with default settings

Source

pub fn with_thresholds( similarity_threshold: f64, min_space_savings: f64, ) -> Self

Create a delta encoder with custom thresholds

Source

pub fn encode( &self, base: &[u8], target: &[u8], ) -> CompressionResult<(Vec<u8>, bool)>

Encode a delta between base and target

Returns (delta_data, should_use_delta)

§Arguments
  • base - Base version data
  • target - Target version data
§Returns

Tuple of (delta_data, should_use_delta). If should_use_delta is false, delta_data contains the full target data instead.

Source

pub fn encode_with_depth( &self, base: &[u8], target: &[u8], current_chain_depth: u32, ) -> CompressionResult<(Vec<u8>, bool)>

Encode a delta between base and target with chain depth tracking

Returns (delta_data, should_use_delta)

§Arguments
  • base - Base version data
  • target - Target version data
  • current_chain_depth - Current depth in the delta chain
§Returns

Tuple of (delta_data, should_use_delta). If should_use_delta is false, delta_data contains the full target data instead.

§Delta Chain Depth

When the chain depth exceeds max_chain_depth, the encoder will return the full object instead of creating another delta. This prevents excessively long delta chains that can hurt decompression performance.

Source

pub fn decode(&self, base: &[u8], delta: &[u8]) -> CompressionResult<Vec<u8>>

Decode a delta to reconstruct the target

§Arguments
  • base - Base version data
  • delta - Delta data
§Returns

Reconstructed target data

Source

pub fn decode_chain( &self, versions: &[(Vec<u8>, bool)], ) -> CompressionResult<Vec<u8>>

Apply a delta chain to reconstruct the final version

§Arguments
  • versions - Ordered list of (data, is_delta) tuples, base first
§Returns

Reconstructed final version

Source

pub fn hash_data(data: &[u8]) -> String

Calculate hash for data (for tracking purposes)

Source

pub fn max_chain_depth(&self) -> u32

Get the maximum chain depth setting

Source

pub fn set_max_chain_depth(&mut self, depth: u32)

Set the maximum chain depth

When encoding deltas, if the current chain depth reaches this value, the encoder will store the full object instead of creating another delta.

§Arguments
  • depth - Maximum allowed chain depth (typically 50-100)
§Example
use mediagit_compression::delta::DeltaEncoder;

let mut encoder = DeltaEncoder::new();
encoder.set_max_chain_depth(75);
assert_eq!(encoder.max_chain_depth(), 75);
Source

pub fn with_max_chain_depth(max_chain_depth: u32) -> Self

Create a delta encoder with custom chain depth

§Arguments
  • max_chain_depth - Maximum allowed chain depth
§Example
use mediagit_compression::delta::DeltaEncoder;

let encoder = DeltaEncoder::with_max_chain_depth(100);
assert_eq!(encoder.max_chain_depth(), 100);

Trait Implementations§

Source§

impl Clone for DeltaEncoder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DeltaEncoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DeltaEncoder

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more