fix: remove old code

This commit is contained in:
Strix 2023-10-15 18:06:33 +02:00
parent 15971aa4fa
commit 913ae5e74a
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774

View file

@ -27,50 +27,6 @@ pub struct Packet {
pub data: PacketData,
}
impl Packet {
/// Build packet **without** CRC32
pub fn build_base_packet(&self) -> Vec<u8> {
match self {
Packet {
dest,
src,
packet_id,
reply_to,
command,
data,
} => {
let mut buf = Vec::new();
let data = data.clone().into_bytes();
let data_length = data.len();
buf.push(0x01);
buf.extend_from_slice(&dest.bytes);
buf.extend_from_slice(&src.bytes);
buf.extend_from_slice(&packet_id.bytes);
buf.extend_from_slice(&reply_to.bytes);
buf.push(command.clone());
buf.push((data_length >> 8) as u8);
buf.push((data_length & 0xFF) as u8);
buf.extend(data);
buf
}
}
}
pub fn get_crc32(&self) -> u32 {
crc32fast::hash(self.build_base_packet().as_slice())
}
pub fn build_full_packet(&self) -> Vec<u8> {
match self {
Packet { .. } => {
let mut buf = self.build_base_packet();
buf.extend_from_slice(crc32fast::hash(&buf.as_slice()).to_be_bytes().as_ref());
buf
}
}
}
}
pub trait ToPacket {
fn to_packet(self, src: Identifier, dest: Identifier, packet_id: Identifier, reply_to: Identifier) -> Packet;
}
@ -81,4 +37,10 @@ impl TryFrom<Vec<u8>> for Packet {
fn try_from(data: Vec<u8>) -> io::Result<Self> {
Ok(RawPacket::try_from(data)?.into())
}
}
impl Into<Vec<u8>> for Packet {
fn into(self) -> Vec<u8> {
RawPacket::from(self).into()
}
}