mirror of
https://github.com/maciejpedzich/f1-game-packet-parser.git
synced 2025-04-12 00:21:11 +02:00
f1-game-packet-parser
This is a Rust crate that allows you to convert raw binary data from F1 24, F1 23, and F1 22 UDP telemetry into organised structs.
Getting started
Add f1_game_packet_parser
to your project's Cargo.toml
file:
[dependencies]
f1_game_packet_parser = "1.0.0"
Example
This crate doesn't provide a UDP client out of the box. Here's how to write one that will parse and pretty-print incoming packets:
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 and print it.
let packet = parse(&buf[..amt])?;
println!("{:#?}", packet);
}
}
Minimum supported Rust version
The minimum supported Rust version is documented in the Cargo.toml file. This may be bumped in minor releases if necessary.
Original documentation links
License
MIT
Languages
Rust
100%