vmi_utils/bridge/
packet.rs

1/// Bridge packet.
2#[derive(Debug, Default, Clone, Copy)]
3pub struct BridgePacket {
4    magic: u32,
5    request: u16,
6    method: u16,
7    value1: u64,
8    value2: u64,
9    value3: u64,
10    value4: u64,
11}
12
13impl BridgePacket {
14    /// Creates a new packet with the given request and method.
15    pub fn new(magic: u32, request: u16, method: u16) -> Self {
16        Self {
17            magic,
18            request,
19            method,
20            value1: 0,
21            value2: 0,
22            value3: 0,
23            value4: 0,
24        }
25    }
26
27    /// Sets the first value of the packet.
28    pub fn with_value1(self, value1: u64) -> Self {
29        Self { value1, ..self }
30    }
31
32    /// Sets the second value of the packet.
33    pub fn with_value2(self, value2: u64) -> Self {
34        Self { value2, ..self }
35    }
36
37    /// Sets the third value of the packet.
38    pub fn with_value3(self, value3: u64) -> Self {
39        Self { value3, ..self }
40    }
41
42    /// Sets the fourth value of the packet.
43    pub fn with_value4(self, value4: u64) -> Self {
44        Self { value4, ..self }
45    }
46
47    /// Returns the magic number of the packet.
48    pub fn magic(&self) -> u32 {
49        self.magic
50    }
51
52    /// Returns the request of the packet.
53    pub fn request(&self) -> u16 {
54        self.request
55    }
56
57    /// Returns the method of the packet.
58    pub fn method(&self) -> u16 {
59        self.method
60    }
61
62    /// Returns the first value of the packet.
63    pub fn value1(&self) -> u64 {
64        self.value1
65    }
66
67    /// Returns the second value of the packet.
68    pub fn value2(&self) -> u64 {
69        self.value2
70    }
71
72    /// Returns the third value of the packet.
73    pub fn value3(&self) -> u64 {
74        self.value3
75    }
76
77    /// Returns the fourth value of the packet.
78    pub fn value4(&self) -> u64 {
79        self.value4
80    }
81}