Newer
Older
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
use crate::v2::params::{Id, JsonRpcNotificationParams, JsonRpcParams, TwoPointZero};
use beef::Cow;
use serde::{Deserialize, Serialize};
use serde_json::value::RawValue;
/// [JSON-RPC request object](https://www.jsonrpc.org/specification#request-object)
#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct JsonRpcRequest<'a> {
/// JSON-RPC version.
pub jsonrpc: TwoPointZero,
/// Request ID
#[serde(borrow)]
pub id: Option<&'a RawValue>,
/// Name of the method to be invoked.
#[serde(borrow)]
pub method: Cow<'a, str>,
/// Parameter values of the request.
#[serde(borrow)]
pub params: Option<&'a RawValue>,
}
/// Invalid request with known request ID.
#[derive(Deserialize, Debug)]
pub struct JsonRpcInvalidRequest<'a> {
/// Request ID
#[serde(borrow)]
pub id: Option<&'a RawValue>,
}
/// JSON-RPC notification (a request object without a request ID).
#[derive(Serialize, Deserialize, Debug)]
pub struct JsonRpcNotification<'a> {
/// JSON-RPC version.
pub jsonrpc: TwoPointZero,
/// Name of the method to be invoked.
pub method: &'a str,
/// Parameter values of the request.
pub params: JsonRpcNotificationParams<'a>,
}
/// Serializable [JSON-RPC object](https://www.jsonrpc.org/specification#request-object)
#[derive(Serialize, Debug)]
pub struct JsonRpcCallSer<'a> {
/// JSON-RPC version.
pub jsonrpc: TwoPointZero,
/// Name of the method to be invoked.
pub method: &'a str,
/// Request ID
pub id: Id,
/// Parameter values of the request.
pub params: JsonRpcParams<'a>,
}
impl<'a> JsonRpcCallSer<'a> {
/// Create a new serializable JSON-RPC request.
pub fn new(id: Id, method: &'a str, params: JsonRpcParams<'a>) -> Self {
Self { jsonrpc: TwoPointZero, id, method, params }
}
}
/// Serializable [JSON-RPC notification object](https://www.jsonrpc.org/specification#request-object)
#[derive(Serialize, Debug)]
pub struct JsonRpcNotificationSer<'a> {
/// JSON-RPC version.
pub jsonrpc: TwoPointZero,
/// Name of the method to be invoked.
pub method: &'a str,
/// Parameter values of the request.
pub params: JsonRpcParams<'a>,
}
impl<'a> JsonRpcNotificationSer<'a> {
/// Create a new serializable JSON-RPC request.
pub fn new(method: &'a str, params: JsonRpcParams<'a>) -> Self {
Self { jsonrpc: TwoPointZero, method, params }
}
}