dis_rust/entity_information/
entity_marking_record.rs1use bytes::{BytesMut, BufMut, Buf};
10
11#[derive(Clone, Debug,)]
12pub struct EntityMarkingRecord {
14 pub entity_marking_character_set_field: EntityMarkingCharacterSet,
15 pub entity_marking_string_record: String,
16}
17
18impl EntityMarkingRecord {
19 pub fn new(
21 entity_marking_character_set_field: EntityMarkingCharacterSet,
22 entity_marking_string_record: String,) -> Self {
23 EntityMarkingRecord {
24 entity_marking_character_set_field,
25 entity_marking_string_record
26 }
27 }
28
29 pub fn default(marking: String) -> Self {
41 EntityMarkingRecord {
42 entity_marking_character_set_field: EntityMarkingCharacterSet::ASCII,
43 entity_marking_string_record: marking
44 }
45 }
46
47 pub fn serialize(&self, buf: &mut BytesMut) {
50 buf.put_u8(self.entity_marking_character_set_field as u8);
51 let marking = self.entity_marking_string_record.clone();
52 buf.put_slice(&marking.into_bytes()[..]);
53 }
54
55 pub fn decode(buf: &mut BytesMut) -> EntityMarkingRecord {
56 EntityMarkingRecord {
57 entity_marking_character_set_field: EntityMarkingCharacterSet::from_u8(buf.get_u8()),
58 entity_marking_string_record: "".to_string(),
59 }
60 }
61}
62
63#[derive(Debug, Clone, Copy)]
64pub enum EntityMarkingCharacterSet {
66 Unused = 0,
67 ASCII = 1,
68 ArmyMarking = 2,
69 DigitChevron = 3,
70}
71
72impl EntityMarkingCharacterSet {
73 pub fn from_u8(bit: u8) -> EntityMarkingCharacterSet {
74 match bit {
75 0 => EntityMarkingCharacterSet::Unused,
76 1 => EntityMarkingCharacterSet::ASCII,
77 2 => EntityMarkingCharacterSet::ArmyMarking,
78 3 => EntityMarkingCharacterSet::DigitChevron,
79 4_u8..=u8::MAX => EntityMarkingCharacterSet::Unused
80 }
81 }
82}