Skip to main content

encode

Function encode 

Source
pub fn encode(base: &[u8], result: &[u8]) -> Result<Vec<u8>, MkitError>
Expand description

Build a v1 delta stream that reconstructs result from base.

The writer is an FNV-1a-on-16-byte-blocks scan. Any conformant writer is acceptable; this one is greedy. Output is always at least HEADER_LEN bytes.

§Errors

Returns MkitError::DeltaLengthOverflow if either base.len() or result.len() exceeds u32::MAX. SPEC-PACKFILE caps individual payloads under this bound, so this is a programmer error rather than a normal runtime condition — but silently saturating (the old behaviour) produced a stream that decode() rejected with a confusing “length mismatch” far from the actual source.

§Panics

Panics only on invariant violations in the writer’s bookkeeping (insert-buffer length > 127, match length > u16::MAX); both are guarded above and unreachable for any valid input.