dis_rs/common/detonation/
writer.rs

1use crate::common::detonation::model::Detonation;
2use crate::common::{Serialize, SerializePdu, SupportedVersion};
3use bytes::{BufMut, BytesMut};
4
5impl SerializePdu for Detonation {
6    fn serialize_pdu(&self, _version: SupportedVersion, buf: &mut BytesMut) -> u16 {
7        let source_entity_id_bytes = self.source_entity_id.serialize(buf);
8        let target_entity_id_bytes = self.target_entity_id.serialize(buf);
9        let exploding_entity_id_bytes = self.exploding_entity_id.serialize(buf);
10        let event_id_bytes = self.event_id.serialize(buf);
11        let velocity_bytes = self.velocity.serialize(buf);
12        let world_location_bytes = self.location_in_world_coordinates.serialize(buf);
13        let descriptor_bytes = self.descriptor.serialize(buf);
14        let entity_location_bytes = self.location_in_entity_coordinates.serialize(buf);
15        buf.put_u8(self.detonation_result.into());
16        buf.put_u8(self.variable_parameters.len() as u8);
17        buf.put_u16(0u16);
18        let variable_params_bytes: u16 = self
19            .variable_parameters
20            .iter()
21            .map(|param| param.serialize(buf))
22            .sum();
23
24        source_entity_id_bytes
25            + target_entity_id_bytes
26            + exploding_entity_id_bytes
27            + event_id_bytes
28            + velocity_bytes
29            + world_location_bytes
30            + descriptor_bytes
31            + entity_location_bytes
32            + 4
33            + variable_params_bytes
34    }
35}