Skip to main content

Mountain/IPC/Common/MessageType/
IPCMessage.rs

1
2//! Standard IPC message: identifier, command name, JSON payload,
3//! creation timestamp, optional correlation ID, and a priority. Built
4//! through `new` and the `WithPayload` / `WithCorrelationId` /
5//! `WithPriority` builder shims.
6
7use serde::{Deserialize, Serialize};
8
9use crate::IPC::Common::MessageType::MessagePriority;
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct Struct {
13	pub Id:String,
14
15	pub Command:String,
16
17	pub Payload:serde_json::Value,
18
19	pub Timestamp:u64,
20
21	pub CorrelationId:Option<String>,
22
23	pub Priority:MessagePriority::Enum,
24}
25
26impl Struct {
27	pub fn new(Command:impl Into<String>) -> Self {
28		Self {
29			Id:uuid::Uuid::new_v4().to_string(),
30
31			Command:Command.into(),
32
33			Payload:serde_json::Value::Null,
34
35			Timestamp:chrono::Utc::now().timestamp_millis() as u64,
36
37			CorrelationId:None,
38
39			Priority:MessagePriority::Enum::Normal,
40		}
41	}
42
43	pub fn WithPayload(mut self, Payload:serde_json::Value) -> Self {
44		self.Payload = Payload;
45
46		self
47	}
48
49	pub fn WithCorrelationId(mut self, CorrelationId:impl Into<String>) -> Self {
50		self.CorrelationId = Some(CorrelationId.into());
51
52		self
53	}
54
55	pub fn WithPriority(mut self, Priority:MessagePriority::Enum) -> Self {
56		self.Priority = Priority;
57
58		self
59	}
60}