dis_rs/common/resupply_received/
model.rs

1use crate::common::model::{EntityId, PduBody};
2use crate::common::{BodyInfo, Interaction};
3use crate::enumerations::PduType;
4use crate::model::{SupplyQuantity, SUPPLY_QUANTITY_RECORD_LENGTH};
5use crate::resupply_received::builder::ResupplyReceivedBuilder;
6#[cfg(feature = "serde")]
7use serde::{Deserialize, Serialize};
8
9const RESUPPLY_RECEIVED_BASE_BODY_LENGTH: u16 = 16;
10
11/// 5.5.7 Resupply Received PDU
12///
13/// 7.4.4 Resupply Received PDU
14#[derive(Clone, Debug, Default, PartialEq)]
15#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
16pub struct ResupplyReceived {
17    pub requesting_id: EntityId,
18    pub servicing_id: EntityId,
19    pub supplies: Vec<SupplyQuantity>,
20}
21
22impl ResupplyReceived {
23    #[must_use]
24    pub fn builder() -> ResupplyReceivedBuilder {
25        ResupplyReceivedBuilder::new()
26    }
27
28    #[must_use]
29    pub fn into_builder(self) -> ResupplyReceivedBuilder {
30        ResupplyReceivedBuilder::new_from_body(self)
31    }
32
33    #[must_use]
34    pub fn into_pdu_body(self) -> PduBody {
35        PduBody::ResupplyReceived(self)
36    }
37}
38
39impl BodyInfo for ResupplyReceived {
40    fn body_length(&self) -> u16 {
41        RESUPPLY_RECEIVED_BASE_BODY_LENGTH
42            + (self.supplies.len() as u16 * SUPPLY_QUANTITY_RECORD_LENGTH)
43    }
44
45    fn body_type(&self) -> PduType {
46        PduType::ResupplyReceived
47    }
48}
49
50impl Interaction for ResupplyReceived {
51    fn originator(&self) -> Option<&EntityId> {
52        Some(&self.requesting_id)
53    }
54
55    fn receiver(&self) -> Option<&EntityId> {
56        Some(&self.servicing_id)
57    }
58}