use bytes::{BytesMut, BufMut, Buf};
#[derive(Clone, Debug,)]
pub struct EntityMarkingRecord {
pub entity_marking_character_set_field: EntityMarkingCharacterSet,
pub entity_marking_string_record: String,
}
impl EntityMarkingRecord {
pub fn new(
entity_marking_character_set_field: EntityMarkingCharacterSet,
entity_marking_string_record: String,) -> Self {
EntityMarkingRecord {
entity_marking_character_set_field,
entity_marking_string_record
}
}
pub fn default(marking: String) -> Self {
EntityMarkingRecord {
entity_marking_character_set_field: EntityMarkingCharacterSet::ASCII,
entity_marking_string_record: marking
}
}
pub fn serialize(&self, buf: &mut BytesMut) {
buf.put_u8(self.entity_marking_character_set_field as u8);
let marking = self.entity_marking_string_record.clone();
buf.put_slice(&marking.into_bytes()[..]);
}
pub fn decode(buf: &mut BytesMut) -> EntityMarkingRecord {
EntityMarkingRecord {
entity_marking_character_set_field: EntityMarkingCharacterSet::from_u8(buf.get_u8()),
entity_marking_string_record: "".to_string(),
}
}
}
#[derive(Debug, Clone, Copy)]
pub enum EntityMarkingCharacterSet {
Unused = 0,
ASCII = 1,
ArmyMarking = 2,
DigitChevron = 3,
}
impl EntityMarkingCharacterSet {
pub fn from_u8(bit: u8) -> EntityMarkingCharacterSet {
match bit {
0 => EntityMarkingCharacterSet::Unused,
1 => EntityMarkingCharacterSet::ASCII,
2 => EntityMarkingCharacterSet::ArmyMarking,
3 => EntityMarkingCharacterSet::DigitChevron,
4_u8..=u8::MAX => EntityMarkingCharacterSet::Unused
}
}
}