f1_game_packet_parser/packets/
final_classification.rs

1use super::u8_to_usize;
2use crate::constants::{ActualTyreCompound, ResultStatus, VisualTyreCompound};
3
4use binrw::BinRead;
5use serde::{Deserialize, Serialize};
6
7const MAX_NUM_TYRE_STINTS: usize = 8;
8
9#[non_exhaustive]
10#[derive(BinRead, PartialEq, PartialOrd, Clone, Debug, Serialize, Deserialize)]
11#[br(little, import(_packet_format: u16))]
12pub struct FinalClassificationData {
13    /// Finishing position.
14    pub position: u8,
15    /// Number of laps completed.
16    pub num_laps: u8,
17    /// Grid position of the car.
18    pub grid_position: u8,
19    /// Number of points scored.
20    pub points: u8,
21    /// Number of pit stops made.
22    pub num_pit_stops: u8,
23    /// Result status.
24    pub result_status: ResultStatus,
25    /// Best lap time of the session in milliseconds.
26    pub best_lap_time_ms: u32,
27    /// Total race time in seconds (without penalties).
28    pub total_race_time: f64,
29    /// Total penalties accumulated in seconds.
30    pub penalties_time: u8,
31    /// Number of penalties applied to this driver.
32    pub num_penalties: u8,
33    /// Number of tyre stints.
34    #[br(
35        map(u8_to_usize),
36        assert(
37            num_tyre_stints <= MAX_NUM_TYRE_STINTS,
38            "Final classification entry has an invalid number of tyre stints: {}",
39            num_tyre_stints
40        )
41    )]
42    pub num_tyre_stints: usize,
43    /// Actual tyres used by the driver.
44    /// Should have a size equal to
45    /// [`num_tyre_stints`](field@FinalClassificationData::num_tyre_stints).
46    #[br(count(num_tyre_stints), pad_after(MAX_NUM_TYRE_STINTS - num_tyre_stints))]
47    pub tyre_stints_actual: Vec<ActualTyreCompound>,
48    /// Visual tyres used by the driver.
49    /// Should have a size equal to
50    /// [`num_tyre_stints`](field@FinalClassificationData::num_tyre_stints).
51    #[br(count(num_tyre_stints), pad_after(MAX_NUM_TYRE_STINTS - num_tyre_stints))]
52    pub tyre_stints_visual: Vec<VisualTyreCompound>,
53    /// The lap numbers the stints end on.
54    /// Should have a size equal to
55    /// [`num_tyre_stints`](field@FinalClassificationData::num_tyre_stints).
56    #[br(count(num_tyre_stints), pad_after(MAX_NUM_TYRE_STINTS - num_tyre_stints))]
57    pub tyre_stints_end_laps: Vec<u8>,
58}