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