amadeus_runtime/consensus/
consensus_muts.rs1#[derive(Clone, Debug, PartialEq)]
2pub enum Mutation {
3 Put { op: Vec<u8>, key: Vec<u8>, value: Vec<u8> },
4 Delete { op: Vec<u8>, key: Vec<u8> },
5 SetBit { op: Vec<u8>, key: Vec<u8>, value: u64, bloomsize: u64 },
6 ClearBit { op: Vec<u8>, key: Vec<u8>, value: u64 },
7}
8
9use std::collections::HashMap;
10
11#[inline]
12fn u64_ascii(n: u64) -> Vec<u8> {
13 n.to_string().into_bytes()
14}
15
16pub fn mutations_to_map(muts: Vec<Mutation>) -> Vec<HashMap<Vec<u8>, Vec<u8>>> {
17 let mut out = Vec::with_capacity(muts.len());
18
19 for m in muts {
20 let mut map: HashMap<Vec<u8>, Vec<u8>> = HashMap::with_capacity(5);
21
22 match m {
23 Mutation::Put { op, key, value } => {
24 map.insert(b"op".to_vec(), op); map.insert(b"key".to_vec(), key); map.insert(b"value".to_vec(), value); }
28 Mutation::Delete { op, key } => {
29 map.insert(b"op".to_vec(), op);
30 map.insert(b"key".to_vec(), key);
31 }
32 Mutation::SetBit { op, key, value, bloomsize } => {
33 map.insert(b"op".to_vec(), op);
34 map.insert(b"key".to_vec(), key);
35 map.insert(b"value".to_vec(), u64_ascii(value));
36 map.insert(b"bloomsize".to_vec(), u64_ascii(bloomsize));
37 }
38 Mutation::ClearBit { op, key, value } => {
39 map.insert(b"op".to_vec(), op);
40 map.insert(b"key".to_vec(), key);
41 map.insert(b"value".to_vec(), u64_ascii(value));
42 }
43 }
44
45 out.push(map);
46 }
47
48 out
49}