json_rpc_types/request.rs
1use serde::{Serialize, Deserialize};
2
3type StrBuf = str_buf::StrBuf<32>;
4
5use crate::version::Version;
6use crate::id::Id;
7
8///Request representation.
9///
10///Note that omitting `id` means that request is notification, rather than call, which expects
11///response.
12///This can be used to indicate lack of interest in response.
13///
14///Type parameters:
15///
16///- `P` - to specify type of `params` field, which is optional. Normally it should be collection of values or object. But choice is yours.
17///- `T` - specifies textual type. By default it uses static buffer of 32 bytes, which is more than enough in normal cases.
18#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
19#[serde(deny_unknown_fields)]
20pub struct Request<P, T=StrBuf> {
21 ///A String specifying the version of the JSON-RPC protocol.
22 #[serde(default)]
23 pub jsonrpc: Version,
24 ///A String containing the name of the method to be invoked
25 ///
26 ///By default is static buffer of 32 bytes.
27 pub method: T,
28 #[serde(skip_serializing_if = "Option::is_none")]
29 ///A Structured value that holds the parameter values to be used during the invocation of the method
30 pub params: Option<P>,
31 #[serde(skip_serializing_if = "Option::is_none")]
32 ///An identifier established by the Client.
33 ///
34 ///If not present, request is notification to which
35 ///there should be no response.
36 pub id: Option<Id>,
37}
38
39impl<P, T> Request<P, T> {
40 ///Returns whether request is notification.
41 pub const fn is_notification(&self) -> bool {
42 self.id.is_none()
43 }
44}