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
use crate::protocols::ProtocolPayload;
use serde::{Deserialize, Serialize};
use serde_bare::Uint;
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct CreateStreamRequest {
pub stream_name: Option<String>,
}
impl CreateStreamRequest {
#[allow(dead_code, clippy::new_ret_no_self)]
pub fn new<S: Into<Option<String>>>(s: S) -> ProtocolPayload {
ProtocolPayload::new(
"stream_create",
Self {
stream_name: s.into(),
},
)
}
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct PushRequest {
pub request_id: Uint,
pub data: Vec<u8>,
}
impl PushRequest {
#[allow(dead_code, clippy::new_ret_no_self)]
pub fn new<T: Into<Vec<u8>>>(request_id: u64, data: T) -> ProtocolPayload {
ProtocolPayload::new(
"stream_push",
Self {
request_id: Uint(request_id),
data: data.into(),
},
)
}
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct PullRequest {
pub request_id: Uint,
pub index: Uint,
pub limit: Uint,
}
impl PullRequest {
#[allow(dead_code, clippy::new_ret_no_self)]
pub fn new(request_id: u64, index: u64, limit: u64) -> ProtocolPayload {
ProtocolPayload::new(
"stream_pull",
Self {
request_id: Uint(request_id),
index: Uint(index),
limit: Uint(limit),
},
)
}
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub enum Index {
Get {
client_id: String,
stream_name: String,
},
Save {
client_id: String,
stream_name: String,
index: Uint,
},
}
impl Index {
#[allow(dead_code)]
pub fn get<S: Into<String>>(stream_name: S, client_id: S) -> ProtocolPayload {
ProtocolPayload::new(
"stream_index",
Self::Get {
client_id: client_id.into(),
stream_name: stream_name.into(),
},
)
}
#[allow(dead_code)]
pub fn save<S: Into<String>>(stream_name: S, client_id: S, index: u64) -> ProtocolPayload {
ProtocolPayload::new(
"stream_index",
Self::Save {
client_id: client_id.into(),
stream_name: stream_name.into(),
index: Uint(index),
},
)
}
}