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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
use std::io;
use std::result;
use consistency::Consistency;
use types::*;
use FromCursor;
use frame::Frame;
pub type Result = result::Result<Frame, CDRSError>;
#[derive(Debug)]
pub struct CDRSError {
pub error_code: CInt,
pub message: CString,
pub additional_info: AdditionalErrorInfo
}
impl FromCursor for CDRSError {
fn from_cursor(mut cursor: &mut io::Cursor<Vec<u8>>) -> CDRSError {
let error_code = CInt::from_cursor(&mut cursor);
let message = CString::from_cursor(&mut cursor);
let additional_info = AdditionalErrorInfo::from_cursor_with_code(&mut cursor, error_code);
return CDRSError {
error_code: error_code,
message: message,
additional_info: additional_info
};
}
}
#[derive(Debug)]
pub enum AdditionalErrorInfo {
Server(SimpleError),
Protocol(SimpleError),
Authentication(SimpleError),
Unavailable(UnavailableError),
Overloaded(SimpleError),
IsBootstrapping(SimpleError),
Truncate(SimpleError),
WriteTimeout(WriteTimeoutError),
ReadTimeout(ReadTimeoutError),
ReadFailure(ReadFailureError),
FunctionFailure(FunctionFailureError),
WriteFailure(WriteFailureError),
Syntax(SimpleError),
Unauthorized(SimpleError),
Invalid(SimpleError),
Config(SimpleError),
AlreadyExists(AlreadyExistsError),
Unprepared(UnpreparedError)
}
impl AdditionalErrorInfo {
pub fn from_cursor_with_code(mut cursor: &mut io::Cursor<Vec<u8>>, error_code: CInt)
-> AdditionalErrorInfo {
return match error_code {
0x0000 => AdditionalErrorInfo::Server(SimpleError::from_cursor(&mut cursor)),
0x000A => AdditionalErrorInfo::Protocol(SimpleError::from_cursor(&mut cursor)),
0x0100 => AdditionalErrorInfo::Authentication(SimpleError::from_cursor(&mut cursor)),
0x1000 => AdditionalErrorInfo::Unavailable(UnavailableError::from_cursor(&mut cursor)),
0x1001 => AdditionalErrorInfo::Overloaded(SimpleError::from_cursor(&mut cursor)),
0x1002 => AdditionalErrorInfo::IsBootstrapping(SimpleError::from_cursor(&mut cursor)),
0x1003 => AdditionalErrorInfo::Truncate(SimpleError::from_cursor(&mut cursor)),
0x1100 => AdditionalErrorInfo::WriteTimeout(WriteTimeoutError::from_cursor(&mut cursor)),
0x1200 => AdditionalErrorInfo::ReadTimeout(ReadTimeoutError::from_cursor(&mut cursor)),
0x1300 => AdditionalErrorInfo::ReadFailure(ReadFailureError::from_cursor(&mut cursor)),
0x1400 => AdditionalErrorInfo::FunctionFailure(FunctionFailureError::from_cursor(&mut cursor)),
0x1500 => AdditionalErrorInfo::WriteFailure(WriteFailureError::from_cursor(&mut cursor)),
0x2000 => AdditionalErrorInfo::Syntax(SimpleError::from_cursor(&mut cursor)),
0x2100 => AdditionalErrorInfo::Unauthorized(SimpleError::from_cursor(&mut cursor)),
0x2200 => AdditionalErrorInfo::Invalid(SimpleError::from_cursor(&mut cursor)),
0x2300 => AdditionalErrorInfo::Config(SimpleError::from_cursor(&mut cursor)),
0x2400 => AdditionalErrorInfo::AlreadyExists(AlreadyExistsError::from_cursor(&mut cursor)),
0x2500 => AdditionalErrorInfo::Unprepared(UnpreparedError::from_cursor(&mut cursor)),
_ => unreachable!()
};
}
}
#[derive(Debug)]
pub struct SimpleError {}
impl FromCursor for SimpleError {
fn from_cursor(mut _cursor: &mut io::Cursor<Vec<u8>>) -> SimpleError {
return SimpleError {};
}
}
#[derive(Debug)]
pub struct UnavailableError {
pub cl: Consistency,
pub required: CInt,
pub alive: CInt
}
impl FromCursor for UnavailableError {
fn from_cursor(mut cursor: &mut io::Cursor<Vec<u8>>) -> UnavailableError {
let cl = Consistency::from_cursor(&mut cursor);
let required = CInt::from_cursor(&mut cursor);
let alive = CInt::from_cursor(&mut cursor);
return UnavailableError {
cl: cl,
required: required,
alive: alive
};
}
}
#[derive(Debug)]
pub struct WriteTimeoutError {
pub cl: Consistency,
pub received: CInt,
pub blockfor: CInt,
pub write_type: WriteType
}
impl FromCursor for WriteTimeoutError {
fn from_cursor(mut cursor: &mut io::Cursor<Vec<u8>>) -> WriteTimeoutError {
let cl = Consistency::from_cursor(&mut cursor);
let received = CInt::from_cursor(&mut cursor);
let blockfor = CInt::from_cursor(&mut cursor);
let write_type = WriteType::from_cursor(&mut cursor);
return WriteTimeoutError {
cl: cl,
received: received,
blockfor: blockfor,
write_type: write_type
};
}
}
#[derive(Debug)]
pub struct ReadTimeoutError {
pub cl: Consistency,
pub received: CInt,
pub blockfor: CInt,
data_present: u8
}
impl ReadTimeoutError {
pub fn replica_has_responded(&self) -> bool {
return self.data_present != 0;
}
}
impl FromCursor for ReadTimeoutError {
fn from_cursor(mut cursor: &mut io::Cursor<Vec<u8>>) -> ReadTimeoutError {
let cl = Consistency::from_cursor(&mut cursor);
let received = CInt::from_cursor(&mut cursor);
let blockfor = CInt::from_cursor(&mut cursor);
let data_present = from_bytes(cursor_next_value(&mut cursor, 1)) as u8;
return ReadTimeoutError {
cl: cl,
received: received,
blockfor: blockfor,
data_present: data_present
};
}
}
#[derive(Debug)]
pub struct ReadFailureError {
pub cl: Consistency,
pub received: CInt,
pub blockfor: CInt,
pub num_failures: CInt,
data_present: u8
}
impl ReadFailureError {
pub fn replica_has_responded(&self) -> bool {
return self.data_present != 0;
}
}
impl FromCursor for ReadFailureError {
fn from_cursor(mut cursor: &mut io::Cursor<Vec<u8>>) -> ReadFailureError {
let cl = Consistency::from_cursor(&mut cursor);
let received = CInt::from_cursor(&mut cursor);
let blockfor = CInt::from_cursor(&mut cursor);
let num_failures = CInt::from_cursor(&mut cursor);
let data_present = from_bytes(cursor_next_value(&mut cursor, 1)) as u8;
return ReadFailureError {
cl: cl,
received: received,
blockfor: blockfor,
num_failures: num_failures,
data_present: data_present
};
}
}
#[derive(Debug)]
pub struct FunctionFailureError {
pub keyspace: CString,
pub function: CString,
pub arg_types: CStringList
}
impl FromCursor for FunctionFailureError {
fn from_cursor(mut cursor: &mut io::Cursor<Vec<u8>>) -> FunctionFailureError {
let keyspace = CString::from_cursor(&mut cursor);
let function = CString::from_cursor(&mut cursor);
let arg_types = CStringList::from_cursor(&mut cursor);
return FunctionFailureError {
keyspace: keyspace,
function: function,
arg_types: arg_types
};
}
}
#[derive(Debug)]
pub struct WriteFailureError {
pub cl: Consistency,
pub received: CInt,
pub blockfor: CInt,
pub num_failures: CInt,
pub write_type: WriteType
}
impl FromCursor for WriteFailureError {
fn from_cursor(mut cursor: &mut io::Cursor<Vec<u8>>) -> WriteFailureError {
let cl = Consistency::from_cursor(&mut cursor);
let received = CInt::from_cursor(&mut cursor);
let blockfor = CInt::from_cursor(&mut cursor);
let num_failures = CInt::from_cursor(&mut cursor);
let write_type = WriteType::from_cursor(&mut cursor);
return WriteFailureError {
cl: cl,
received: received,
blockfor: blockfor,
num_failures: num_failures,
write_type: write_type
};
}
}
#[derive(Debug)]
pub enum WriteType {
Simple,
Batch,
UnloggedBatch,
Counter,
BatchLog
}
impl FromCursor for WriteType {
fn from_cursor(mut cursor: &mut io::Cursor<Vec<u8>>) -> WriteType {
return match CString::from_cursor(&mut cursor).as_str() {
"SIMPLE" => WriteType::Simple,
"BATCH" => WriteType::Batch,
"UNLOGGED_BATCH" => WriteType::UnloggedBatch,
"COUNTER" => WriteType::Counter,
"BATCH_LOG" => WriteType::BatchLog,
_ => unreachable!()
};
}
}
#[derive(Debug)]
pub struct AlreadyExistsError {
pub ks: CString,
pub table: CString
}
impl FromCursor for AlreadyExistsError {
fn from_cursor(mut cursor: &mut io::Cursor<Vec<u8>>) -> AlreadyExistsError {
let ks = CString::from_cursor(&mut cursor);
let table = CString::from_cursor(&mut cursor);
return AlreadyExistsError {
ks: ks,
table: table
};
}
}
#[derive(Debug)]
pub struct UnpreparedError {
pub id: CBytes
}
impl FromCursor for UnpreparedError {
fn from_cursor(mut cursor: &mut io::Cursor<Vec<u8>>) -> UnpreparedError {
let id = CBytes::from_cursor(&mut cursor);
return UnpreparedError {
id: id
};
}
}