diff --git a/src/packets/mod.rs b/src/packets/mod.rs index e57241b..c4b5ffa 100644 --- a/src/packets/mod.rs +++ b/src/packets/mod.rs @@ -37,7 +37,7 @@ use crate::packets::session::{ MAX_NUM_MARSHAL_ZONES, MAX_NUM_SESSIONS, }; use crate::packets::session_history::{ - LapHistoryData, TyreStintHistoryData, LAP_HISTORY_RAW_SIZE, MAX_NUM_LAPS, + get_lap_history_raw_size, LapHistoryData, TyreStintHistoryData, MAX_NUM_LAPS, MAX_NUM_TYRE_STINTS, }; use crate::packets::time_trial::TimeTrialDataSet; @@ -335,6 +335,7 @@ pub struct F1PacketSession { /// Number of sessions in the ongoing race weekend. #[br( map(u8_to_usize), + if(packet_format >= 2024), assert( num_sessions_in_weekend <= MAX_NUM_SESSIONS, "Session packet has an invalid number of sessions in a weekend: {}", @@ -574,7 +575,7 @@ pub struct F1PacketSessionHistory { #[br( count(num_laps), args{ inner: (packet_format,) }, - pad_after((MAX_NUM_LAPS - num_laps) * LAP_HISTORY_RAW_SIZE) + pad_after((MAX_NUM_LAPS - num_laps) * get_lap_history_raw_size(packet_format)) )] pub lap_history_data: Vec, /// Tyre stint history. diff --git a/src/packets/session_history.rs b/src/packets/session_history.rs index 26735c1..2c08576 100644 --- a/src/packets/session_history.rs +++ b/src/packets/session_history.rs @@ -5,7 +5,6 @@ use binrw::BinRead; use serde::{Deserialize, Serialize}; pub(super) const MAX_NUM_LAPS: usize = 100; -pub(super) const LAP_HISTORY_RAW_SIZE: usize = 14; pub(super) const MAX_NUM_TYRE_STINTS: usize = 8; #[non_exhaustive] @@ -53,3 +52,12 @@ pub struct TyreStintHistoryData { /// Visual tyre compound used. pub visual_tyre_compound: VisualTyreCompound, } + +#[inline(always)] +pub(super) fn get_lap_history_raw_size(packet_format: u16) -> usize { + if packet_format >= 2023 { + 14 + } else { + 11 + } +}