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
use bytes::{BytesMut, BufMut, Buf};
#[derive(Copy, Clone, Debug, Default)]
pub struct EntityCapabilitiesRecord {
pub ammunition_supply_field: bool,
pub fuel_supply_field: bool,
pub recovery_field: bool,
pub repair_field: bool,
}
impl EntityCapabilitiesRecord {
pub fn new(
ammunition_supply_field: bool,
fuel_supply_field: bool,
recovery_field: bool,
repair_field: bool,) -> Self {
EntityCapabilitiesRecord {
ammunition_supply_field,
fuel_supply_field,
recovery_field,
repair_field,
}
}
pub fn default() -> Self {
EntityCapabilitiesRecord {
ammunition_supply_field: false,
fuel_supply_field: false,
recovery_field: false,
repair_field: false,
}
}
pub fn serialize(&self, buf: &mut BytesMut) {
let ammunition_supply = if self.ammunition_supply_field { 1u32 } else { 0u32 } << 31;
let fuel_supply = if self.fuel_supply_field { 1u32 } else { 0u32 } << 30;
let recovery = if self.recovery_field { 1u32 } else { 0u32 } << 29;
let repair = if self.repair_field { 1u32 } else { 0u32 } << 28;
let capabilities = 0u32 | ammunition_supply | fuel_supply | recovery | repair;
buf.put_u32(capabilities);
}
pub fn decode(buf: &mut BytesMut) -> EntityCapabilitiesRecord {
let bytes = buf.get_u32();
EntityCapabilitiesRecord {
ammunition_supply_field: (bytes >> 1) != 0,
fuel_supply_field: (bytes >> 1) != 0,
recovery_field: (bytes >> 1) != 0,
repair_field: (bytes >> 1) != 0,
}
}
}