air_interpreter_interface/
call_service_result.rs1use air_interpreter_sede::define_simple_representation;
18use air_interpreter_sede::derive_serialized_type;
19use air_interpreter_sede::MsgPackMultiformat;
20use air_interpreter_sede::Representation;
21use serde::Deserialize;
22use serde::Serialize;
23use serde_json::Value as JValue;
24use std::collections::HashMap;
25
26pub type CallResults = HashMap<String, CallServiceResult>;
29pub const CALL_SERVICE_SUCCESS: i32 = 0;
30
31pub type CallResultsFormat = MsgPackMultiformat;
32
33derive_serialized_type!(SerializedCallResults);
34
35define_simple_representation! {
36 CallResultsRepr,
37 CallResults,
38 CallResultsFormat,
39 SerializedCallResults
40}
41
42pub type CallResultsDeserializeError = <CallResultsRepr as Representation>::DeserializeError;
43pub type CallResultsSerializeError = <CallResultsRepr as Representation>::SerializeError;
44
45#[derive(Debug, Default, Clone, Serialize, Deserialize)]
47pub struct CallServiceResult {
48 pub ret_code: i32,
50
51 pub result: String,
54}
55
56impl CallServiceResult {
57 pub fn ok(result: &JValue) -> Self {
58 Self {
59 ret_code: CALL_SERVICE_SUCCESS,
60 result: result.to_string(),
62 }
63 }
64
65 pub fn err(err_code: i32, result: &JValue) -> Self {
66 Self {
67 ret_code: err_code,
68 result: result.to_string(),
69 }
70 }
71}
72
73use std::fmt;
74
75impl fmt::Display for CallServiceResult {
76 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
77 write!(f, "ret_code: {}, result: '{}'", self.ret_code, self.result)
78 }
79}