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-08 23:39:52 +02:00
/// Parse the entity method raw payload.
2023-05-08 23:14:13 +02:00
pub fn new(raw_payload: &[u8]) -> Result<Self> {
let mut raw_payload = raw_payload;
2023-04-29 22:17:12 +02:00
2023-05-08 23:14:13 +02:00
raw_payload.read_u32::<LittleEndian>()?;
let sub_type = raw_payload.read_u32::<LittleEndian>()?;
2023-04-29 22:17:12 +02:00
let this = match sub_type {
47 => {
2023-05-08 23:14:13 +02:00
let _inner_length = raw_payload.read_u32::<LittleEndian>()?;
2023-04-30 22:13:51 +02:00
2023-05-08 23:14:13 +02:00
let field_number = decode_varint(&mut raw_payload)?;
let message_length = read_quirky_length(&mut raw_payload)?;
2023-05-03 15:25:33 +02:00
Self::UpdateArena {
2023-04-30 22:13:51 +02:00
field_number,
2023-05-08 23:14:13 +02:00
arguments: UpdateArena::decode(&raw_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)
}
}