diff options
author | hozan23 <hozan23@karyontech.net> | 2024-05-23 00:19:58 +0200 |
---|---|---|
committer | hozan23 <hozan23@karyontech.net> | 2024-05-23 00:19:58 +0200 |
commit | 2d1a8aea0b9330cd2eaad26eb187644adad6bed9 (patch) | |
tree | 6083adaa09ae2f0ef2912f7934cdf0bfafff1654 /jsonrpc/src/message.rs | |
parent | cc1d61c401e52ba3b6cd264c5400fb7ab52522dc (diff) |
jsonrpc: spawn task when handle new request
Diffstat (limited to 'jsonrpc/src/message.rs')
-rw-r--r-- | jsonrpc/src/message.rs | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/jsonrpc/src/message.rs b/jsonrpc/src/message.rs index 9c89362..2cf28b1 100644 --- a/jsonrpc/src/message.rs +++ b/jsonrpc/src/message.rs @@ -1,5 +1,9 @@ use serde::{Deserialize, Serialize}; +use crate::SubscriptionID; + +pub type ID = u64; + pub const JSONRPC_VERSION: &str = "2.0"; /// Parse error: Invalid JSON was received by the server. @@ -32,24 +36,25 @@ pub struct Request { pub struct Response { pub jsonrpc: String, #[serde(skip_serializing_if = "Option::is_none")] + pub id: Option<serde_json::Value>, + #[serde(skip_serializing_if = "Option::is_none")] pub result: Option<serde_json::Value>, #[serde(skip_serializing_if = "Option::is_none")] pub error: Option<Error>, - #[serde(skip_serializing_if = "Option::is_none")] - pub id: Option<serde_json::Value>, - #[serde(skip_serializing_if = "Option::is_none")] - pub subscription: Option<serde_json::Value>, } #[derive(Debug, Serialize, Deserialize)] pub struct Notification { pub jsonrpc: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub method: Option<String>, + pub method: String, #[serde(skip_serializing_if = "Option::is_none")] pub params: Option<serde_json::Value>, - #[serde(skip_serializing_if = "Option::is_none")] - pub subscription: Option<serde_json::Value>, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct NotificationResult { + pub result: Option<serde_json::Value>, + pub subscription: SubscriptionID, } #[derive(Debug, Serialize, Deserialize)] @@ -74,8 +79,8 @@ impl std::fmt::Display for Response { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, - "{{jsonrpc: {}, result': {:?}, error: {:?} , id: {:?}, subscription: {:?}}}", - self.jsonrpc, self.result, self.error, self.id, self.subscription + "{{jsonrpc: {}, result': {:?}, error: {:?} , id: {:?}}}", + self.jsonrpc, self.result, self.error, self.id, ) } } @@ -94,8 +99,8 @@ impl std::fmt::Display for Notification { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, - "{{jsonrpc: {}, method: {:?}, params: {:?}, subscription: {:?}}}", - self.jsonrpc, self.method, self.params, self.subscription + "{{jsonrpc: {}, method: {:?}, params: {:?}}}", + self.jsonrpc, self.method, self.params ) } } |