use rusmpp_macros::Rusmpp;
use crate::{pdus::owned::Pdu, types::owned::COctetString};
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Rusmpp)]
#[rusmpp(decode = owned, test = skip)]
#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
#[cfg_attr(feature = "serde", derive(::serde::Serialize))]
#[cfg_attr(feature = "serde-deserialize-unchecked", derive(::serde::Deserialize))]
pub struct Outbind {
pub system_id: COctetString<1, 16>,
pub password: COctetString<1, 9>,
}
impl Outbind {
pub fn new(system_id: COctetString<1, 16>, password: COctetString<1, 9>) -> Self {
Self {
system_id,
password,
}
}
pub fn builder() -> OutbindBuilder {
OutbindBuilder::new()
}
}
impl From<Outbind> for Pdu {
fn from(value: Outbind) -> Self {
Self::Outbind(value)
}
}
#[derive(Debug, Default)]
pub struct OutbindBuilder {
inner: Outbind,
}
impl OutbindBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn system_id(mut self, system_id: COctetString<1, 16>) -> Self {
self.inner.system_id = system_id;
self
}
pub fn password(mut self, password: COctetString<1, 9>) -> Self {
self.inner.password = password;
self
}
pub fn build(self) -> Outbind {
self.inner
}
}
#[cfg(test)]
mod tests {
use std::str::FromStr;
use crate::tests::TestInstance;
use super::*;
impl TestInstance for Outbind {
fn instances() -> alloc::vec::Vec<Self> {
alloc::vec![
Self::default(),
Self::builder()
.system_id(COctetString::from_str("system_id").unwrap())
.password(COctetString::from_str("password").unwrap())
.build(),
]
}
}
#[test]
fn encode_decode() {
crate::tests::owned::encode_decode_test_instances::<Outbind>();
}
}