f1_game_packet_parser/packets/
time_trial.rs

1use super::{u8_to_bool, u8_to_usize};
2use crate::constants::{GearboxAssist, TractionControl, MAX_NUM_CARS};
3
4use binrw::BinRead;
5use serde::{Deserialize, Serialize};
6
7#[allow(clippy::struct_excessive_bools)]
8#[non_exhaustive]
9#[derive(
10    BinRead, Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Debug, Serialize, Deserialize,
11)]
12#[br(little, import(_packet_format: u16))]
13pub struct TimeTrialDataSet {
14    /// Index of the car this data set relates to.
15    #[br(
16        map(u8_to_usize),
17        assert(
18            vehicle_index < MAX_NUM_CARS,
19            "Time trial data set has an invalid vehicle index: {}",
20            vehicle_index
21        )
22    )]
23    pub vehicle_index: usize,
24    /// Team's ID.
25    /// See [`team_id`](mod@crate::constants::team_id) for possible values.
26    pub team_id: u8,
27    /// Lap time in milliseconds.
28    pub lap_time_ms: u32,
29    /// Sector 1 time in milliseconds.
30    pub sector1_time_ms: u32,
31    /// Sector 2 time in milliseconds.
32    pub sector2_time_ms: u32,
33    /// Sector 3 time in milliseconds.
34    pub sector3_time_ms: u32,
35    /// Type of traction control assist enabled.
36    pub traction_control: TractionControl,
37    /// Type of gearbox assist enabled.
38    pub gearbox_assist: GearboxAssist,
39    /// Whether ABS is enabled.
40    #[br(try_map(u8_to_bool))]
41    pub anti_lock_brakes: bool,
42    /// Whether equal car performance is enabled.
43    #[br(try_map(u8_to_bool))]
44    pub equal_car_performance: bool,
45    /// Whether custom setup is in use.
46    #[br(try_map(u8_to_bool))]
47    pub custom_setup: bool,
48    /// Whether this lap is valid.
49    #[br(try_map(u8_to_bool))]
50    pub valid: bool,
51}