1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::io;

use crate::pdu::data::bind_resp_data::BindRespData;
use crate::pdu::formats::WriteStream;
use crate::pdu::PduParseError;

#[derive(Debug, PartialEq)]
pub struct BindTransceiverRespPdu(pub BindRespData);

impl BindTransceiverRespPdu {
    pub fn new(system_id: &str) -> Result<Self, PduParseError> {
        Ok(Self(BindRespData::new(system_id)?))
    }

    pub fn new_error() -> Self {
        Self(BindRespData::new_error())
    }

    pub async fn write(&self, stream: &mut WriteStream) -> io::Result<()> {
        self.0.write(stream).await
    }

    pub fn parse(
        bytes: &mut dyn io::BufRead,
        command_status: u32,
    ) -> Result<Self, PduParseError> {
        Ok(Self(BindRespData::parse(bytes, command_status)?))
    }

    pub fn validate_command_status(
        self,
        command_status: u32,
    ) -> Result<Self, PduParseError> {
        Ok(Self(self.0.validate_command_status(command_status)?))
    }
}