diff --git a/Cargo.toml b/Cargo.toml index 6db9b76..1351ccc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "f1-2022-udp-server" description = "A UDP server library for F1 2022" license = "MIT" -version = "0.1.4" +version = "0.1.5" edition = "2021" homepage = "https://github.com/jaapieaapie1/F1-2022-telemetry-rust" exclude = [".idea/", "target/"] diff --git a/src/server.rs b/src/server.rs index bd25168..8c015be 100644 --- a/src/server.rs +++ b/src/server.rs @@ -27,7 +27,7 @@ impl Server { } pub fn read_packet(&self) -> io::Result { - let mut buf: [u8; PacketHeader::PACKET_SIZE] = [0; PacketHeader::PACKET_SIZE]; + let mut buf: [u8; Self::calculate_size(PacketHeader::PACKET_SIZE)] = [0; Self::calculate_size(PacketHeader::PACKET_SIZE)]; self.stream.peek(&mut buf)?; let header = PacketHeader::new(&mut ByteBuffer::from_bytes(&buf))?; @@ -87,10 +87,17 @@ impl Server { } fn read_packet_dynamically(&self) -> io::Result

{ - let mut buf: Vec = vec![0; P::get_packet_size()]; + let mut buf: Vec = vec![0; Self::calculate_size(P::get_packet_size())]; self.stream.recv(&mut buf)?; P::new(&mut ByteBuffer::from_bytes(&buf)) } + + pub const fn calculate_size(size: usize) -> usize { + if cfg!(windows) { + return size + 2048 + } + size + } }