Mountain/IPC/Common/MessageType/
IPCMessage.rs1use serde::{Deserialize, Serialize};
7
8use crate::IPC::Common::MessageType::MessagePriority;
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct Struct {
12 pub Id:String,
13
14 pub Command:String,
15
16 pub Payload:serde_json::Value,
17
18 pub Timestamp:u64,
19
20 pub CorrelationId:Option<String>,
21
22 pub Priority:MessagePriority::Enum,
23}
24
25impl Struct {
26 pub fn new(Command:impl Into<String>) -> Self {
27 Self {
28 Id:uuid::Uuid::new_v4().to_string(),
29
30 Command:Command.into(),
31
32 Payload:serde_json::Value::Null,
33
34 Timestamp:chrono::Utc::now().timestamp_millis() as u64,
35
36 CorrelationId:None,
37
38 Priority:MessagePriority::Enum::Normal,
39 }
40 }
41
42 pub fn WithPayload(mut self, Payload:serde_json::Value) -> Self {
43 self.Payload = Payload;
44
45 self
46 }
47
48 pub fn WithCorrelationId(mut self, CorrelationId:impl Into<String>) -> Self {
49 self.CorrelationId = Some(CorrelationId.into());
50
51 self
52 }
53
54 pub fn WithPriority(mut self, Priority:MessagePriority::Enum) -> Self {
55 self.Priority = Priority;
56
57 self
58 }
59}