From 926639387c4869ef82a49cbf19ca2c73be2b4ad1 Mon Sep 17 00:00:00 2001 From: Raine Date: Sun, 15 Oct 2023 18:06:34 +0200 Subject: [PATCH] fix: weird size issue... usize as u16 --- domo_proto/src/lib.rs | 42 ++++++++++++---------- domo_proto/src/packet/raw_packet/packet.rs | 2 +- domo_proto/src/packet/raw_packet/vec.rs | 2 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/domo_proto/src/lib.rs b/domo_proto/src/lib.rs index d18517d..04c7026 100644 --- a/domo_proto/src/lib.rs +++ b/domo_proto/src/lib.rs @@ -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,24 +49,29 @@ mod tests { #[test] pub fn packets() { - assert_eq!(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![ - 0x01, // version - 0xAA, 0xBB, 0xCC, 0xDD, // dest - 0xAA, 0xBB, 0xCC, 0xDD, // src - 0x00, 0x00, 0x00, 0x01, // packet_id - 0x00, 0x00, 0x00, 0x00, // reply_to - 0x00, // command - 0x00, 0x00, // data length - // no packet data - ] + assert_eq!( + Into::>::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(), + }), + { + let mut v: Vec = vec![ + 0x01, // version + 0xAA, 0xBB, 0xCC, 0xDD, // dest + 0xAA, 0xBB, 0xCC, 0xDD, // src + 0x00, 0x00, 0x00, 0x01, // packet_id + 0x00, 0x00, 0x00, 0x00, // reply_to + 0x00, // command + 0x00, 0x00, // data length + // no packet data + ]; + v.extend(crc32fast::hash(&v).to_be_bytes().to_vec()); + v + } ); } } diff --git a/domo_proto/src/packet/raw_packet/packet.rs b/domo_proto/src/packet/raw_packet/packet.rs index c3fcfeb..0f25832 100644 --- a/domo_proto/src/packet/raw_packet/packet.rs +++ b/domo_proto/src/packet/raw_packet/packet.rs @@ -23,7 +23,7 @@ impl From 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()) } diff --git a/domo_proto/src/packet/raw_packet/vec.rs b/domo_proto/src/packet/raw_packet/vec.rs index c85125b..f52b57a 100644 --- a/domo_proto/src/packet/raw_packet/vec.rs +++ b/domo_proto/src/packet/raw_packet/vec.rs @@ -41,7 +41,7 @@ impl Into> 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