mirror of
https://github.com/maciejpedzich/f1-game-packet-parser.git
synced 2025-04-18 18:51:11 +02:00
refactor: add binrw asserts for all index fields in event packets
This commit is contained in:
parent
359360cded
commit
3625265317
@ -137,9 +137,9 @@ pub enum EventDetails {
|
|||||||
#[br(
|
#[br(
|
||||||
map(u8_to_usize),
|
map(u8_to_usize),
|
||||||
assert(
|
assert(
|
||||||
vehicle_index < MAX_NUM_CARS,
|
fastest_vehicle_index < MAX_NUM_CARS,
|
||||||
"Speed trap event has an invalid fastest vehicle index: {}",
|
"Speed trap event has an invalid fastest vehicle index: {}",
|
||||||
vehicle_index
|
fastest_vehicle_index
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
fastest_vehicle_index: usize,
|
fastest_vehicle_index: usize,
|
||||||
@ -159,14 +159,28 @@ pub enum EventDetails {
|
|||||||
#[br(magic = b"DTSV")]
|
#[br(magic = b"DTSV")]
|
||||||
DriveThroughServed {
|
DriveThroughServed {
|
||||||
/// Index of the vehicle serving the penalty.
|
/// Index of the vehicle serving the penalty.
|
||||||
#[br(map(u8_to_usize))]
|
#[br(
|
||||||
|
map(u8_to_usize),
|
||||||
|
assert(
|
||||||
|
vehicle_index < MAX_NUM_CARS,
|
||||||
|
"Drive-through served event has an invalid vehicle index: {}",
|
||||||
|
vehicle_index
|
||||||
|
)
|
||||||
|
)]
|
||||||
vehicle_index: usize,
|
vehicle_index: usize,
|
||||||
},
|
},
|
||||||
/// Sent when a driver has served a stop-go penalty.
|
/// Sent when a driver has served a stop-go penalty.
|
||||||
#[br(magic = b"SGSV")]
|
#[br(magic = b"SGSV")]
|
||||||
StopGoServed {
|
StopGoServed {
|
||||||
/// Index of the vehicle serving the penalty.
|
/// Index of the vehicle serving the penalty.
|
||||||
#[br(map(u8_to_usize))]
|
#[br(
|
||||||
|
map(u8_to_usize),
|
||||||
|
assert(
|
||||||
|
vehicle_index < MAX_NUM_CARS,
|
||||||
|
"Stop-go served event has an invalid vehicle index: {}",
|
||||||
|
vehicle_index
|
||||||
|
)
|
||||||
|
)]
|
||||||
vehicle_index: usize,
|
vehicle_index: usize,
|
||||||
},
|
},
|
||||||
/// Sent when a flashback is activated.
|
/// Sent when a flashback is activated.
|
||||||
@ -185,6 +199,7 @@ pub enum EventDetails {
|
|||||||
button_status: ButtonStatus,
|
button_status: ButtonStatus,
|
||||||
},
|
},
|
||||||
/// Sent when the red flag is shown.
|
/// Sent when the red flag is shown.
|
||||||
|
/// Available from the 2023 format onwards.
|
||||||
#[br(magic = b"RDFL")]
|
#[br(magic = b"RDFL")]
|
||||||
RedFlag,
|
RedFlag,
|
||||||
/// Sent when a car has overtaken another.
|
/// Sent when a car has overtaken another.
|
||||||
@ -192,10 +207,24 @@ pub enum EventDetails {
|
|||||||
#[br(magic = b"OVTK")]
|
#[br(magic = b"OVTK")]
|
||||||
Overtake {
|
Overtake {
|
||||||
/// Index of the overtaking vehicle.
|
/// Index of the overtaking vehicle.
|
||||||
#[br(map(u8_to_usize))]
|
#[br(
|
||||||
|
map(u8_to_usize),
|
||||||
|
assert(
|
||||||
|
overtaking_vehicle_index < MAX_NUM_CARS,
|
||||||
|
"Overtake event has an invalid overtaking vehicle index: {}",
|
||||||
|
overtaking_vehicle_index
|
||||||
|
)
|
||||||
|
)]
|
||||||
overtaking_vehicle_index: usize,
|
overtaking_vehicle_index: usize,
|
||||||
/// Index of the overtaken vehicle.
|
/// Index of the overtaken vehicle.
|
||||||
#[br(map(u8_to_usize))]
|
#[br(
|
||||||
|
map(u8_to_usize),
|
||||||
|
assert(
|
||||||
|
overtaken_vehicle_index < MAX_NUM_CARS,
|
||||||
|
"Collision event has an invalid overtaken vehicle index: {}",
|
||||||
|
overtaken_vehicle_index
|
||||||
|
)
|
||||||
|
)]
|
||||||
overtaken_vehicle_index: usize,
|
overtaken_vehicle_index: usize,
|
||||||
},
|
},
|
||||||
/// Sent when safety car gets deployed.
|
/// Sent when safety car gets deployed.
|
||||||
@ -212,10 +241,24 @@ pub enum EventDetails {
|
|||||||
#[br(magic = b"COLL")]
|
#[br(magic = b"COLL")]
|
||||||
Collision {
|
Collision {
|
||||||
/// Index of the first vehicle involved in the collision.
|
/// Index of the first vehicle involved in the collision.
|
||||||
#[br(map(u8_to_usize))]
|
#[br(
|
||||||
|
map(u8_to_usize),
|
||||||
|
assert(
|
||||||
|
vehicle_index < MAX_NUM_CARS,
|
||||||
|
"Collision event has an invalid vehicle index: {}",
|
||||||
|
vehicle_index
|
||||||
|
)
|
||||||
|
)]
|
||||||
vehicle_index: usize,
|
vehicle_index: usize,
|
||||||
/// Index of the second vehicle involved in the collision.
|
/// Index of the second vehicle involved in the collision.
|
||||||
#[br(map(u8_to_usize))]
|
#[br(
|
||||||
|
map(u8_to_usize),
|
||||||
|
assert(
|
||||||
|
other_vehicle_index < MAX_NUM_CARS,
|
||||||
|
"Collision event has an invalid other vehicle index: {}",
|
||||||
|
other_vehicle_index
|
||||||
|
)
|
||||||
|
)]
|
||||||
other_vehicle_index: usize,
|
other_vehicle_index: usize,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user