Skip to main content

Mountain/IPC/Common/MessageType/
IPCResponse.rs

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