-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket.rs
More file actions
executable file
·42 lines (34 loc) · 1.06 KB
/
socket.rs
File metadata and controls
executable file
·42 lines (34 loc) · 1.06 KB
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
35
36
37
38
39
40
41
42
use arrayvec::ArrayString;
use serde_derive::{Deserialize, Serialize};
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "alloc")]
use alloc::string::ToString;
use crate::{DeviceId, SceneId, UpdateNotification, UpdateRequest};
#[derive(Clone, Debug, Serialize, Deserialize)]
#[non_exhaustive]
pub enum ServerBoundSocketMessage {
UpdateRequest(UpdateRequest),
ActivateScene(SceneId),
StateQuery { device_id: DeviceId },
}
pub type FailureMessage = ArrayString<100>;
#[derive(Clone, Debug, Serialize, Deserialize)]
#[non_exhaustive]
pub enum ClientBoundSocketMessage {
Unimplemented,
RequestReceived,
UpdateNotification(UpdateNotification),
Failure(Option<FailureMessage>),
}
#[cfg(feature = "alloc")]
impl From<anyhow::Error> for ClientBoundSocketMessage {
fn from(err: anyhow::Error) -> Self {
let message = err.chain().next().map(|c| c.to_string());
Self::Failure(message.map(|message| {
let mut arr_str = FailureMessage::new();
arr_str.push_str(&message);
arr_str
}))
}
}