mx_message/
mx_envelope.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
7#[serde(rename = "Envelope")]
8pub struct MxEnvelope<H, D> {
9 #[serde(rename = "@xmlns", skip_serializing_if = "Option::is_none")]
11 pub xmlns: Option<String>,
12
13 #[serde(rename = "@xmlns:xsi", skip_serializing_if = "Option::is_none")]
14 pub xmlns_xsi: Option<String>,
15
16 #[serde(rename = "AppHdr")]
18 pub app_hdr: H,
19
20 #[serde(rename = "Document")]
22 pub document: MxDocument<D>,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
27pub struct MxDocument<D> {
28 #[serde(rename = "@xmlns", skip_serializing_if = "Option::is_none")]
30 pub xmlns: Option<String>,
31
32 #[serde(flatten)]
34 pub message: D,
35}
36
37impl<H, D> MxEnvelope<H, D> {
38 pub fn new(app_hdr: H, document: D, document_namespace: String) -> Self {
40 Self {
41 xmlns: Some("urn:iso:std:iso:20022:tech:xsd:head.001.001.02".to_string()),
42 xmlns_xsi: Some("http://www.w3.org/2001/XMLSchema-instance".to_string()),
43 app_hdr,
44 document: MxDocument {
45 xmlns: Some(document_namespace),
46 message: document,
47 },
48 }
49 }
50
51 pub fn new_pacs008(app_hdr: H, document: D) -> Self {
53 Self::new(
54 app_hdr,
55 document,
56 "urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08".to_string(),
57 )
58 }
59
60 pub fn new_pacs009(app_hdr: H, document: D) -> Self {
62 Self::new(
63 app_hdr,
64 document,
65 "urn:iso:std:iso:20022:tech:xsd:pacs.009.001.08".to_string(),
66 )
67 }
68
69 pub fn new_pain001(app_hdr: H, document: D) -> Self {
71 Self::new(
72 app_hdr,
73 document,
74 "urn:iso:std:iso:20022:tech:xsd:pain.001.001.09".to_string(),
75 )
76 }
77
78 pub fn new_camt052(app_hdr: H, document: D) -> Self {
80 Self::new(
81 app_hdr,
82 document,
83 "urn:iso:std:iso:20022:tech:xsd:camt.052.001.08".to_string(),
84 )
85 }
86
87 pub fn new_camt053(app_hdr: H, document: D) -> Self {
89 Self::new(
90 app_hdr,
91 document,
92 "urn:iso:std:iso:20022:tech:xsd:camt.053.001.08".to_string(),
93 )
94 }
95}