Files
wotbreplay-parser/src/models/data/entity_method.rs
T

52 lines
1.4 KiB
Rust
Raw Normal View History

//! Structures for «entity method» call packets.
2023-04-29 22:17:12 +02:00
use byteorder::{LittleEndian, ReadBytesExt};
2023-04-30 22:13:51 +02:00
use prost::encoding::decode_varint;
use prost::Message;
2023-04-29 22:17:12 +02:00
use serde::Serialize;
use serde_with::serde_as;
2023-04-29 22:17:12 +02:00
2023-05-03 15:25:33 +02:00
use self::update_arena::UpdateArena;
2023-04-30 22:13:51 +02:00
use crate::models::data::read_quirky_length;
2023-04-29 22:17:12 +02:00
use crate::result::Result;
2023-05-03 15:25:33 +02:00
pub mod update_arena;
#[serde_as]
2023-04-29 22:17:12 +02:00
#[derive(Debug, Serialize)]
pub enum EntityMethod {
/// Subtype 47.
2023-05-03 15:25:33 +02:00
UpdateArena {
2023-04-30 22:13:51 +02:00
field_number: u64,
2023-05-03 15:25:33 +02:00
arguments: UpdateArena,
2023-04-30 19:32:35 +02:00
},
2023-04-29 22:17:12 +02:00
2023-04-30 19:32:35 +02:00
/// Default variant when subtype is not known by the parser.
Unknown { sub_type: u32 },
2023-04-29 22:17:12 +02:00
}
impl EntityMethod {
2023-05-03 15:25:33 +02:00
/// Parse the entity method payload.
pub fn new(payload: &[u8]) -> Result<Self> {
let mut payload = payload;
2023-04-29 22:17:12 +02:00
payload.read_u32::<LittleEndian>()?;
let sub_type = payload.read_u32::<LittleEndian>()?;
2023-04-29 22:17:12 +02:00
let this = match sub_type {
47 => {
let _inner_length = payload.read_u32::<LittleEndian>()?;
2023-04-30 22:13:51 +02:00
let field_number = decode_varint(&mut payload)?;
let message_length = read_quirky_length(&mut payload)?;
2023-05-03 15:25:33 +02:00
Self::UpdateArena {
2023-04-30 22:13:51 +02:00
field_number,
arguments: UpdateArena::decode(&payload[..message_length])?,
2023-04-30 22:13:51 +02:00
}
2023-04-30 19:32:35 +02:00
}
_ => Self::Unknown { sub_type },
2023-04-29 22:17:12 +02:00
};
Ok(this)
}
}