Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3700882
D9314.id31948.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D9314.id31948.diff
View Options
diff --git a/shared/tunnelbroker_messages/src/messages/message_to_device.rs b/shared/tunnelbroker_messages/src/messages/message_to_device.rs
new file mode 100644
--- /dev/null
+++ b/shared/tunnelbroker_messages/src/messages/message_to_device.rs
@@ -0,0 +1,30 @@
+// Messages sent between Tunnelbroker and a device via WebSocket
+
+use serde::{Deserialize, Serialize};
+
+#[derive(Serialize, Deserialize, PartialEq, Debug)]
+#[serde(tag = "type", rename_all = "camelCase")]
+pub struct MessageToDevice {
+ #[serde(rename = "deviceID")]
+ pub device_id: String,
+ pub payload: String,
+}
+
+#[cfg(test)]
+mod message_to_device_tests {
+ use super::*;
+
+ #[test]
+ fn test_message_to_device_deserialization() {
+ let example_payload = r#"{
+ "type": "MessageToDevice",
+ "deviceID": "alice",
+ "payload": "message from Bob"
+ }"#;
+
+ let request =
+ serde_json::from_str::<MessageToDevice>(example_payload).unwrap();
+ assert_eq!(request.device_id, "alice");
+ assert_eq!(request.payload, "message from Bob");
+ }
+}
diff --git a/shared/tunnelbroker_messages/src/messages/mod.rs b/shared/tunnelbroker_messages/src/messages/mod.rs
--- a/shared/tunnelbroker_messages/src/messages/mod.rs
+++ b/shared/tunnelbroker_messages/src/messages/mod.rs
@@ -1,8 +1,10 @@
// Messages sent between Tunnelbroker and a device
pub mod keys;
+pub mod message_to_device;
pub mod session;
pub use keys::*;
+pub use message_to_device::*;
pub use session::*;
use serde::{Deserialize, Serialize};
@@ -12,4 +14,5 @@
pub enum Messages {
RefreshKeysRequest(RefreshKeyRequest),
ConnectionInitializationMessage(ConnectionInitializationMessage),
+ MessageToDevice(MessageToDevice),
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jan 8, 5:07 PM (4 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2820604
Default Alt Text
D9314.id31948.diff (1 KB)
Attached To
Mode
D9314: [Tunnelbroker] add WebSocket version of MessageToDevice
Attached
Detach File
Event Timeline
Log In to Comment