rusmpp_core/values/sub_address/
borrowed.rs

1use rusmpp_macros::Rusmpp;
2
3use crate::{types::borrowed::OctetString, values::sub_address::SubaddressTag};
4
5// https://smpp.org/SMPP_v5.pdf#page=165
6#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Rusmpp)]
7#[rusmpp(decode = borrowed)]
8#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
9#[cfg_attr(feature = "serde", derive(::serde::Serialize))]
10pub struct Subaddress<'a> {
11    pub tag: SubaddressTag,
12    // addr can not be empty, because the whole source_subaddress tlv value is between 2 and 23 bytes long, and the tag is 1 byte long
13    #[rusmpp(length = "unchecked")]
14    pub addr: OctetString<'a, 1, 22>,
15}
16
17impl<'a> Subaddress<'a> {
18    pub fn new(tag: SubaddressTag, addr: OctetString<'a, 1, 22>) -> Self {
19        Self { tag, addr }
20    }
21}
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26
27    #[test]
28    fn encode_decode() {
29        crate::tests::borrowed::encode_decode_with_length_test_instances::<Subaddress>();
30    }
31}