Skip to main content

merge_diff_copy

Function merge_diff_copy 

Source
pub fn merge_diff_copy<'a>(
    destination: &'a mut [u8],
    original: &[u8],
    diffset: &DiffSet<'_>,
) -> Result<&'a mut [u8], ProgramError>
Expand description

Constructs destination by applying the diff to original, such that destination becomes the post-diff state of the original.

Precondition: - destination.len() == diffset.changed_len() - original.len() may differ from destination.len() to allow Solana account resizing (shrink or expand). Assumption: - destination is assumed to be zero-initialized. That automatically holds true for freshly allocated Solana account data. The function does NOT validate this assumption for performance reason. Returns: - Ok(&mut u8) where the slice contains the trailing unwritten bytes in destination and are assumed to be already zero-initialized. Callers may write to those bytes or validate it. Notes: - Merge consists of: - bytes covered by diff segments are written from diffset. - unmodified regions are copied directly from original. - In shrink case, extra trailing bytes from original are ignored. - In expansion case, any remaining bytes beyond both the diff coverage and original.len() stay unwritten and are assumed to be zero-initialized.