dis_rs/common/other/
model.rs1use crate::common::model::{EntityId, PduBody};
2use crate::common::other::builder::OtherBuilder;
3use crate::common::{BodyInfo, Interaction};
4use crate::enumerations::PduType;
5#[cfg(feature = "serde")]
6use serde::{Deserialize, Serialize};
7
8#[derive(Clone, Debug, Default, PartialEq)]
16#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
17pub struct Other {
18 pub originating_entity_id: Option<EntityId>,
19 pub receiving_entity_id: Option<EntityId>,
20 pub body: Vec<u8>,
21}
22
23impl BodyInfo for Other {
24 fn body_length(&self) -> u16 {
25 self.body.len() as u16
26 }
27
28 fn body_type(&self) -> PduType {
29 PduType::Other
30 }
31}
32
33impl Other {
34 #[must_use]
35 pub fn builder() -> OtherBuilder {
36 OtherBuilder::new()
37 }
38
39 #[must_use]
40 pub fn into_builder(self) -> OtherBuilder {
41 OtherBuilder::new_from_body(self)
42 }
43
44 #[must_use]
45 pub fn into_pdu_body(self) -> PduBody {
46 PduBody::Other(self)
47 }
48}
49
50impl Interaction for Other {
51 fn originator(&self) -> Option<&EntityId> {
52 if let Some(entity) = &self.originating_entity_id {
53 Some(entity)
54 } else {
55 None
56 }
57 }
58
59 fn receiver(&self) -> Option<&EntityId> {
60 if let Some(entity) = &self.receiving_entity_id {
61 Some(entity)
62 } else {
63 None
64 }
65 }
66}