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
use super::{KeyRange, KeyValue};
use crate::proto::etcdserverpb;
use crate::ResponseHeader;
pbwrap_request!(
RangeRequest
);
impl RangeRequest {
pub fn new(key_range: KeyRange) -> Self {
Self {
proto: etcdserverpb::RangeRequest {
key: key_range.key,
range_end: key_range.range_end,
limit: 0,
revision: 0,
sort_order: 0,
sort_target: 0,
serializable: false,
keys_only: false,
count_only: false,
min_mod_revision: 0,
max_mod_revision: 0,
min_create_revision: 0,
max_create_revision: 0,
},
}
}
pub fn set_limit(&mut self, limit: usize) {
self.proto.limit = limit as i64;
}
}
pbwrap_response!(RangeResponse);
impl RangeResponse {
pub fn take_header(&mut self) -> Option<ResponseHeader> {
self.proto.header.take().map(From::from)
}
pub fn take_kvs(&mut self) -> Vec<KeyValue> {
std::mem::take(&mut self.proto.kvs)
.into_iter()
.map(From::from)
.collect()
}
pub fn has_more(&self) -> bool {
self.proto.more
}
pub fn count(&self) -> usize {
self.proto.count as usize
}
}