open_dis_rust/common/
entity_id.rs1use super::simulation_address::SimulationAddress;
8use bytes::{Buf, BufMut, BytesMut};
9
10#[derive(Copy, Clone, Debug, Default, PartialEq)]
11pub struct EntityId {
13 pub simulation_address: SimulationAddress,
15 pub entity_id: u16,
17}
18
19impl EntityId {
20 #[must_use]
21 pub fn new(site_id: u16, application_id: u16, entity_id: u16) -> Self {
22 EntityId {
23 simulation_address: SimulationAddress::new(site_id, application_id),
24 entity_id,
25 }
26 }
27
28 #[must_use]
29 pub fn default(entity_id: u16) -> Self {
30 EntityId {
31 simulation_address: SimulationAddress::default(),
32 entity_id,
33 }
34 }
35
36 pub fn serialize(&self, buf: &mut BytesMut) {
37 self.simulation_address.serialize(buf);
38 buf.put_u16(self.entity_id);
39 }
40
41 pub fn deserialize(buf: &mut BytesMut) -> EntityId {
42 EntityId {
43 simulation_address: EntityId::deserialize_simulation_address(buf),
44 entity_id: buf.get_u16(),
45 }
46 }
47
48 fn deserialize_simulation_address(buf: &mut BytesMut) -> SimulationAddress {
49 SimulationAddress {
50 site_id: buf.get_u16(),
51 application_id: buf.get_u16(),
52 }
53 }
54}