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