bnr_xfs/callback_response/
operation.rs1use std::fmt;
2
3use crate::{create_xfs_i4, impl_xfs_struct, xfs::OperationId};
4
5create_xfs_i4!(
6 OperationIdentificationId,
7 "identificationId",
8 "Represents the specific call instance for a particular callback operation."
9);
10
11#[repr(C)]
13#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
14pub struct CallbackOperationResponse {
15 operation_id: OperationId,
16 identification_id: OperationIdentificationId,
17}
18
19impl CallbackOperationResponse {
20 pub const fn new() -> Self {
22 Self {
23 operation_id: OperationId::new(),
24 identification_id: OperationIdentificationId::new(),
25 }
26 }
27
28 pub const fn create(operation_id: i32, identification_id: i32) -> Self {
30 Self {
31 operation_id: OperationId::create(operation_id as u32),
32 identification_id: OperationIdentificationId::create(identification_id as u32),
33 }
34 }
35
36 pub const fn operation_id(&self) -> u32 {
38 self.operation_id.inner()
39 }
40
41 pub fn set_operation_id(&mut self, val: i32) {
43 self.operation_id = OperationId::create(val as u32);
44 }
45
46 pub fn with_operation_id(mut self, val: i32) -> Self {
48 self.set_operation_id(val);
49 self
50 }
51
52 pub const fn identification_id(&self) -> u32 {
54 self.identification_id.inner()
55 }
56
57 pub fn set_identification_id(&mut self, val: i32) {
59 self.identification_id.set_inner(val as u32)
60 }
61
62 pub fn with_identification_id(mut self, val: i32) -> Self {
64 self.set_identification_id(val);
65 self
66 }
67}
68
69impl fmt::Display for CallbackOperationResponse {
70 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71 write!(f, "{{")?;
72 write!(f, r#""operation_id": {}, "#, self.operation_id())?;
73 write!(f, r#""identification_id": {}"#, self.identification_id())?;
74 write!(f, "}}")
75 }
76}
77
78impl_xfs_struct!(CallbackOperationResponse, "callbackResponse", [operation_id: OperationId, identification_id: OperationIdentificationId]);
79
80#[cfg(test)]
81mod tests {
82 use super::*;
83
84 use crate::xfs::{
85 self,
86 method_response::{XfsMethodResponse, XfsMethodResponseStruct},
87 params::XfsParam,
88 };
89 use crate::Result;
90
91 #[test]
92 fn test_callback_response_serde() -> Result<()> {
93 let exp_xml = r#"<?xml version="1.0" encoding="ISO-8859-1"?><methodResponse><params><param><value><struct><member><name>operationId</name><value><i4>6121</i4></value></member><member><name>identificationId</name><value><i4>4</i4></value></member></struct></value></param></params></methodResponse>"#;
94 let exp_res =
95 XfsMethodResponseStruct::new(XfsMethodResponse::new_params([XfsParam::create(
96 CallbackOperationResponse::create(6121, 4).into(),
97 )]));
98
99 assert_eq!(xfs::to_iso_string(&exp_res)?.as_str(), exp_xml);
100 assert_eq!(xfs::from_str::<XfsMethodResponseStruct>(exp_xml)?, exp_res);
101
102 Ok(())
103 }
104}