-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathpull.rs
62 lines (53 loc) · 1.81 KB
/
pull.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
#![cfg_attr(feature = "unstable-bolt-protocol-impl-v2", allow(deprecated))]
use crate::types::BoltMap;
use neo4rs_macros::BoltStruct;
#[derive(Debug, PartialEq, Clone, BoltStruct)]
#[signature(0xB1, 0x3F)]
#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.9.0", note = "Use `crate::bolt::Pull` instead.")
)]
pub struct Pull {
extra: BoltMap,
}
impl Default for Pull {
fn default() -> Self {
Pull::new(-1, -1)
}
}
impl Pull {
#[cfg_attr(feature = "unstable-bolt-protocol-impl-v2", allow(dead_code))]
pub fn new(n: i64, qid: i64) -> Pull {
let mut extra = BoltMap::default();
extra.put("n".into(), n.into());
extra.put("qid".into(), qid.into());
Pull { extra }
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::types::BoltWireFormat;
use crate::version::Version;
use bytes::Bytes;
#[test]
fn should_serialize_pull_message() {
let pull = Pull::new(42, 1);
let mut bytes: Bytes = pull.into_bytes(Version::V4_1).unwrap();
let marker_signature = bytes.split_to(2);
assert_eq!(&*marker_signature, &[0xB1, 0x3F]);
let extra: BoltMap = BoltMap::parse(Version::V4_1, &mut bytes).unwrap();
assert_eq!(extra.get::<i64>("n").unwrap(), 42);
assert_eq!(extra.get::<i64>("qid").unwrap(), 1);
}
#[test]
fn should_serialize_pull_with_default_value() {
let pull = Pull::default();
let mut bytes: Bytes = pull.into_bytes(Version::V4_1).unwrap();
let marker_signature = bytes.split_to(2);
assert_eq!(&*marker_signature, &[0xB1, 0x3F]);
let extra: BoltMap = BoltMap::parse(Version::V4_1, &mut bytes).unwrap();
assert_eq!(extra.get::<i64>("n").unwrap(), 255);
assert_eq!(extra.get::<i64>("qid").unwrap(), 255);
}
}