rusmpp_core/pdus/owned/
outbind.rs1use rusmpp_macros::Rusmpp;
2
3use crate::{pdus::owned::Pdu, types::owned::COctetString};
4
5#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Rusmpp)]
12#[rusmpp(decode = owned, test = skip)]
13#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
14#[cfg_attr(feature = "serde", derive(::serde::Serialize))]
15#[cfg_attr(feature = "serde-deserialize-unchecked", derive(::serde::Deserialize))]
16pub struct Outbind {
17 pub system_id: COctetString<1, 16>,
21 pub password: COctetString<1, 9>,
26}
27
28impl Outbind {
29 pub fn new(system_id: COctetString<1, 16>, password: COctetString<1, 9>) -> Self {
30 Self {
31 system_id,
32 password,
33 }
34 }
35
36 pub fn builder() -> OutbindBuilder {
37 OutbindBuilder::new()
38 }
39}
40
41impl From<Outbind> for Pdu {
42 fn from(value: Outbind) -> Self {
43 Self::Outbind(value)
44 }
45}
46
47#[derive(Debug, Default)]
48pub struct OutbindBuilder {
49 inner: Outbind,
50}
51
52impl OutbindBuilder {
53 pub fn new() -> Self {
54 Self::default()
55 }
56
57 pub fn system_id(mut self, system_id: COctetString<1, 16>) -> Self {
58 self.inner.system_id = system_id;
59 self
60 }
61
62 pub fn password(mut self, password: COctetString<1, 9>) -> Self {
63 self.inner.password = password;
64 self
65 }
66
67 pub fn build(self) -> Outbind {
68 self.inner
69 }
70}
71
72#[cfg(test)]
73mod tests {
74 use std::str::FromStr;
75
76 use crate::tests::TestInstance;
77
78 use super::*;
79
80 impl TestInstance for Outbind {
81 fn instances() -> alloc::vec::Vec<Self> {
82 alloc::vec![
83 Self::default(),
84 Self::builder()
85 .system_id(COctetString::from_str("system_id").unwrap())
86 .password(COctetString::from_str("password").unwrap())
87 .build(),
88 ]
89 }
90 }
91
92 #[test]
93 fn encode_decode() {
94 crate::tests::owned::encode_decode_test_instances::<Outbind>();
95 }
96}