pub fn apply_historical_log(
base: &mut Vec<u8>,
delta: &ArchivedHistoricalLogDiff,
)Expand description
Applies a historical log delta to a serialized historical log in place.
HistoricalLogDiff::Unchanged leaves the existing log untouched.
HistoricalLogDiff::Append appends the serialized historical items
contained in the delta to the existing log.
The delta is assumed to have been generated for the supplied base state. This function does not validate that the base log corresponds to the state from which the delta was created.
§Complexity
HistoricalLogDiff::Unchanged: O(1).HistoricalLogDiff::Append: O(k), where k is the number of appended bytes.
§Example
use eth_state_diff::historical_log::{
apply_historical_log,
diff_historical_log,
};
use eth_state_diff::types::ArchivedHistoricalLogDiff;
const ITEM_SIZE: usize = 4;
let mut base = vec![1u8, 2, 3, 4];
let target = vec![1u8, 2, 3, 4, 5, 6, 7, 8];
let delta = diff_historical_log(
8191,
16384,
&target,
ITEM_SIZE,
None,
);
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&delta).expect("failed to serialize");
let archived = rkyv::access::<ArchivedHistoricalLogDiff, rkyv::rancor::Error>(&bytes)
.expect("failed to access");
apply_historical_log(&mut base, archived);
assert_eq!(base, target);