Break: restructure the code

This commit is contained in:
eigenein committed 2023-05-03 15:25:33 +02:00
1 parent 897f98c17c
commit 1830536224
7 files changed
+23 -20

No files matched your search

@@ -2,9 +2,8 @@ use std::collections::HashMap;
use serde::{Deserialize, Serialize};
/// Looks like some sort of replay summary.
#[derive(Debug, Serialize, Deserialize)]
pub struct Type0 {
pub struct BasePlayerCreate {
#[serde(rename(deserialize = "playersBattleCategoriesIds"))]
pub players_battle_categories_ids: HashMap<u32, (u8, u32)>,
+9 -5
View File
@@ -4,16 +4,19 @@ use prost::Message;
use serde::Serialize;
use serde_with::serde_as;
use self::update_arena::UpdateArena;
use crate::models::data::read_quirky_length;
use crate::models::data::update_arena::UpdateArena;
use crate::result::Result;
pub mod update_arena;
#[serde_as]
#[derive(Debug, Serialize)]
pub enum EntityMethod {
Subtype2F {
/// Subtype `0x2F`.
UpdateArena {
field_number: u64,
sub_type_2f: UpdateArena,
arguments: UpdateArena,
/// Original payload for investigation.
#[serde_as(as = "serde_with::hex::Hex")]
@@ -31,6 +34,7 @@ pub enum EntityMethod {
}
impl EntityMethod {
/// Parse the entity method payload.
pub fn new(payload: Vec<u8>) -> Result<Self> {
let mut reader = payload.as_slice();
@@ -43,9 +47,9 @@ impl EntityMethod {
let field_number = decode_varint(&mut reader)?;
let message_length = read_quirky_length(&mut reader)?;
Self::Subtype2F {
Self::UpdateArena {
field_number,
sub_type_2f: UpdateArena::decode(&reader[..message_length])?,
arguments: UpdateArena::decode(&reader[..message_length])?,
payload,
}
}
@@ -1,7 +1,6 @@
use prost::Message;
use serde::Serialize;
/// Subtype `0x2F`.
#[derive(Message, Serialize)]
pub struct UpdateArena {
#[prost(message, tag = "1")]
+7 -6
View File
@@ -4,22 +4,23 @@ use byteorder::{LittleEndian, ReadBytesExt};
use serde::Serialize;
use serde_with::serde_as;
use crate::models::data::base_player_create::BasePlayerCreate;
use crate::models::data::entity_method::EntityMethod;
use crate::models::data::type_0::Type0;
use crate::models::data::{read_pickled, read_quirky_length, read_string};
use crate::result::Result;
#[serde_as]
#[derive(Debug, Serialize)]
pub enum Payload {
/// Looks like some sort of replay summary.
Type0 {
/// Type 0.
BasePlayerCreate {
author_nickname: String,
arena_unique_id: u64,
arena_type_id: u32,
type_0: Box<Type0>,
arguments: Box<BasePlayerCreate>,
},
/// Type 8.
EntityMethod(EntityMethod),
/// Default payload when type is not known by the parser.
@@ -46,8 +47,8 @@ impl Payload {
let pickled_length = read_quirky_length(&mut reader)?;
read_pickled(&mut reader, pickled_length)?
};
Self::Type0 {
type_0,
Self::BasePlayerCreate {
arguments: type_0,
author_nickname,
arena_unique_id,
arena_type_id,