mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
dont clone game event values
This commit is contained in:
parent
a9c76eb27c
commit
50f3690e3a
4 changed files with 6086 additions and 4248 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -44,16 +44,16 @@ pub enum GameEventValue {
|
|||
}
|
||||
|
||||
pub trait FromGameEventValue: Sized {
|
||||
fn from_value(value: GameEventValue, name: &str) -> Result<Self>;
|
||||
fn from_value(value: GameEventValue, name: &'static str) -> Result<Self>;
|
||||
}
|
||||
|
||||
impl FromGameEventValue for String {
|
||||
fn from_value(value: GameEventValue, name: &str) -> Result<Self> {
|
||||
fn from_value(value: GameEventValue, name: &'static str) -> Result<Self> {
|
||||
match value {
|
||||
GameEventValue::String(val) => Ok(val),
|
||||
_ => Err(ParseError::InvalidGameEvent {
|
||||
expected_type: GameEventValueType::String,
|
||||
name: name.to_string(),
|
||||
name,
|
||||
value,
|
||||
}),
|
||||
}
|
||||
|
|
@ -61,12 +61,12 @@ impl FromGameEventValue for String {
|
|||
}
|
||||
|
||||
impl FromGameEventValue for f32 {
|
||||
fn from_value(value: GameEventValue, name: &str) -> Result<Self> {
|
||||
fn from_value(value: GameEventValue, name: &'static str) -> Result<Self> {
|
||||
match value {
|
||||
GameEventValue::Float(val) => Ok(val),
|
||||
_ => Err(ParseError::InvalidGameEvent {
|
||||
expected_type: GameEventValueType::Float,
|
||||
name: name.to_string(),
|
||||
name,
|
||||
value,
|
||||
}),
|
||||
}
|
||||
|
|
@ -74,12 +74,12 @@ impl FromGameEventValue for f32 {
|
|||
}
|
||||
|
||||
impl FromGameEventValue for u32 {
|
||||
fn from_value(value: GameEventValue, name: &str) -> Result<Self> {
|
||||
fn from_value(value: GameEventValue, name: &'static str) -> Result<Self> {
|
||||
match value {
|
||||
GameEventValue::Long(val) => Ok(val),
|
||||
_ => Err(ParseError::InvalidGameEvent {
|
||||
expected_type: GameEventValueType::Long,
|
||||
name: name.to_string(),
|
||||
name,
|
||||
value,
|
||||
}),
|
||||
}
|
||||
|
|
@ -87,12 +87,12 @@ impl FromGameEventValue for u32 {
|
|||
}
|
||||
|
||||
impl FromGameEventValue for u16 {
|
||||
fn from_value(value: GameEventValue, name: &str) -> Result<Self> {
|
||||
fn from_value(value: GameEventValue, name: &'static str) -> Result<Self> {
|
||||
match value {
|
||||
GameEventValue::Short(val) => Ok(val),
|
||||
_ => Err(ParseError::InvalidGameEvent {
|
||||
expected_type: GameEventValueType::Short,
|
||||
name: name.to_string(),
|
||||
name,
|
||||
value,
|
||||
}),
|
||||
}
|
||||
|
|
@ -100,12 +100,12 @@ impl FromGameEventValue for u16 {
|
|||
}
|
||||
|
||||
impl FromGameEventValue for u8 {
|
||||
fn from_value(value: GameEventValue, name: &str) -> Result<Self> {
|
||||
fn from_value(value: GameEventValue, name: &'static str) -> Result<Self> {
|
||||
match value {
|
||||
GameEventValue::Byte(val) => Ok(val),
|
||||
_ => Err(ParseError::InvalidGameEvent {
|
||||
expected_type: GameEventValueType::Byte,
|
||||
name: name.to_string(),
|
||||
name,
|
||||
value,
|
||||
}),
|
||||
}
|
||||
|
|
@ -113,12 +113,12 @@ impl FromGameEventValue for u8 {
|
|||
}
|
||||
|
||||
impl FromGameEventValue for bool {
|
||||
fn from_value(value: GameEventValue, name: &str) -> Result<Self> {
|
||||
fn from_value(value: GameEventValue, name: &'static str) -> Result<Self> {
|
||||
match value {
|
||||
GameEventValue::Boolean(val) => Ok(val),
|
||||
_ => Err(ParseError::InvalidGameEvent {
|
||||
expected_type: GameEventValueType::Boolean,
|
||||
name: name.to_string(),
|
||||
name,
|
||||
value,
|
||||
}),
|
||||
}
|
||||
|
|
@ -126,12 +126,12 @@ impl FromGameEventValue for bool {
|
|||
}
|
||||
|
||||
impl FromGameEventValue for () {
|
||||
fn from_value(value: GameEventValue, name: &str) -> Result<Self> {
|
||||
fn from_value(value: GameEventValue, name: &'static str) -> Result<Self> {
|
||||
match value {
|
||||
GameEventValue::Local => Ok(()),
|
||||
_ => Err(ParseError::InvalidGameEvent {
|
||||
expected_type: GameEventValueType::Local,
|
||||
name: name.to_string(),
|
||||
name,
|
||||
value,
|
||||
}),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,10 +34,12 @@ pub enum ParseError {
|
|||
StringTableNotFound(u8),
|
||||
/// A unknown game event type was read
|
||||
UnknownGameEvent(&'static str),
|
||||
/// A malformed game event was read
|
||||
MalformedGameEvent(GameEventError),
|
||||
/// A read game event doesn't contain the expected values
|
||||
InvalidGameEvent {
|
||||
expected_type: GameEventValueType,
|
||||
name: String,
|
||||
name: &'static str,
|
||||
value: GameEventValue,
|
||||
},
|
||||
/// Unexpected type of compressed data
|
||||
|
|
@ -55,6 +57,11 @@ pub enum ParseError {
|
|||
InvalidDemo(&'static str),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum GameEventError {
|
||||
IncorrectValueCount,
|
||||
}
|
||||
|
||||
impl From<ReadError> for ParseError {
|
||||
fn from(err: ReadError) -> ParseError {
|
||||
ParseError::ReadError(err)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,10 @@ pub use bitstream_reader::Result as ReadResult;
|
|||
|
||||
pub use crate::demo::{
|
||||
message::MessageType,
|
||||
parser::{DemoParser, MatchState, MessageTypeAnalyser, Parse, ParseError, ParserState, Result},
|
||||
parser::{
|
||||
DemoParser, GameEventError, MatchState, MessageTypeAnalyser, Parse, ParseError,
|
||||
ParserState, Result,
|
||||
},
|
||||
Demo, Stream,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue