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 pub Command:String,
16 pub Payload:serde_json::Value,
17 pub Timestamp:u64,
18 pub CorrelationId:Option<String>,
19 pub Priority:MessagePriority::Enum,
20}
21
22impl Struct {
23 pub fn new(Command:impl Into<String>) -> Self {
24 Self {
25 Id:uuid::Uuid::new_v4().to_string(),
26 Command:Command.into(),
27 Payload:serde_json::Value::Null,
28 Timestamp:chrono::Utc::now().timestamp_millis() as u64,
29 CorrelationId:None,
30 Priority:MessagePriority::Enum::Normal,
31 }
32 }
33
34 pub fn WithPayload(mut self, Payload:serde_json::Value) -> Self {
35 self.Payload = Payload;
36 self
37 }
38
39 pub fn WithCorrelationId(mut self, CorrelationId:impl Into<String>) -> Self {
40 self.CorrelationId = Some(CorrelationId.into());
41 self
42 }
43
44 pub fn WithPriority(mut self, Priority:MessagePriority::Enum) -> Self {
45 self.Priority = Priority;
46 self
47 }
48}