act_lib/
patch_index_helper.rs

1pub struct ModifiedIndex {
2    pub pos: u32,
3    pub size: u32,
4}
5
6pub struct PatchIndexHelper {
7    pub higher_index: u32,
8    pub indexes_modified: Vec<ModifiedIndex>,
9}
10
11impl PatchIndexHelper {
12    pub fn new() -> PatchIndexHelper {
13        PatchIndexHelper {
14            higher_index: 0,
15            indexes_modified: vec![],
16        }
17    }
18
19    pub fn register_patched_index(&mut self, index: u32, size: u32) {
20        let modified_index = ModifiedIndex { pos: index, size };
21        self.indexes_modified.push(modified_index);
22    }
23
24    pub fn get_drifted_index(&mut self, original_index: u32) -> u32 {
25        let mut drifted_index = original_index;
26        for index_modify in &self.indexes_modified {
27            if original_index >= index_modify.pos {
28                drifted_index += index_modify.size;
29            }
30        }
31        drifted_index
32    }
33}
34
35impl Default for PatchIndexHelper {
36    fn default() -> Self {
37        Self::new()
38    }
39}