feat: add Identifier::random and some other tiny fixes

This commit is contained in:
Strix 2023-10-15 18:06:25 +02:00
parent f462630eb4
commit 405cf8b368
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774
8 changed files with 190 additions and 11 deletions

View file

@ -7,6 +7,7 @@ use identifier::Identifier;
use packet_data::PacketData;
use std::convert::TryFrom;
use std::fmt::Debug;
use std::io::Read;
#[derive(Debug)]
pub enum Packet {
@ -23,7 +24,19 @@ pub enum Packet {
impl Packet {
pub fn packet_id(&self) -> Identifier {
match self {
Packet::V1 { packet_id, ..} => packet_id.clone()
Packet::V1 { packet_id, .. } => packet_id.clone()
}
}
pub fn command(&self) -> u8 {
match self {
Packet::V1 { command, .. } => command.clone()
}
}
pub fn data(&self) -> PacketData {
match self {
Packet::V1 { data, .. } => data.clone()
}
}
@ -98,3 +111,7 @@ impl Into<Vec<u8>> for Packet {
self.build_full_packet()
}
}
pub trait ToPacket {
fn to_v1_packet(self, src: Identifier, dest: Identifier, packet_id: Identifier, reply_to: Identifier) -> Packet;
}