fix: replace incorrect constant for lap history entry's raw size with inline function

This commit is contained in:
Maciej Pędzich 2025-02-26 21:56:52 +01:00
parent 9b165c456d
commit 70dccb8c0b
Signed by: maciejpedzich
GPG Key ID: CE4A303D84882F0D
2 changed files with 12 additions and 3 deletions

View File

@ -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<LapHistoryData>,
/// Tyre stint history.

View File

@ -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
}
}