dis_rs/common/stop_freeze/
model.rs

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::common::model::{ClockTime, EntityId, PduBody};
use crate::common::{BodyInfo, Interaction};
use crate::enumerations::{PduType, StopFreezeFrozenBehavior, StopFreezeReason};
use crate::stop_freeze::builder::StopFreezeBuilder;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

const STOP_FREEZE_BODY_LENGTH: u16 = 28;

/// 5.6.5.5 Stop/Freeze PDU
///
/// 7.5.5 Stop/Freeze PDU
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct StopFreeze {
    pub originating_id: EntityId,
    pub receiving_id: EntityId,
    pub real_world_time: ClockTime,
    pub reason: StopFreezeReason,
    pub frozen_behavior: StopFreezeFrozenBehavior,
    pub request_id: u32,
}

impl StopFreeze {
    #[must_use]
    pub fn builder() -> StopFreezeBuilder {
        StopFreezeBuilder::new()
    }

    #[must_use]
    pub fn into_builder(self) -> StopFreezeBuilder {
        StopFreezeBuilder::new_from_body(self)
    }

    #[must_use]
    pub fn into_pdu_body(self) -> PduBody {
        PduBody::StopFreeze(self)
    }
}

impl BodyInfo for StopFreeze {
    fn body_length(&self) -> u16 {
        STOP_FREEZE_BODY_LENGTH
    }

    fn body_type(&self) -> PduType {
        PduType::StopFreeze
    }
}

impl Interaction for StopFreeze {
    fn originator(&self) -> Option<&EntityId> {
        Some(&self.originating_id)
    }

    fn receiver(&self) -> Option<&EntityId> {
        Some(&self.receiving_id)
    }
}