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::detonation::model::{Detonation, DetonationDescriptor};
use crate::common::{Serialize, SerializePdu, SupportedVersion};
use bytes::{BufMut, BytesMut};

impl SerializePdu for Detonation {
    fn serialize_pdu(&self, _version: SupportedVersion, buf: &mut BytesMut) -> u16 {
        let source_entity_id_bytes = self.source_entity_id.serialize(buf);
        let target_entity_id_bytes = self.target_entity_id.serialize(buf);
        let exploding_entity_id_bytes = self.exploding_entity_id.serialize(buf);
        let event_id_bytes = self.event_id.serialize(buf);
        let velocity_bytes = self.velocity.serialize(buf);
        let world_location_bytes = self.location_in_world_coordinates.serialize(buf);
        let descriptor_bytes = self.descriptor.serialize(buf);
        let entity_location_bytes = self.location_in_entity_coordinates.serialize(buf);
        buf.put_u8(self.detonation_result.into());
        buf.put_u8(self.variable_parameters.len() as u8);
        buf.put_u16(0u16);
        let variable_params_bytes: u16 = self
            .variable_parameters
            .iter()
            .map(|param| param.serialize(buf))
            .sum();

        source_entity_id_bytes
            + target_entity_id_bytes
            + exploding_entity_id_bytes
            + event_id_bytes
            + velocity_bytes
            + world_location_bytes
            + descriptor_bytes
            + entity_location_bytes
            + 4
            + variable_params_bytes
    }
}

impl Serialize for DetonationDescriptor {
    fn serialize(&self, buf: &mut BytesMut) -> u16 {
        match self {
            Self::Munition(munition) => munition.serialize(buf),
            Self::Explosion(explosion) => explosion.serialize(buf),
            Self::Expendable(expendable) => expendable.serialize(buf),
        }
    }
}