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
use crate::{Result, ResultExt}; use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] pub enum ResponseMessage { ServerError { reason: String, content: String }, Pong { v: i64 }, Connected { p: Box<crate::project::ProjectDescription>, u: Box<crate::profile::UserProfile> }, SchemaResponse { schema: crate::Schema }, SqlResponse { result: crate::database::results::ResultSet } } impl ResponseMessage { pub fn from_json(s: &str) -> Result<ResponseMessage> { serde_json::from_str(&s).chain_err(|| format!("Can't decode ResponseMessage from [{}]", s)) } pub fn to_json(&self) -> Result<String> { serde_json::to_string_pretty(&self).chain_err(|| format!("Can't encode ResponseMessage [{:?}]", &self)) } }