feat: add packet_id() to Packet enum
This commit is contained in:
parent
506d07ed8d
commit
fc5cbdb361
2 changed files with 18 additions and 2 deletions
|
@ -1,10 +1,20 @@
|
|||
use std::fmt::{Formatter, LowerHex};
|
||||
use std::fmt::{Display, Formatter, LowerHex};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
||||
pub struct Identifier {
|
||||
pub bytes: [u8; 4],
|
||||
}
|
||||
|
||||
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!(
|
||||
|
|
|
@ -21,6 +21,12 @@ pub enum Packet {
|
|||
}
|
||||
|
||||
impl Packet {
|
||||
pub fn packet_id(&self) -> Identifier {
|
||||
match self {
|
||||
Packet::V1 { packet_id, ..} => packet_id.clone()
|
||||
}
|
||||
}
|
||||
|
||||
/// Build packet **without** CRC32
|
||||
pub fn build_base_packet(&self) -> Vec<u8> {
|
||||
match self {
|
||||
|
|
Loading…
Reference in a new issue