use bacnet_types::error::RemoteError;
use super::{AbortPdu, Apdu, ErrorPdu, RejectPdu};
impl ErrorPdu {
#[must_use]
pub const fn remote_error(&self) -> RemoteError {
RemoteError::Error {
class: self.error_class,
code: self.error_code,
}
}
}
impl RejectPdu {
#[must_use]
pub const fn remote_error(&self) -> RemoteError {
RemoteError::Reject {
reason: self.reject_reason,
}
}
}
impl AbortPdu {
#[must_use]
pub const fn remote_error(&self) -> RemoteError {
RemoteError::Abort {
reason: self.abort_reason,
}
}
}
impl Apdu {
#[must_use]
pub const fn remote_error(&self) -> Option<RemoteError> {
match self {
Self::Error(pdu) => Some(pdu.remote_error()),
Self::Reject(pdu) => Some(pdu.remote_error()),
Self::Abort(pdu) => Some(pdu.remote_error()),
Self::ConfirmedRequest(_)
| Self::UnconfirmedRequest(_)
| Self::SimpleAck(_)
| Self::ComplexAck(_)
| Self::SegmentAck(_) => None,
}
}
}