rusmpp_core/pdus/borrowed/
query_sm.rs

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