Skip to main content

apply_attestations

Function apply_attestations 

Source
pub fn apply_attestations(base: &mut Vec<u8>, delta: &ArchivedAttestationsDiff)
Expand description

Applies an attestation delta to a serialized SSZ list in place.

AttestationsDiff::Unchanged leaves the base buffer untouched.

AttestationsDiff::Append appends the serialized bytes stored in the delta to the existing buffer.

AttestationsDiff::FullReplacement clears the existing buffer and replaces it with the serialized target bytes.

§Complexity

§Example


let mut base = b"AAAA".to_vec();
let delta = diff_attestations(&base, b"AAAABBBB");

match delta {
    AttestationsDiff::Unchanged => {}
    AttestationsDiff::Append(bytes) => base.extend_from_slice(&bytes),
    AttestationsDiff::FullReplacement(bytes) => {
        base.clear();
        base.extend_from_slice(&bytes);
    }
}

assert_eq!(base, b"AAAABBBB");