1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6pub const BUF_SIZE: usize = (u16::MAX as usize) + 1;
7pub const TCP_ADDR: &str = "0.0.0.0:5123";
8#[cfg(unix)]
9pub const UNIX_PATH: &str = "/tmp/ipc_broker.sock";
10#[cfg(windows)]
11pub const PIPE_PATH: &str = r"\\.\pipe\ipc_broker";
12
13#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
14pub struct ClientId(String);
15
16impl From<Uuid> for ClientId {
17 fn from(uuid: Uuid) -> Self {
18 ClientId(uuid.to_string())
19 }
20}
21
22impl fmt::Display for ClientId {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 write!(f, "{}", self.0)
26 }
27}
28
29#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
30pub struct CallId(String);
31
32impl From<Uuid> for CallId {
33 fn from(uuid: Uuid) -> Self {
34 CallId(uuid.to_string())
35 }
36}
37
38#[derive(Serialize, Deserialize, Debug, PartialEq)]
39pub enum RpcRequest {
40 RegisterObject {
41 object_name: String,
42 },
43 Call {
44 call_id: CallId,
45 object_name: String,
46 method: String,
47 args: serde_json::Value,
48 },
49 Subscribe {
50 object_name: String,
51 topic: String,
52 },
53 Publish {
54 object_name: String,
55 topic: String,
56 args: serde_json::Value,
57 },
58 HasObject {
59 object_name: String,
60 },
61}
62
63#[derive(Serialize, Deserialize, Debug, PartialEq)]
64pub enum RpcResponse {
65 Registered {
66 object_name: String,
67 },
68 Result {
69 call_id: CallId,
70 object_name: String,
71 value: serde_json::Value,
72 },
73 Error {
74 call_id: Option<CallId>,
75 object_name: String,
76 message: String,
77 },
78 Event {
79 object_name: String,
80 topic: String,
81 args: serde_json::Value,
82 },
83 Subscribed {
84 object_name: String,
85 topic: String,
86 },
87 HasObjectResult {
88 object_name: String,
89 exists: bool,
90 },
91}