Fix panic when running on x86_64

The length of usize::to_be_bytes depends on the size of the pointer on the
targeted cpu architecture
This commit is contained in:
Sosthène Guédon
2023-01-25 10:11:23 +01:00
parent 82c26f2391
commit e3cb8acfef
+6 -2
View File
@@ -1,4 +1,4 @@
use core::convert::TryInto;
use core::convert::{TryFrom, TryInto};
use crate::constants::*;
@@ -119,7 +119,11 @@ impl From<DataBlock<'_>> for RawPacket {
let len = block.data.len();
packet.resize_default(10 + len).ok();
packet[0] = 0x80;
packet[1..][..4].copy_from_slice(&len.to_le_bytes());
packet[1..][..4].copy_from_slice(
&u32::try_from(len)
.expect("Packets should not be more than 4GiB")
.to_le_bytes(),
);
packet[5] = 0;
packet[6] = block.seq;