use crate::common::model::{EntityId, PduBody};
use crate::common::other::builder::OtherBuilder;
use crate::common::{BodyInfo, Interaction};
use crate::enumerations::PduType;
use crate::BodyRaw;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Other {
pub originating_entity_id: Option<EntityId>,
pub receiving_entity_id: Option<EntityId>,
pub body: Vec<u8>,
}
impl BodyInfo for Other {
fn body_length(&self) -> u16 {
self.body.len() as u16
}
fn body_type(&self) -> PduType {
PduType::Other
}
}
impl BodyRaw for Other {
type Builder = OtherBuilder;
fn builder() -> Self::Builder {
Self::Builder::new()
}
fn into_builder(self) -> Self::Builder {
Self::Builder::new_from_body(self)
}
fn into_pdu_body(self) -> PduBody {
PduBody::Other(self)
}
}
impl Interaction for Other {
fn originator(&self) -> Option<&EntityId> {
if let Some(entity) = &self.originating_entity_id {
Some(entity)
} else {
None
}
}
fn receiver(&self) -> Option<&EntityId> {
if let Some(entity) = &self.receiving_entity_id {
Some(entity)
} else {
None
}
}
}