From 1bdf45a1ee5b1c068eac60a72154acfda872f261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20P=C4=99dzich?= Date: Sun, 23 Feb 2025 18:22:37 +0100 Subject: [PATCH] refactor: use from_bits_retain instead of truncate when reading bitmap fields --- src/packets/car_telemetry.rs | 2 +- src/packets/event.rs | 8 ++++---- src/packets/session_history.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/packets/car_telemetry.rs b/src/packets/car_telemetry.rs index 7067b9b..103ab33 100644 --- a/src/packets/car_telemetry.rs +++ b/src/packets/car_telemetry.rs @@ -70,7 +70,7 @@ pub struct CarTelemetryData { )] pub rev_lights_percent: u8, /// Bitmap of active rev lights. - #[br(map(RevLights::from_bits_truncate))] + #[br(map(RevLights::from_bits_retain))] pub rev_lights_bit_value: RevLights, /// Brakes' temperature values in degrees Celsius. /// See [`wheel_index`](mod@crate::constants::wheel_index) diff --git a/src/packets/event.rs b/src/packets/event.rs index f696cef..fd6fd7d 100644 --- a/src/packets/event.rs +++ b/src/packets/event.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; #[non_exhaustive] #[derive(BinRead, PartialEq, PartialOrd, Copy, Clone, Debug, Serialize, Deserialize)] #[br(little, import(_packet_format: u16))] -pub enum EventDataDetails { +pub enum EventDetails { /// Sent when the session starts. #[br(magic = b"SSTA")] SessionStarted, @@ -130,7 +130,7 @@ pub enum EventDataDetails { #[br(magic = b"BUTN")] Buttons { /// Bitmap specifying which buttons are currently pressed. - #[br(map(ButtonStatus::from_bits_truncate))] + #[br(map(ButtonStatus::from_bits_retain))] button_status: ButtonStatus, }, /// Sent when a car has overtaken another. @@ -154,9 +154,9 @@ pub enum EventDataDetails { Collision { /// Index of the first vehicle involved in the collision. #[br(map(u8_to_usize))] - vehicle1_index: usize, + vehicle_index: usize, /// Index of the second vehicle involved in the collision. #[br(map(u8_to_usize))] - vehicle2_index: usize, + other_vehicle_index: usize, }, } diff --git a/src/packets/session_history.rs b/src/packets/session_history.rs index 810bc6a..26735c1 100644 --- a/src/packets/session_history.rs +++ b/src/packets/session_history.rs @@ -35,7 +35,7 @@ pub struct LapHistoryData { #[br(if(packet_format >= 2023))] pub sector3_time_minutes: u8, /// Bitmap of lap validity across all sectors and overall. - #[br(map(LapValid::from_bits_truncate))] + #[br(map(LapValid::from_bits_retain))] pub lap_valid_bit_flags: LapValid, }