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(