feat: rust proto implementation
This commit is contained in:
parent
1e68840042
commit
e4b508ae86
12 changed files with 381 additions and 0 deletions
45
domo_proto/src/packet/identifier.rs
Normal file
45
domo_proto/src/packet/identifier.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use std::fmt::{Formatter, LowerHex};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Identifier {
|
||||
pub bytes: [u8; 4],
|
||||
}
|
||||
|
||||
impl LowerHex for Identifier {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{:x}{:x}{:x}{:x}",
|
||||
self.bytes[0], self.bytes[1], self.bytes[2], self.bytes[3]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&[u8]> for Identifier {
|
||||
fn from(value: &[u8]) -> Self {
|
||||
let mut bytes = [0_u8; 4];
|
||||
bytes[..value.len()].copy_from_slice(value);
|
||||
Identifier {
|
||||
bytes: [bytes[0], bytes[1], bytes[2], bytes[3]],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<u8>> for Identifier {
|
||||
fn from(value: Vec<u8>) -> Self {
|
||||
Identifier::from(value.as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for Identifier {
|
||||
fn from(value: u32) -> Self {
|
||||
Identifier {
|
||||
bytes: [
|
||||
(value >> 24) as u8,
|
||||
(value >> 16) as u8,
|
||||
(value >> 8) as u8,
|
||||
(value >> 0) as u8,
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue