refactor: breaking refactor of domo_proto and domo_node
This commit is contained in:
parent
be4425aff9
commit
15971aa4fa
31 changed files with 902 additions and 393 deletions
|
|
@ -1,68 +0,0 @@
|
|||
use std::fmt::{Display, Formatter, LowerHex};
|
||||
use rand::random;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
||||
pub struct Identifier {
|
||||
pub bytes: [u8; 4],
|
||||
}
|
||||
|
||||
impl Identifier {
|
||||
pub fn random() -> Identifier {
|
||||
Identifier::from(random::<u32>())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Identifier {
|
||||
fn default() -> Self {
|
||||
Identifier::from(0x00000000)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Identifier {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"0x{:x}{:x}{:x}{:x}",
|
||||
self.bytes[0], self.bytes[1], self.bytes[2], self.bytes[3]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
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[..4].copy_from_slice(value[..4].as_ref());
|
||||
Identifier {
|
||||
bytes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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