surrealcs_kernel/messages/server/
kv_operations.rs

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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//! The key value operations that can be performed on the key value store.
use revision::revisioned;
use serde::{Deserialize, Serialize};

/// Check if a key exists.
///
/// # Fields
/// * `key` - The key to check if it exists.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[revisioned(revision = 1)]
pub struct MessageExists {
	pub key: Vec<u8>,
	pub version: Option<u64>,
}

/// Get the value of a key.
///
/// # Fields
/// * `key` - The key to get the value of.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[revisioned(revision = 1)]
pub struct MessageGet {
	pub key: Vec<u8>,
	pub version: Option<u64>,
}

/// Set the value of a key.
///
/// # Fields
/// * `key` - The key to set the value of.
/// * `value` - The value to set the key to.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[revisioned(revision = 1)]
pub struct MessageSet {
	pub key: Vec<u8>,
	pub value: Vec<u8>,
	pub version: Option<u64>,
}

/// Put a key value pair.
///
/// # Fields
/// * `key` - The key to put.
/// * `value` - The value to put.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[revisioned(revision = 1)]
pub struct MessagePut {
	pub key: Vec<u8>,
	pub value: Vec<u8>,
	pub version: Option<u64>,
}

/// Put a key value pair if the value of that key is the same as the one provided.
///
/// # Fields
/// * `key` - The key to put.
/// * `value` - The value to put.
/// * `expected_value` - The expected value of the key before the PUT.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[revisioned(revision = 1)]
pub struct MessagePutc {
	pub key: Vec<u8>,
	pub value: Vec<u8>,
	pub expected_value: Option<Vec<u8>>,
}

/// Delete a key.
///
/// # Fields
/// * `key` - The key to delete.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[revisioned(revision = 1)]
pub struct MessageDel {
	pub key: Vec<u8>,
}

/// Delete a key if the value of that key is the same as the one provided.
///
/// # Fields
/// * `key` - The key to delete.
/// * `expected_value` - The expected value of the key before the DELETE.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[revisioned(revision = 1)]
pub struct MessageDelc {
	pub key: Vec<u8>,
	pub expected_value: Option<Vec<u8>>,
}

/// Delete a key and return the value.
///
/// # Fields
/// * `keys` - The keys to delete.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[revisioned(revision = 1)]
pub struct MessageDelr {
	pub begin: Vec<u8>,
	pub finish: Vec<u8>,
}

/// Get all keys within a range with a limit.
///
/// # Fields
/// * `begin` - The beginning of the range.
/// * `finish` - The end of the range.
/// * `limit` - The limit of the number of keys to return.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[revisioned(revision = 1)]
pub struct MessageKeys {
	pub begin: Vec<u8>,
	pub finish: Vec<u8>,
	pub limit: u32,
	pub version: Option<u64>,
}

/// Get all keys and values within a range with a limit.
///
/// # Fields
/// * `begin` - The beginning of the range.
/// * `finish` - The end of the range.
/// * `limit` - The limit of the number of keys to return.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[revisioned(revision = 1)]
pub struct MessageScan {
	pub begin: Vec<u8>,
	pub finish: Vec<u8>,
	pub limit: u32,
	pub version: Option<u64>,
}

/// The response to the `Get` operation.
///
/// # Fields
/// * `value` - The value of the key.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[revisioned(revision = 1)]
pub struct ResponseGet {
	pub value: Option<Vec<u8>>,
}

/// The response to the `Keys` operation.
///
/// # Fields
/// * `keys` - The keys within the range.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[revisioned(revision = 1)]
pub struct ResponseKeys {
	pub keys: Vec<Vec<u8>>,
}

/// The response to the `Scan` operation.
///
/// # Fields
/// * `values` - The key value pairs within the range.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[revisioned(revision = 1)]
pub struct ResponseScan {
	pub values: Vec<(Vec<u8>, Vec<u8>)>,
}