feat: add packet_id() to Packet enum

This commit is contained in:
Strix 2023-10-15 18:06:23 +02:00
parent 506d07ed8d
commit fc5cbdb361
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774
2 changed files with 18 additions and 2 deletions

View file

@ -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!(

View file

@ -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 {