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	pub Data:serde_json::Value,
13	pub Success:bool,
14	pub Error:Option<String>,
15	pub Timestamp:u64,
16}
17
18impl Struct {
19	pub fn Success(CorrelationId:impl Into<String>, Data:serde_json::Value) -> Self {
20		Self {
21			CorrelationId:CorrelationId.into(),
22			Data,
23			Success:true,
24			Error:None,
25			Timestamp:chrono::Utc::now().timestamp_millis() as u64,
26		}
27	}
28
29	pub fn Error(CorrelationId:impl Into<String>, Error:impl Into<String>) -> Self {
30		Self {
31			CorrelationId:CorrelationId.into(),
32			Data:serde_json::Value::Null,
33			Success:false,
34			Error:Some(Error.into()),
35			Timestamp:chrono::Utc::now().timestamp_millis() as u64,
36		}
37	}
38}