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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use serde::{Deserialize, Serialize};
use tai64::TAI64N;
#[derive(Debug, Eq, PartialEq)]
pub enum TuringOp {
RepoCreate,
RepoDrop,
DbCreate,
DbList,
DbDrop,
DocumentCreate,
DocumentList,
DocumentDrop,
FieldInsert,
FieldGet,
FieldRemove,
FieldModify,
FieldList,
NotSupported,
}
pub async fn from_op<'op>(value: &TuringOp) -> &'op [u8] {
match value {
&TuringOp::RepoCreate => &[0x00],
&TuringOp::RepoDrop => &[0x01],
&TuringOp::DbCreate => &[0x02],
&TuringOp::DbList => &[0x03],
&TuringOp::DbDrop => &[0x04],
&TuringOp::DocumentCreate => &[0x05],
&TuringOp::DocumentList => &[0x06],
&TuringOp::DocumentDrop => &[0x07],
&TuringOp::FieldInsert => &[0x08],
&TuringOp::FieldGet => &[0x09],
&TuringOp::FieldRemove => &[0x0a],
&TuringOp::FieldModify => &[0x0b],
&TuringOp::FieldList => &[0x0c],
&TuringOp::NotSupported => &[0xf1],
}
}
pub async fn to_op<'op>(value: &[u8]) -> TuringOp {
match value {
&[0x00] => TuringOp::RepoCreate,
&[0x01] => TuringOp::RepoDrop,
&[0x02] => TuringOp::DbCreate,
&[0x03] => TuringOp::DbList,
&[0x04] => TuringOp::DbDrop,
&[0x05] => TuringOp::DocumentCreate,
&[0x06] => TuringOp::DocumentList,
&[0x07] => TuringOp::DocumentDrop,
&[0x08] => TuringOp::FieldInsert,
&[0x09] => TuringOp::FieldGet,
&[0x0a] => TuringOp::FieldRemove,
&[0x0b] => TuringOp::FieldModify,
&[0x0c] => TuringOp::FieldList,
&[0xf1] => TuringOp::NotSupported,
_ => TuringOp::NotSupported,
}
}
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct FieldData {
data: Vec<u8>,
created: TAI64N,
modified: TAI64N,
}
impl FieldData {
pub async fn new(value: &[u8]) -> FieldData {
let current_time = TAI64N::now();
Self {
data: value.into(),
created: current_time,
modified: current_time,
}
}
pub async fn update(&mut self, value: &[u8]) -> &FieldData {
self.data = value.into();
self.modified = TAI64N::now();
self
}
}