mirror of
https://github.com/eigenein/wotbreplay-parser.git
synced 2026-10-21 10:27:01 +02:00
💥 Improve the docs and error handling
This commit is contained in:
1 parent
838a49ee68
commit
c986abca5d
10 files changed
+58
-19
No files matched your search
@@ -6,6 +6,7 @@ use serde_with::serde_as;
|
||||
|
||||
use crate::models::data::payload::Payload;
|
||||
use crate::result::Result;
|
||||
use crate::Error;
|
||||
|
||||
/// «Packet» is a single traffic message in a replay,
|
||||
/// packets tell us what is going on during the battle.
|
||||
@@ -28,14 +29,26 @@ pub struct Packet {
|
||||
}
|
||||
|
||||
impl Packet {
|
||||
/// Parse next packet from the reader.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Parsed packet, or [`None`], when no packets are left.
|
||||
pub fn from_reader(reader: &mut impl Read) -> Result<Option<Self>> {
|
||||
let Ok(length) = reader.read_u32::<LittleEndian>() else { return Ok(None) };
|
||||
let type_ = reader.read_u32::<LittleEndian>()?;
|
||||
let clock_secs = reader.read_f32::<LittleEndian>()?;
|
||||
let raw_payload = Self::read_raw_payload(reader, length as usize)?;
|
||||
let payload = Payload::new(type_, &raw_payload).map_err(|source| {
|
||||
Error::PacketPayloadParsingError {
|
||||
source: Box::new(source),
|
||||
type_,
|
||||
clock_secs,
|
||||
}
|
||||
})?;
|
||||
let this = Self {
|
||||
clock_secs,
|
||||
payload: Payload::new(type_, &raw_payload)?,
|
||||
payload,
|
||||
|
||||
#[cfg(feature = "raw-payload")]
|
||||
raw_payload,
|
||||
|
||||
Reference in new issue
Block a user