fix: weird size issue... usize as u16

This commit is contained in:
Strix 2023-10-15 18:06:34 +02:00
parent f88706bac8
commit 926639387c
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774
3 changed files with 26 additions and 20 deletions

View file

@ -27,6 +27,7 @@ mod tests {
use crate::packet; use crate::packet;
use crate::data_types::{DataType, get_data_types}; use crate::data_types::{DataType, get_data_types};
use crate::identifier::Identifier; use crate::identifier::Identifier;
use crate::packet::Packet;
use crate::packet::packet_data::PacketData; use crate::packet::packet_data::PacketData;
#[test] #[test]
@ -48,24 +49,29 @@ mod tests {
#[test] #[test]
pub fn packets() { pub fn packets() {
assert_eq!(packet::Packet { assert_eq!(
src: Identifier::from(0xAABBCCDD), Into::<Vec<u8>>::into(packet::Packet {
dest: Identifier::from(0xAABBCCDD), src: Identifier::from(0xAABBCCDD),
packet_id: Identifier::from(0x00000001), dest: Identifier::from(0xAABBCCDD),
reply_to: Identifier::from(0x00000000), packet_id: Identifier::from(0x00000001),
command: 0x00, reply_to: Identifier::from(0x00000000),
data: PacketData::default(), command: 0x00,
}.build_base_packet(), data: PacketData::default(),
vec![ }),
0x01, // version {
0xAA, 0xBB, 0xCC, 0xDD, // dest let mut v: Vec<u8> = vec![
0xAA, 0xBB, 0xCC, 0xDD, // src 0x01, // version
0x00, 0x00, 0x00, 0x01, // packet_id 0xAA, 0xBB, 0xCC, 0xDD, // dest
0x00, 0x00, 0x00, 0x00, // reply_to 0xAA, 0xBB, 0xCC, 0xDD, // src
0x00, // command 0x00, 0x00, 0x00, 0x01, // packet_id
0x00, 0x00, // data length 0x00, 0x00, 0x00, 0x00, // reply_to
// no packet data 0x00, // command
] 0x00, 0x00, // data length
// no packet data
];
v.extend(crc32fast::hash(&v).to_be_bytes().to_vec());
v
}
); );
} }
} }

View file

@ -23,7 +23,7 @@ impl From<Packet> for RawPacket {
v.extend(packet.packet_id.bytes); v.extend(packet.packet_id.bytes);
v.extend(packet.reply_to.bytes); v.extend(packet.reply_to.bytes);
v.push(packet.command); v.push(packet.command);
v.extend(data_length.to_be_bytes()); v.extend((data_length as u16).to_be_bytes());
v.extend(data); v.extend(data);
crc32fast::hash(v.as_ref()) crc32fast::hash(v.as_ref())
} }

View file

@ -41,7 +41,7 @@ impl Into<Vec<u8>> for RawPacket {
v.extend(self.packet_id.to_be_bytes()); v.extend(self.packet_id.to_be_bytes());
v.extend(self.reply_to.to_be_bytes()); v.extend(self.reply_to.to_be_bytes());
v.push(self.command); v.push(self.command);
v.extend(self.data_length.to_be_bytes()); v.extend((self.data_length as u16).to_be_bytes());
v.extend(self.data); v.extend(self.data);
v.extend(self.checksum.to_be_bytes()); v.extend(self.checksum.to_be_bytes());
v v