fix: remove old code
This commit is contained in:
parent
15971aa4fa
commit
913ae5e74a
1 changed files with 6 additions and 44 deletions
|
@ -27,50 +27,6 @@ pub struct Packet {
|
||||||
pub data: PacketData,
|
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 {
|
pub trait ToPacket {
|
||||||
fn to_packet(self, src: Identifier, dest: Identifier, packet_id: Identifier, reply_to: Identifier) -> Packet;
|
fn to_packet(self, src: Identifier, dest: Identifier, packet_id: Identifier, reply_to: Identifier) -> Packet;
|
||||||
}
|
}
|
||||||
|
@ -82,3 +38,9 @@ impl TryFrom<Vec<u8>> for Packet {
|
||||||
Ok(RawPacket::try_from(data)?.into())
|
Ok(RawPacket::try_from(data)?.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Into<Vec<u8>> for Packet {
|
||||||
|
fn into(self) -> Vec<u8> {
|
||||||
|
RawPacket::from(self).into()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue