mirror of
https://github.com/eigenein/wotbreplay-parser.git
synced 2026-10-21 02:17:02 +02:00
💥 Rename Packet::clock to clock_secs
This commit is contained in:
1 parent
a177447ca1
commit
838a49ee68
3 files changed
+33
-24
No files matched your search
@@ -27,21 +27,21 @@ pub enum EntityMethod {
|
|||||||
|
|
||||||
impl EntityMethod {
|
impl EntityMethod {
|
||||||
/// Parse the entity method payload.
|
/// Parse the entity method payload.
|
||||||
pub fn new(payload: &[u8]) -> Result<Self> {
|
pub fn new(raw_payload: &[u8]) -> Result<Self> {
|
||||||
let mut payload = payload;
|
let mut raw_payload = raw_payload;
|
||||||
|
|
||||||
payload.read_u32::<LittleEndian>()?;
|
raw_payload.read_u32::<LittleEndian>()?;
|
||||||
let sub_type = payload.read_u32::<LittleEndian>()?;
|
let sub_type = raw_payload.read_u32::<LittleEndian>()?;
|
||||||
|
|
||||||
let this = match sub_type {
|
let this = match sub_type {
|
||||||
47 => {
|
47 => {
|
||||||
let _inner_length = payload.read_u32::<LittleEndian>()?;
|
let _inner_length = raw_payload.read_u32::<LittleEndian>()?;
|
||||||
|
|
||||||
let field_number = decode_varint(&mut payload)?;
|
let field_number = decode_varint(&mut raw_payload)?;
|
||||||
let message_length = read_quirky_length(&mut payload)?;
|
let message_length = read_quirky_length(&mut raw_payload)?;
|
||||||
Self::UpdateArena {
|
Self::UpdateArena {
|
||||||
field_number,
|
field_number,
|
||||||
arguments: UpdateArena::decode(&payload[..message_length])?,
|
arguments: UpdateArena::decode(&raw_payload[..message_length])?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,21 @@ use serde_with::serde_as;
|
|||||||
use crate::models::data::payload::Payload;
|
use crate::models::data::payload::Payload;
|
||||||
use crate::result::Result;
|
use crate::result::Result;
|
||||||
|
|
||||||
|
/// «Packet» is a single traffic message in a replay,
|
||||||
|
/// packets tell us what is going on during the battle.
|
||||||
#[serde_as]
|
#[serde_as]
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct Packet {
|
pub struct Packet {
|
||||||
pub clock: f32,
|
/// Replay time, starting from zero.
|
||||||
|
#[serde(rename = "clock")]
|
||||||
|
pub clock_secs: f32,
|
||||||
|
|
||||||
|
/// Parsed packet payload.
|
||||||
pub payload: Payload,
|
pub payload: Payload,
|
||||||
|
|
||||||
|
/// Raw packet payload, excluding the clock and packet type, and including optional subtype.
|
||||||
|
///
|
||||||
|
/// This attribute requires the `raw-payload` feature.
|
||||||
#[cfg(feature = "raw-payload")]
|
#[cfg(feature = "raw-payload")]
|
||||||
#[serde_as(as = "serde_with::hex::Hex")]
|
#[serde_as(as = "serde_with::hex::Hex")]
|
||||||
pub raw_payload: Vec<u8>,
|
pub raw_payload: Vec<u8>,
|
||||||
@@ -22,19 +31,19 @@ impl Packet {
|
|||||||
pub fn from_reader(reader: &mut impl Read) -> Result<Option<Self>> {
|
pub fn from_reader(reader: &mut impl Read) -> Result<Option<Self>> {
|
||||||
let Ok(length) = reader.read_u32::<LittleEndian>() else { return Ok(None) };
|
let Ok(length) = reader.read_u32::<LittleEndian>() else { return Ok(None) };
|
||||||
let type_ = reader.read_u32::<LittleEndian>()?;
|
let type_ = reader.read_u32::<LittleEndian>()?;
|
||||||
let clock = reader.read_f32::<LittleEndian>()?;
|
let clock_secs = reader.read_f32::<LittleEndian>()?;
|
||||||
let payload = Self::read_payload(reader, length as usize)?;
|
let raw_payload = Self::read_raw_payload(reader, length as usize)?;
|
||||||
let this = Self {
|
let this = Self {
|
||||||
clock,
|
clock_secs,
|
||||||
payload: Payload::new(type_, &payload)?,
|
payload: Payload::new(type_, &raw_payload)?,
|
||||||
|
|
||||||
#[cfg(feature = "raw-payload")]
|
#[cfg(feature = "raw-payload")]
|
||||||
raw_payload: payload,
|
raw_payload,
|
||||||
};
|
};
|
||||||
Ok(Some(this))
|
Ok(Some(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_payload(reader: &mut impl Read, length: usize) -> Result<Vec<u8>> {
|
fn read_raw_payload(reader: &mut impl Read, length: usize) -> Result<Vec<u8>> {
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
buffer.resize(length, 0);
|
buffer.resize(length, 0);
|
||||||
reader.read_exact(&mut buffer)?;
|
reader.read_exact(&mut buffer)?;
|
||||||
|
|||||||
@@ -30,19 +30,19 @@ pub enum Payload {
|
|||||||
|
|
||||||
impl Payload {
|
impl Payload {
|
||||||
/// Parse the packet payload.
|
/// Parse the packet payload.
|
||||||
pub fn new(packet_type: u32, payload: &[u8]) -> Result<Self> {
|
pub fn new(packet_type: u32, raw_payload: &[u8]) -> Result<Self> {
|
||||||
let mut payload = payload;
|
let mut raw_payload = raw_payload;
|
||||||
|
|
||||||
let this = match packet_type {
|
let this = match packet_type {
|
||||||
0 => {
|
0 => {
|
||||||
payload.read_exact(&mut [0; 10])?;
|
raw_payload.read_exact(&mut [0; 10])?;
|
||||||
|
|
||||||
let author_nickname = read_string(&mut payload)?;
|
let author_nickname = read_string(&mut raw_payload)?;
|
||||||
let arena_unique_id = payload.read_u64::<LittleEndian>()?;
|
let arena_unique_id = raw_payload.read_u64::<LittleEndian>()?;
|
||||||
let arena_type_id = payload.read_u32::<LittleEndian>()?;
|
let arena_type_id = raw_payload.read_u32::<LittleEndian>()?;
|
||||||
let arguments = {
|
let arguments = {
|
||||||
let pickled_length = read_quirky_length(&mut payload)?;
|
let pickled_length = read_quirky_length(&mut raw_payload)?;
|
||||||
read_pickled(&mut payload, pickled_length)?
|
read_pickled(&mut raw_payload, pickled_length)?
|
||||||
};
|
};
|
||||||
Self::BasePlayerCreate {
|
Self::BasePlayerCreate {
|
||||||
arguments,
|
arguments,
|
||||||
@@ -52,7 +52,7 @@ impl Payload {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
8 => Self::EntityMethod(EntityMethod::new(payload)?),
|
8 => Self::EntityMethod(EntityMethod::new(raw_payload)?),
|
||||||
|
|
||||||
_ => Self::Unknown { packet_type },
|
_ => Self::Unknown { packet_type },
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user