hypen_server/remote/
types.rs1use hypen_engine::Patch;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(tag = "type", rename_all = "camelCase")]
10pub enum RemoteMessage {
11 Hello {
13 #[serde(skip_serializing_if = "Option::is_none", rename = "sessionId")]
15 session_id: Option<String>,
16 #[serde(skip_serializing_if = "Option::is_none")]
18 props: Option<serde_json::Value>,
19 },
20
21 SessionAck {
23 #[serde(rename = "sessionId")]
24 session_id: String,
25 #[serde(rename = "isNew")]
26 is_new: bool,
27 #[serde(rename = "isRestored")]
28 is_restored: bool,
29 },
30
31 InitialTree {
33 module: String,
34 state: serde_json::Value,
35 patches: Vec<Patch>,
36 revision: u64,
37 },
38
39 Patch {
41 module: String,
42 patches: Vec<Patch>,
43 revision: u64,
44 },
45
46 StateUpdate {
48 module: String,
49 state: serde_json::Value,
50 revision: u64,
51 },
52
53 DispatchAction {
55 module: String,
56 action: String,
57 #[serde(skip_serializing_if = "Option::is_none")]
58 payload: Option<serde_json::Value>,
59 },
60
61 SubscribeState {
63 module: String,
64 },
65
66 SessionExpired {
68 #[serde(rename = "sessionId")]
69 session_id: String,
70 reason: String,
71 },
72}
73
74impl RemoteMessage {
75 pub fn to_json(&self) -> Result<String, serde_json::Error> {
77 serde_json::to_string(self)
78 }
79
80 pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
82 serde_json::from_str(json)
83 }
84}