mirror of
https://github.com/eigenein/wotbreplay-parser.git
synced 2026-10-24 19:59:48 +02:00
Break: refactor the packet payloads
This commit is contained in:
1 parent
9d601082d6
commit
e48fe1dd0d
8 files changed
+70
-70
No files matched your search
+7
-30
@@ -3,8 +3,8 @@
|
||||
pub mod entity_method;
|
||||
pub mod packet;
|
||||
pub mod payload;
|
||||
pub mod replay_header;
|
||||
pub mod summary;
|
||||
pub mod subtype_2f;
|
||||
pub mod type_0;
|
||||
|
||||
use std::io::Read;
|
||||
|
||||
@@ -12,11 +12,7 @@ use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
|
||||
pub use self::entity_method::*;
|
||||
pub use self::summary::*;
|
||||
use crate::models::data::packet::Packet;
|
||||
use crate::models::data::payload::Payload;
|
||||
use crate::models::data::replay_header::ReplayHeader;
|
||||
use crate::result::Result;
|
||||
use crate::Error;
|
||||
|
||||
@@ -26,9 +22,7 @@ pub struct Data {
|
||||
/// For example: `9.8.5_apple`.
|
||||
pub client_version: String,
|
||||
|
||||
pub replay_header: Option<ReplayHeader>,
|
||||
|
||||
pub other_packets: Vec<Packet>,
|
||||
pub packets: Vec<Packet>,
|
||||
}
|
||||
|
||||
impl Data {
|
||||
@@ -46,29 +40,12 @@ impl Data {
|
||||
// Some extra byte, no idea:
|
||||
reader.read_u8()?;
|
||||
|
||||
let mut this = Self::new(client_version);
|
||||
|
||||
loop {
|
||||
let Some(packet) = Packet::from_reader(&mut reader)? else { break };
|
||||
match packet.payload {
|
||||
Payload::ReplayHeader(header) => {
|
||||
this.replay_header = Some(*header);
|
||||
}
|
||||
_ => {
|
||||
this.other_packets.push(packet);
|
||||
}
|
||||
}
|
||||
let mut packets = Vec::new();
|
||||
while let Some(packet) = Packet::from_reader(&mut reader)? {
|
||||
packets.push(packet);
|
||||
}
|
||||
|
||||
Ok(this)
|
||||
}
|
||||
|
||||
pub const fn new(client_version: String) -> Self {
|
||||
Self {
|
||||
client_version,
|
||||
replay_header: None,
|
||||
other_packets: Vec::new(),
|
||||
}
|
||||
Ok(Self { client_version, packets })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::io::Read;
|
||||
|
||||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use serde::Serialize;
|
||||
use serde_with::serde_as;
|
||||
@@ -7,10 +9,11 @@ use crate::result::Result;
|
||||
#[serde_as]
|
||||
#[derive(Debug, Serialize)]
|
||||
pub enum EntityMethod {
|
||||
/// TODO: team composition.
|
||||
Subtype2F(#[serde_as(as = "serde_with::hex::Hex")] Vec<u8>),
|
||||
Subtype2F {
|
||||
// prefix: [u8; 9],
|
||||
},
|
||||
|
||||
/// Default variant when subtype is not known.
|
||||
/// Default variant when subtype is not known by the parser.
|
||||
Unknown {
|
||||
sub_type: u32,
|
||||
|
||||
@@ -28,7 +31,12 @@ impl EntityMethod {
|
||||
let sub_type = reader.read_u32::<LittleEndian>()?;
|
||||
|
||||
let this = match sub_type {
|
||||
0x2F => Self::Subtype2F(payload),
|
||||
0x2F => {
|
||||
// let mut prefix = [0; 9];
|
||||
// reader.read_exact(&mut prefix)?;
|
||||
Self::Subtype2F {}
|
||||
}
|
||||
|
||||
_ => Self::Unknown { sub_type, payload },
|
||||
};
|
||||
Ok(this)
|
||||
|
||||
+17
-12
@@ -4,17 +4,25 @@ use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use serde::Serialize;
|
||||
use serde_with::serde_as;
|
||||
|
||||
use crate::models::data::replay_header::ReplayHeader;
|
||||
use crate::models::data::{assert_magic, read_pickled, read_string, EntityMethod};
|
||||
use crate::models::data::entity_method::EntityMethod;
|
||||
use crate::models::data::type_0::Type0;
|
||||
use crate::models::data::{assert_magic, read_pickled, read_string};
|
||||
use crate::result::Result;
|
||||
|
||||
#[serde_as]
|
||||
#[derive(Debug, Serialize)]
|
||||
pub enum Payload {
|
||||
ReplayHeader(Box<ReplayHeader>),
|
||||
/// Looks like some sort of replay summary.
|
||||
Type0 {
|
||||
author_nickname: String,
|
||||
arena_unique_id: u64,
|
||||
arena_type_id: u32,
|
||||
type_0: Box<Type0>,
|
||||
},
|
||||
|
||||
EntityMethod(EntityMethod),
|
||||
|
||||
/// Default payload when type is not known.
|
||||
/// Default payload when type is not known by the parser.
|
||||
Unknown {
|
||||
type_: u32,
|
||||
|
||||
@@ -34,26 +42,23 @@ impl Payload {
|
||||
let author_nickname = read_string(&mut reader)?;
|
||||
let arena_unique_id = reader.read_u64::<LittleEndian>()?;
|
||||
let arena_type_id = reader.read_u32::<LittleEndian>()?;
|
||||
let summary = {
|
||||
let type_0 = {
|
||||
assert_magic(reader.read_u8()?, 0xFF)?;
|
||||
let pickled_length = reader.read_u16::<LittleEndian>()?;
|
||||
assert_magic(reader.read_u8()?, 0x00)?;
|
||||
read_pickled(&mut reader, pickled_length as usize)?
|
||||
};
|
||||
Self::ReplayHeader(Box::new(ReplayHeader {
|
||||
summary,
|
||||
Self::Type0 {
|
||||
type_0,
|
||||
author_nickname,
|
||||
arena_unique_id,
|
||||
arena_type_id,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
8 => Self::EntityMethod(EntityMethod::new(payload)?),
|
||||
|
||||
_ => Self::Unknown {
|
||||
raw: payload,
|
||||
type_,
|
||||
},
|
||||
_ => Self::Unknown { raw: payload, type_ },
|
||||
};
|
||||
Ok(this)
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::models::data::Summary;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct ReplayHeader {
|
||||
pub summary: Summary,
|
||||
pub author_nickname: String,
|
||||
pub arena_unique_id: u64,
|
||||
pub arena_type_id: u32,
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub struct Subtype2f {}
|
||||
@@ -2,8 +2,9 @@ use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Looks like some sort of replay summary.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Summary {
|
||||
pub struct Type0 {
|
||||
#[serde(rename(deserialize = "playersBattleCategoriesIds"))]
|
||||
pub players_battle_categories_ids: HashMap<u32, (u8, u32)>,
|
||||
|
||||
Reference in new issue
Block a user