open_dis_rust/common/simulation_address.rs
1// open-dis-rust - Rust implementation of the IEEE 1278.1-2012 Distributed Interactive
2// Simulation (DIS) application protocol
3// Copyright (C) 2023 Cameron Howell
4//
5// Licensed under the BSD 2-Clause License
6
7use bytes::{Buf, BufMut, BytesMut};
8
9#[derive(Copy, Clone, Debug, PartialEq)]
10/// Implemented according to IEEE 1278.1-2012 ยง6.2.80
11pub struct SimulationAddress {
12 /// Identification number representing the site, which may be a facility,
13 /// installation, organizational unit, or a geographical location. Valid
14 /// site ID values range from 1 to 65,534
15 pub site_id: u16,
16 /// Identification number representing the software program that is used to
17 /// generate and process distributed simulation data. Valid application ID
18 /// values range from 1 to 65,534
19 pub application_id: u16,
20}
21
22impl Default for SimulationAddress {
23 fn default() -> Self {
24 SimulationAddress {
25 site_id: 1,
26 application_id: 1,
27 }
28 }
29}
30
31impl SimulationAddress {
32 #[must_use]
33 pub fn new(site_id: u16, application_id: u16) -> Self {
34 SimulationAddress {
35 site_id,
36 application_id,
37 }
38 }
39
40 pub fn serialize(&self, buf: &mut BytesMut) {
41 buf.put_u16(self.site_id);
42 buf.put_u16(self.application_id);
43 }
44
45 pub fn deserialize(buf: &mut BytesMut) -> SimulationAddress {
46 SimulationAddress {
47 site_id: buf.get_u16(),
48 application_id: buf.get_u16(),
49 }
50 }
51}