Break: refactor the packet payloads

This commit is contained in:
eigenein committed 2023-04-30 19:32:35 +02:00
1 parent 9d601082d6
commit e48fe1dd0d
8 files changed
+70 -70

No files matched your search

+12 -4
View File
@@ -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
View File
@@ -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)
}
-11
View File
@@ -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,
}
+1
View File
@@ -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)>,