Break: refactor the models

This commit is contained in:
Pavel Perestoronin committed 2022-12-03 17:48:42 +01:00
1 parent 583ca024fc
commit 21206737c0
8 files changed
+83 -37

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
use prost::bytes::Buf;
use prost::Message;
use crate::error::Error;
use crate::result::Result;
impl BattleResults {
/// Parse battle results from the buffer.
///
/// Note, that this does NOT parse `battle_results.dat` itself, but the un-pickled tuple element.
pub fn parse(buffer: impl Buf) -> Result<Self> {
Self::decode(buffer).map_err(Error::DecodeFailed)
}
}
#[derive(Message)]
pub struct BattleResults {
#[prost(int64, tag = "2")]
pub timestamp: i64,
#[prost(message, repeated, tag = "201")]
pub players: Vec<Player>,
}
#[derive(Message)]
pub struct Player {
#[prost(uint32, tag = "1")]
pub account_id: u32,
#[prost(message, required, tag = "2")]
pub info: PlayerInfo,
}
#[derive(Message)]
pub struct PlayerInfo {
#[prost(string, tag = "1")]
pub nickname: String,
#[prost(uint32, optional, tag = "2")]
pub platoon_id: Option<u32>,
#[prost(uint32, tag = "3")]
pub team_number: u32,
}
+6
View File
@@ -0,0 +1,6 @@
use serde::Deserialize;
use serde_bytes::ByteBuf;
/// Represents un-pickled `battle_results.dat`.
#[derive(Debug, Deserialize)]
pub struct BattleResultsDat(pub(crate) u64, pub(crate) ByteBuf);