Skip to main content

Mountain/IPC/Common/MessageType/
IPCResponse.rs

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