fix: weird size issue... usize as u16
This commit is contained in:
parent
f88706bac8
commit
926639387c
3 changed files with 26 additions and 20 deletions
|
@ -27,6 +27,7 @@ mod tests {
|
|||
use crate::packet;
|
||||
use crate::data_types::{DataType, get_data_types};
|
||||
use crate::identifier::Identifier;
|
||||
use crate::packet::Packet;
|
||||
use crate::packet::packet_data::PacketData;
|
||||
|
||||
#[test]
|
||||
|
@ -48,15 +49,17 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn packets() {
|
||||
assert_eq!(packet::Packet {
|
||||
assert_eq!(
|
||||
Into::<Vec<u8>>::into(packet::Packet {
|
||||
src: Identifier::from(0xAABBCCDD),
|
||||
dest: Identifier::from(0xAABBCCDD),
|
||||
packet_id: Identifier::from(0x00000001),
|
||||
reply_to: Identifier::from(0x00000000),
|
||||
command: 0x00,
|
||||
data: PacketData::default(),
|
||||
}.build_base_packet(),
|
||||
vec![
|
||||
}),
|
||||
{
|
||||
let mut v: Vec<u8> = vec![
|
||||
0x01, // version
|
||||
0xAA, 0xBB, 0xCC, 0xDD, // dest
|
||||
0xAA, 0xBB, 0xCC, 0xDD, // src
|
||||
|
@ -65,7 +68,10 @@ mod tests {
|
|||
0x00, // command
|
||||
0x00, 0x00, // data length
|
||||
// no packet data
|
||||
]
|
||||
];
|
||||
v.extend(crc32fast::hash(&v).to_be_bytes().to_vec());
|
||||
v
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ impl From<Packet> for RawPacket {
|
|||
v.extend(packet.packet_id.bytes);
|
||||
v.extend(packet.reply_to.bytes);
|
||||
v.push(packet.command);
|
||||
v.extend(data_length.to_be_bytes());
|
||||
v.extend((data_length as u16).to_be_bytes());
|
||||
v.extend(data);
|
||||
crc32fast::hash(v.as_ref())
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ impl Into<Vec<u8>> for RawPacket {
|
|||
v.extend(self.packet_id.to_be_bytes());
|
||||
v.extend(self.reply_to.to_be_bytes());
|
||||
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.checksum.to_be_bytes());
|
||||
v
|
||||
|
|
Loading…
Reference in a new issue