rusmpp_core/pdus/owned/
query_sm.rs

1use rusmpp_macros::Rusmpp;
2
3use crate::{pdus::owned::Pdu, types::owned::COctetString, values::*};
4
5/// This command is issued by the ESME to query the status of a previously submitted short
6/// message.
7/// The matching mechanism is based on the MC assigned message_id and source address.
8/// Where the original submit_sm, data_sm or submit_multi ‘source address’ was defaulted to
9/// NULL, then the source address in the query_sm command should also be set to NULL.
10#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Rusmpp)]
11#[rusmpp(decode = owned, test = skip)]
12#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
13#[cfg_attr(feature = "serde", derive(::serde::Serialize))]
14#[cfg_attr(feature = "serde-deserialize-unchecked", derive(::serde::Deserialize))]
15pub struct QuerySm {
16    /// Message ID of the message whose state
17    /// is to be queried. This must be the MC
18    /// assigned Message ID allocated to the
19    /// original short message when submitted
20    /// to the MC by the submit_sm, data_sm or
21    /// submit_multi command, and returned in
22    /// the response PDU by the MC.
23    pub message_id: COctetString<1, 65>,
24    /// Type of Number of message originator.
25    /// This is used for verification purposes,
26    /// and must match that supplied in the
27    /// original request PDU (e.g. submit_sm).
28    ///
29    /// If not known, set to NULL.
30    pub source_addr_ton: Ton,
31    /// Numbering Plan Identity of message
32    /// originator.
33    /// This is used for verification purposes,
34    /// and must match that supplied in the
35    /// original message submission request
36    /// PDU.
37    ///
38    /// If not known, set to NULL.
39    pub source_addr_npi: Npi,
40    /// Address of message originator.
41    /// This is used for verification purposes,
42    /// and must match that supplied in the
43    /// original request PDU (e.g. submit_sm).
44    ///
45    /// If not known, set to NULL.
46    pub source_addr: COctetString<1, 21>,
47}
48
49impl QuerySm {
50    pub fn new(
51        message_id: COctetString<1, 65>,
52        source_addr_ton: Ton,
53        source_addr_npi: Npi,
54        source_addr: COctetString<1, 21>,
55    ) -> Self {
56        Self {
57            message_id,
58            source_addr_ton,
59            source_addr_npi,
60            source_addr,
61        }
62    }
63
64    pub fn builder() -> QuerySmBuilder {
65        QuerySmBuilder::new()
66    }
67}
68
69impl From<QuerySm> for Pdu {
70    fn from(value: QuerySm) -> Self {
71        Self::QuerySm(value)
72    }
73}
74
75#[derive(Debug, Default)]
76pub struct QuerySmBuilder {
77    inner: QuerySm,
78}
79
80impl QuerySmBuilder {
81    pub fn new() -> Self {
82        Default::default()
83    }
84
85    pub fn message_id(mut self, message_id: COctetString<1, 65>) -> Self {
86        self.inner.message_id = message_id;
87        self
88    }
89
90    pub fn source_addr_ton(mut self, source_addr_ton: Ton) -> Self {
91        self.inner.source_addr_ton = source_addr_ton;
92        self
93    }
94
95    pub fn source_addr_npi(mut self, source_addr_npi: Npi) -> Self {
96        self.inner.source_addr_npi = source_addr_npi;
97        self
98    }
99
100    pub fn source_addr(mut self, source_addr: COctetString<1, 21>) -> Self {
101        self.inner.source_addr = source_addr;
102        self
103    }
104
105    pub fn build(self) -> QuerySm {
106        self.inner
107    }
108}
109
110#[cfg(test)]
111mod tests {
112    use std::str::FromStr;
113
114    use crate::tests::TestInstance;
115
116    use super::*;
117
118    impl TestInstance for QuerySm {
119        fn instances() -> alloc::vec::Vec<Self> {
120            alloc::vec![
121                Self::default(),
122                Self::builder()
123                    .message_id(COctetString::from_str("1234567890123456").unwrap())
124                    .source_addr_ton(Ton::International)
125                    .source_addr_npi(Npi::Isdn)
126                    .source_addr(COctetString::from_str("Source Addr").unwrap())
127                    .build(),
128            ]
129        }
130    }
131
132    #[test]
133    fn encode_decode() {
134        crate::tests::owned::encode_decode_test_instances::<QuerySm>();
135    }
136}