dis-rs 0.13.0

An implementation of the Distributed Interactive Simulation protocol (IEEE-1278.1) in Rust. This main crate contains PDU implementations and facilities to read/write PDUs from Rust data structures to the wire format and vice versa. It supports versions 6 and 7 of the protocol.
Documentation
use crate::common::model::{EntityId, PduBody};
use crate::common::{BodyInfo, Interaction};
use crate::enumerations::PduType;
use crate::model::{SupplyQuantity, SUPPLY_QUANTITY_RECORD_LENGTH};
use crate::resupply_offer::builder::ResupplyOfferBuilder;
use crate::BodyRaw;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

const RESUPPLY_OFFER_BASE_BODY_LENGTH: u16 = 16;

/// 5.5.6 Resupply Offer PDU
///
/// 7.4.3 Resupply Offer PDU
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ResupplyOffer {
    pub requesting_id: EntityId,
    pub servicing_id: EntityId,
    pub supplies: Vec<SupplyQuantity>,
}

impl BodyRaw for ResupplyOffer {
    type Builder = ResupplyOfferBuilder;

    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::ResupplyOffer(self)
    }
}

impl BodyInfo for ResupplyOffer {
    fn body_length(&self) -> u16 {
        RESUPPLY_OFFER_BASE_BODY_LENGTH
            + (self.supplies.len() as u16 * SUPPLY_QUANTITY_RECORD_LENGTH)
    }

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

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

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