1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//     open-dis-rust - Rust implementation of the IEEE-1278.1 Distributed Interactive Simulation
//     Copyright (C) 2023 Cameron Howell
//
//     Licensed under the BSD-2-Clause License

use bytes::{Buf, BufMut, BytesMut};

#[derive(Clone, Debug)]
pub struct RadioEntityType {
    pub entity_kind: u8,
    pub domain: u8,
    pub country: u16,
    pub category: u8,
    pub nomenclature_version: u8,
    pub nomenclature: u16,
}

impl Default for RadioEntityType {
    fn default() -> Self {
        RadioEntityType {
            entity_kind: 0,
            domain: 0,
            country: 0,
            category: 0,
            nomenclature_version: 0,
            nomenclature: 0,
        }
    }
}

impl RadioEntityType {
    pub fn new(
        entity_kind: u8,
        domain: u8,
        country: u16,
        category: u8,
        nomenclature_version: u8,
        nomenclature: u16,
    ) -> Self {
        RadioEntityType {
            entity_kind,
            domain,
            country,
            category,
            nomenclature_version,
            nomenclature,
        }
    }

    pub fn serialize(&self, buf: &mut BytesMut) {
        buf.put_u8(self.entity_kind);
        buf.put_u8(self.domain);
        buf.put_u16(self.country);
        buf.put_u8(self.category);
        buf.put_u8(self.nomenclature_version);
        buf.put_u16(self.nomenclature);
    }

    pub fn decode(buf: &mut BytesMut) -> RadioEntityType {
        RadioEntityType {
            entity_kind: buf.get_u8(),
            domain: buf.get_u8(),
            country: buf.get_u16(),
            category: buf.get_u8(),
            nomenclature_version: buf.get_u8(),
            nomenclature: buf.get_u16(),
        }
    }
}