Crates.io | f1-game-packet-parser |
lib.rs | f1-game-packet-parser |
version | 1.0.5 |
created_at | 2025-02-28 14:54:21.889787+00 |
updated_at | 2025-05-17 22:50:03.4393+00 |
description | Convert binary data from F1 24, F1 23, and F1 22 UDP telemetry into organised structs. |
homepage | https://github.com/maciejpedzich/f1-game-packet-parser |
repository | https://github.com/maciejpedzich/f1-game-packet-parser |
max_upload_size | |
id | 1572899 |
size | 152,743 |
This is a Rust crate that allows you to convert binary data from F1 24, F1 23, and F1 22 UDP telemetry into organised structs.
Add f1-game-packet-parser
to your project by running this command:
cargo add f1-game-packet-parser
This crate doesn't provide a UDP client out of the box. Here's how to write one that will keep parsing incoming packets until it receives final classification or a session ended event packet. It will then print either the final classification or a Session has ended! message and exit.
use f1_game_packet_parser::packets::event::EventDetails;
use f1_game_packet_parser::parse;
use std::error::Error;
use std::net::UdpSocket;
fn main() -> Result<(), Box<dyn Error>> {
// This IP and port should be set in the game's options by default.
let socket = UdpSocket::bind("127.0.0.1:20777")?;
let mut buf = [0u8; 1464];
loop {
// Receive raw packet data from the game.
// The buf array should be large enough for all types of packets.
let (amt, _) = socket.recv_from(&mut buf)?;
// Convert received bytes to an F1Packet struct.
let packet = parse(&buf[..amt])?;
// It's the final classification confirmation.
if let Some(final_classification) = packet.final_classification {
println!("{:#?}", final_classification);
break;
}
// It's the session ended event.
else if packet
.event
.is_some_and(|event| event.details == EventDetails::SessionEnded)
{
println!("Session has ended!");
break;
}
}
Ok(())
}
The minimum supported Rust version is documented in the Cargo.toml
file. It may be bumped in minor releases if necessary.
My initial goal was to provide support from the most recent game all the way to F1 2018, starting development with implementing support for the latter and working my way up. I ended up limiting my crate's backwards compatibility to F1 22, because:
However, if you believe there's a method in the madness and/or need support for these older packet formats, feel free to open an issue or a pull request.
If you're looking for a crate that supports an older telemetry format or need a built-in UDP client, consider one of the following:
In the list below:
MIT