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::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,15 +49,17 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn packets() {
|
pub fn packets() {
|
||||||
assert_eq!(packet::Packet {
|
assert_eq!(
|
||||||
|
Into::<Vec<u8>>::into(packet::Packet {
|
||||||
src: Identifier::from(0xAABBCCDD),
|
src: Identifier::from(0xAABBCCDD),
|
||||||
dest: Identifier::from(0xAABBCCDD),
|
dest: Identifier::from(0xAABBCCDD),
|
||||||
packet_id: Identifier::from(0x00000001),
|
packet_id: Identifier::from(0x00000001),
|
||||||
reply_to: Identifier::from(0x00000000),
|
reply_to: Identifier::from(0x00000000),
|
||||||
command: 0x00,
|
command: 0x00,
|
||||||
data: PacketData::default(),
|
data: PacketData::default(),
|
||||||
}.build_base_packet(),
|
}),
|
||||||
vec![
|
{
|
||||||
|
let mut v: Vec<u8> = vec![
|
||||||
0x01, // version
|
0x01, // version
|
||||||
0xAA, 0xBB, 0xCC, 0xDD, // dest
|
0xAA, 0xBB, 0xCC, 0xDD, // dest
|
||||||
0xAA, 0xBB, 0xCC, 0xDD, // src
|
0xAA, 0xBB, 0xCC, 0xDD, // src
|
||||||
|
@ -65,7 +68,10 @@ mod tests {
|
||||||
0x00, // command
|
0x00, // command
|
||||||
0x00, 0x00, // data length
|
0x00, 0x00, // data length
|
||||||
// no packet data
|
// 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.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())
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue