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 #[serde(default)]
56 module: String,
57 action: String,
58 #[serde(skip_serializing_if = "Option::is_none")]
59 payload: Option<serde_json::Value>,
60 },
61
62 SubscribeState { module: String },
64
65 SessionExpired {
67 #[serde(rename = "sessionId")]
68 session_id: String,
69 reason: String,
70 },
71}
72
73impl RemoteMessage {
74 pub fn to_json(&self) -> Result<String, serde_json::Error> {
76 serde_json::to_string(self)
77 }
78
79 pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
81 serde_json::from_str(json)
82 }
83}