Struct Delta

Source
pub struct Delta {
    pub base_tick: u32,
    pub tick: u32,
    pub bytes: Vec<u8>,
}

Fields§

§base_tick: u32§tick: u32§bytes: Vec<u8>

Implementations§

Source§

impl Delta

Source

pub fn encoded_len(base: &[u8], next: &[u8]) -> Result<usize, DeltaError>

Plan the exact inner wire length without allocating. Equal lengths and the historical snapshot limit (MAX_PACKET_BYTES - 11) are checked before counting changes, so all size arithmetic is bounded. This does not plan the outer ServerExtension::SnapshotDelta envelope (24 more bytes).

use ferravex_net::delta::{Delta, DeltaError};
assert_eq!(Delta::encoded_len(&[0; 10], &[1; 10]), Ok(13));
assert_eq!(Delta::encoded_len(&[0; 10], &[0; 10]), Ok(3));
assert_eq!(Delta::encoded_len(&[0], &[]),
    Err(DeltaError::LengthMismatch { base: 1, next: 0 }));
Source

pub fn encode_into( base: &[u8], next: &[u8], destination: &mut [u8], ) -> Result<usize, DeltaError>

Encode just Delta::bytes into a caller slice, returning its written prefix length. Snapshot validation precedes capacity validation. Every error preserves the entire destination; success preserves the tail. Uses the slice’s length, not any backing Vec’s capacity.

use ferravex_net::delta::Delta;
let mut output = [99; 20];
let n = Delta::encode_into(&[0; 10], &[1; 10], &mut output).unwrap();
assert_eq!(&output[..n], Delta::between(1, &[0; 10], 2, &[1; 10]).unwrap().bytes);
assert_eq!(&output[n..], &[99; 7]);
Source

pub fn between_into( &mut self, base_tick: u32, base: &[u8], tick: u32, next: &[u8], ) -> Result<(), DeltaError>

Replace this delta using its existing Vec capacity, with no allocation. On error, ticks, bytes, length and capacity are unchanged. On success, bytes are replaced (never appended); unused Vec capacity is not scrubbed. Reserve outside the hot path. This deliberately allows any tick pair, matching Self::between; the outer wire codec checks serial ordering.

use ferravex_net::delta::Delta;
let mut delta = Delta { base_tick: 0, tick: 0, bytes: Vec::with_capacity(20) };
delta.between_into(7, &[0; 10], 8, &[1; 10]).unwrap();
delta.between_into(8, &[1; 10], 9, &[1; 10]).unwrap();
assert_eq!(delta.bytes, [10, 0, 1]); // Dense storage was replaced by sparse.
assert_eq!(delta.apply(8, &[1; 10]).unwrap(), [1; 10]);
Source

pub fn between( base_tick: u32, base: &[u8], tick: u32, next: &[u8], ) -> Result<Delta, ProtocolError>

Source

pub fn applied_len( &self, base_tick: u32, base: &[u8], ) -> Result<usize, DeltaError>

Validate the entire delta and return the reconstructed snapshot length, without allocation or writes. Checks run in this order: base tick, header availability, base limit, encoded limit, encoded/base length, tag/body shape, then each sparse range and order. No canonical sparse density or value-change requirement is imposed, preserving legacy apply. See the module’s runnable snapshot recipe and Self::apply_into.

Source

pub fn apply_into( &self, base_tick: u32, base: &[u8], destination: &mut [u8], ) -> Result<usize, DeltaError>

Apply into a caller slice without allocating. Complete validation via Self::applied_len precedes destination capacity checking and all writes. Every error preserves the entire destination, even a late corrupt entry. Success replaces only the returned prefix; the tail is untouched. Input and destination must be disjoint. Matching ticks alone cannot verify the baseline contents: select the exact retained bytes at the session layer.

use ferravex_net::delta::{Delta, DeltaError};
let delta = Delta::between(4, &[0; 10], 5, &[1; 10]).unwrap();
let mut output = [99; 12];
assert_eq!(delta.apply_into(3, &[0; 10], &mut output),
    Err(DeltaError::BaseTickMismatch { expected: 4, actual: 3 }));
assert_eq!(output, [99; 12]);
assert_eq!(delta.apply_into(4, &[0; 10], &mut output), Ok(10));
assert_eq!(output, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 99, 99]);
Source

pub fn apply( &self, base_tick: u32, base: &[u8], ) -> Result<Vec<u8>, ProtocolError>

Trait Implementations§

Source§

impl Clone for Delta

Source§

fn clone(&self) -> Delta

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Delta

Source§

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

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

impl PartialEq for Delta

Source§

fn eq(&self, other: &Delta) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Delta

Source§

impl StructuralPartialEq for Delta

Auto Trait Implementations§

§

impl Freeze for Delta

§

impl RefUnwindSafe for Delta

§

impl Send for Delta

§

impl Sync for Delta

§

impl Unpin for Delta

§

impl UnwindSafe for Delta

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, 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 = 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.