Skip to main content

Mountain/IPC/Common/MessageType/
IPCResponse.rs

1
2//! IPC response: correlation ID, payload, success flag, optional error
3//! string, and timestamp. Built through `Success` / `Error` constructors
4//! that stamp the timestamp from the chrono UTC clock.
5
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Struct {
10	pub CorrelationId:String,
11
12	pub Data:serde_json::Value,
13
14	pub Success:bool,
15
16	pub Error:Option<String>,
17
18	pub Timestamp:u64,
19}
20
21impl Struct {
22	pub fn Success(CorrelationId:impl Into<String>, Data:serde_json::Value) -> Self {
23		Self {
24			CorrelationId:CorrelationId.into(),
25
26			Data,
27
28			Success:true,
29
30			Error:None,
31
32			Timestamp:chrono::Utc::now().timestamp_millis() as u64,
33		}
34	}
35
36	pub fn Error(CorrelationId:impl Into<String>, Error:impl Into<String>) -> Self {
37		Self {
38			CorrelationId:CorrelationId.into(),
39
40			Data:serde_json::Value::Null,
41
42			Success:false,
43
44			Error:Some(Error.into()),
45
46			Timestamp:chrono::Utc::now().timestamp_millis() as u64,
47		}
48	}
49}