-
Notifications
You must be signed in to change notification settings - Fork 0
/
:w
43 lines (37 loc) · 1.1 KB
/
:w
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use std::collections::HashMap;
pub struct RdbParser {
data: Vec<u8>,
index: usize,
}
enum OpCodes {}
// Public
impl RdbParser {
pub fn new(data: Vec<u8>) -> Self {
Self { data, index: 0 }
}
pub fn rdb_to_db(&mut self) -> HashMap<String, String> {
let fb_pos = self.data.iter().position(|&b| b == 0xfb).unwrap();
let mut pos = fb_pos + 4;
let len = self.data[pos];
pos += 1;
let key = &self.data[pos..(pos + len as usize)];
let key = std::str::from_utf8(key).unwrap();
// Parse Value
let mut pos = pos + len as usize;
let len = self.data[pos];
pos += 1;
let value = &self.data[pos..(pos + len as usize)];
let value = std::str::from_utf8(value).unwrap();
let mut database: HashMap<String, String> = HashMap::new();
database.insert(String::from(key), String::from(value));
database
}
// Private
fn parse_header(&mut self) {
let header = self.data[0..9];
self.index += 9;
};
fn parse_metadata();
fn parse();
fn parse_key_value();
}