dis_rs/common/create_entity_r/
model.rs

1use crate::common::model::{EntityId, PduBody};
2use crate::common::{BodyInfo, Interaction};
3use crate::create_entity_r::builder::CreateEntityRBuilder;
4use crate::enumerations::{PduType, RequiredReliabilityService};
5#[cfg(feature = "serde")]
6use serde::{Deserialize, Serialize};
7
8const CREATE_ENTITY_R_BODY_LENGTH: u16 = 20;
9
10/// 5.12.4.2 Create Entity-R PDU
11///
12/// 7.11.2 Create Entity-R PDU
13#[derive(Clone, Debug, Default, PartialEq)]
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15pub struct CreateEntityR {
16    pub originating_id: EntityId,
17    pub receiving_id: EntityId,
18    pub required_reliability_service: RequiredReliabilityService,
19    pub request_id: u32,
20}
21
22impl CreateEntityR {
23    #[must_use]
24    pub fn builder() -> CreateEntityRBuilder {
25        CreateEntityRBuilder::new()
26    }
27
28    #[must_use]
29    pub fn into_builder(self) -> CreateEntityRBuilder {
30        CreateEntityRBuilder::new_from_body(self)
31    }
32
33    #[must_use]
34    pub fn into_pdu_body(self) -> PduBody {
35        PduBody::CreateEntityR(self)
36    }
37}
38
39impl BodyInfo for CreateEntityR {
40    fn body_length(&self) -> u16 {
41        CREATE_ENTITY_R_BODY_LENGTH
42    }
43
44    fn body_type(&self) -> PduType {
45        PduType::CreateEntityR
46    }
47}
48
49impl Interaction for CreateEntityR {
50    fn originator(&self) -> Option<&EntityId> {
51        Some(&self.originating_id)
52    }
53
54    fn receiver(&self) -> Option<&EntityId> {
55        Some(&self.receiving_id)
56    }
57}