From 74e901cd465ad4696775666254abc7d4057d472d Mon Sep 17 00:00:00 2001 From: Sosthene Date: Fri, 19 Jul 2024 22:46:07 +0200 Subject: [PATCH] Add to_string and from_string methods to network types --- src/network.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/network.rs b/src/network.rs index c989730..54f3c94 100644 --- a/src/network.rs +++ b/src/network.rs @@ -105,6 +105,10 @@ impl CipherMessage { error: None, } } + + pub fn to_string(&self) -> String { + serde_json::to_string(self).unwrap() + } } #[derive(Debug, Serialize, Deserialize, Tsify)] @@ -121,6 +125,15 @@ impl AnkNetworkMsg { content: raw.into(), } } + + pub fn from_string(json: &str) -> Result { + let res: Self = serde_json::from_str(json)?; + Ok(res) + } + + pub fn to_string(&self) -> String { + serde_json::to_string(self).unwrap() + } } #[derive(Debug, Default, Serialize, Deserialize, PartialEq, Tsify, Clone)] @@ -178,6 +191,15 @@ impl CachedMessage { new } + pub fn from_string(json: &str) -> Result { + let res = serde_json::from_str(json)?; + Ok(res) + } + + pub fn to_string(&self) -> String { + serde_json::to_string(self).unwrap() + } + pub fn try_decrypt_cipher(&self, cipher: Vec) -> Result> { if self.ciphertext.is_some() || self.shared_secret.is_none() { return Err(Error::msg(