mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
better gameevent errors
This commit is contained in:
parent
2a582197f6
commit
d7172a14cd
3 changed files with 11 additions and 3 deletions
|
|
@ -5,7 +5,7 @@ use std::fs;
|
||||||
pub use tf_demo_parser::{Demo, DemoParser, Parse, ParseError, ParserState, Result, Stream};
|
pub use tf_demo_parser::{Demo, DemoParser, Parse, ParseError, ParserState, Result, Stream};
|
||||||
|
|
||||||
fn main() -> std::result::Result<(), Box<ParseError>> {
|
fn main() -> std::result::Result<(), Box<ParseError>> {
|
||||||
let file = fs::read("data/gully.dem").expect("Unable to read file");
|
let file = fs::read("data/ash.dem").expect("Unable to read file");
|
||||||
let demo = Demo::new(file);
|
let demo = Demo::new(file);
|
||||||
let stream: Stream = demo.get_stream();
|
let stream: Stream = demo.get_stream();
|
||||||
let mut parser = DemoParser::new(stream);
|
let mut parser = DemoParser::new(stream);
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ impl FromGameEventValue for String {
|
||||||
match value {
|
match value {
|
||||||
GameEventValue::String(val) => Ok(val),
|
GameEventValue::String(val) => Ok(val),
|
||||||
_ => Err(ParseError::InvalidGameEvent {
|
_ => Err(ParseError::InvalidGameEvent {
|
||||||
|
expected_type: GameEventValueType::String,
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
value,
|
value,
|
||||||
}),
|
}),
|
||||||
|
|
@ -63,6 +64,7 @@ impl FromGameEventValue for f32 {
|
||||||
match value {
|
match value {
|
||||||
GameEventValue::Float(val) => Ok(val),
|
GameEventValue::Float(val) => Ok(val),
|
||||||
_ => Err(ParseError::InvalidGameEvent {
|
_ => Err(ParseError::InvalidGameEvent {
|
||||||
|
expected_type: GameEventValueType::Float,
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
value,
|
value,
|
||||||
}),
|
}),
|
||||||
|
|
@ -75,6 +77,7 @@ impl FromGameEventValue for u32 {
|
||||||
match value {
|
match value {
|
||||||
GameEventValue::Long(val) => Ok(val),
|
GameEventValue::Long(val) => Ok(val),
|
||||||
_ => Err(ParseError::InvalidGameEvent {
|
_ => Err(ParseError::InvalidGameEvent {
|
||||||
|
expected_type: GameEventValueType::Long,
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
value,
|
value,
|
||||||
}),
|
}),
|
||||||
|
|
@ -87,6 +90,7 @@ impl FromGameEventValue for u16 {
|
||||||
match value {
|
match value {
|
||||||
GameEventValue::Short(val) => Ok(val),
|
GameEventValue::Short(val) => Ok(val),
|
||||||
_ => Err(ParseError::InvalidGameEvent {
|
_ => Err(ParseError::InvalidGameEvent {
|
||||||
|
expected_type: GameEventValueType::Short,
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
value,
|
value,
|
||||||
}),
|
}),
|
||||||
|
|
@ -99,6 +103,7 @@ impl FromGameEventValue for u8 {
|
||||||
match value {
|
match value {
|
||||||
GameEventValue::Byte(val) => Ok(val),
|
GameEventValue::Byte(val) => Ok(val),
|
||||||
_ => Err(ParseError::InvalidGameEvent {
|
_ => Err(ParseError::InvalidGameEvent {
|
||||||
|
expected_type: GameEventValueType::Byte,
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
value,
|
value,
|
||||||
}),
|
}),
|
||||||
|
|
@ -111,6 +116,7 @@ impl FromGameEventValue for bool {
|
||||||
match value {
|
match value {
|
||||||
GameEventValue::Boolean(val) => Ok(val),
|
GameEventValue::Boolean(val) => Ok(val),
|
||||||
_ => Err(ParseError::InvalidGameEvent {
|
_ => Err(ParseError::InvalidGameEvent {
|
||||||
|
expected_type: GameEventValueType::Boolean,
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
value,
|
value,
|
||||||
}),
|
}),
|
||||||
|
|
@ -123,6 +129,7 @@ impl FromGameEventValue for () {
|
||||||
match value {
|
match value {
|
||||||
GameEventValue::Local => Ok(()),
|
GameEventValue::Local => Ok(()),
|
||||||
_ => Err(ParseError::InvalidGameEvent {
|
_ => Err(ParseError::InvalidGameEvent {
|
||||||
|
expected_type: GameEventValueType::Local,
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
value,
|
value,
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use std::rc::Rc;
|
||||||
|
|
||||||
use bitstream_reader::{BitRead, LittleEndian, ReadError};
|
use bitstream_reader::{BitRead, LittleEndian, ReadError};
|
||||||
|
|
||||||
use crate::demo::gamevent::GameEventValue;
|
use crate::demo::gamevent::{GameEventValue, GameEventValueType};
|
||||||
use crate::demo::header::Header;
|
use crate::demo::header::Header;
|
||||||
use crate::demo::message::{Message, MessageType};
|
use crate::demo::message::{Message, MessageType};
|
||||||
use crate::demo::packet::stringtable::StringTableEntry;
|
use crate::demo::packet::stringtable::StringTableEntry;
|
||||||
|
|
@ -14,6 +14,7 @@ pub use crate::demo::parser::state::ParserState;
|
||||||
use crate::Stream;
|
use crate::Stream;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use crate::demo::gameevent_gen::GameEventType;
|
||||||
|
|
||||||
mod analyser;
|
mod analyser;
|
||||||
mod handler;
|
mod handler;
|
||||||
|
|
@ -39,7 +40,7 @@ pub enum ParseError {
|
||||||
/// A unknown game event type was read
|
/// A unknown game event type was read
|
||||||
UnknownGameEvent(String),
|
UnknownGameEvent(String),
|
||||||
/// A read game event doesn't contain the expected values
|
/// A read game event doesn't contain the expected values
|
||||||
InvalidGameEvent { name: String, value: GameEventValue },
|
InvalidGameEvent { expected_type: GameEventValueType, name: String, value: GameEventValue },
|
||||||
/// Unexpected type of compressed data
|
/// Unexpected type of compressed data
|
||||||
UnexpectedCompressionType(String),
|
UnexpectedCompressionType(String),
|
||||||
/// Error while decompressing SNAP compressed string table
|
/// Error while decompressing SNAP compressed string table
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue