mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +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 {
|
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 {
|
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 {
|
match value {
|
||||||
GameEventValue::String(val) => Ok(val),
|
GameEventValue::String(val) => Ok(val),
|
||||||
_ => Err(ParseError::InvalidGameEvent {
|
_ => Err(ParseError::InvalidGameEvent {
|
||||||
expected_type: GameEventValueType::String,
|
expected_type: GameEventValueType::String,
|
||||||
name: name.to_string(),
|
name,
|
||||||
value,
|
value,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
@ -61,12 +61,12 @@ impl FromGameEventValue for String {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromGameEventValue for f32 {
|
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 {
|
match value {
|
||||||
GameEventValue::Float(val) => Ok(val),
|
GameEventValue::Float(val) => Ok(val),
|
||||||
_ => Err(ParseError::InvalidGameEvent {
|
_ => Err(ParseError::InvalidGameEvent {
|
||||||
expected_type: GameEventValueType::Float,
|
expected_type: GameEventValueType::Float,
|
||||||
name: name.to_string(),
|
name,
|
||||||
value,
|
value,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
@ -74,12 +74,12 @@ impl FromGameEventValue for f32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromGameEventValue for u32 {
|
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 {
|
match value {
|
||||||
GameEventValue::Long(val) => Ok(val),
|
GameEventValue::Long(val) => Ok(val),
|
||||||
_ => Err(ParseError::InvalidGameEvent {
|
_ => Err(ParseError::InvalidGameEvent {
|
||||||
expected_type: GameEventValueType::Long,
|
expected_type: GameEventValueType::Long,
|
||||||
name: name.to_string(),
|
name,
|
||||||
value,
|
value,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
@ -87,12 +87,12 @@ impl FromGameEventValue for u32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromGameEventValue for u16 {
|
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 {
|
match value {
|
||||||
GameEventValue::Short(val) => Ok(val),
|
GameEventValue::Short(val) => Ok(val),
|
||||||
_ => Err(ParseError::InvalidGameEvent {
|
_ => Err(ParseError::InvalidGameEvent {
|
||||||
expected_type: GameEventValueType::Short,
|
expected_type: GameEventValueType::Short,
|
||||||
name: name.to_string(),
|
name,
|
||||||
value,
|
value,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
@ -100,12 +100,12 @@ impl FromGameEventValue for u16 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromGameEventValue for u8 {
|
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 {
|
match value {
|
||||||
GameEventValue::Byte(val) => Ok(val),
|
GameEventValue::Byte(val) => Ok(val),
|
||||||
_ => Err(ParseError::InvalidGameEvent {
|
_ => Err(ParseError::InvalidGameEvent {
|
||||||
expected_type: GameEventValueType::Byte,
|
expected_type: GameEventValueType::Byte,
|
||||||
name: name.to_string(),
|
name,
|
||||||
value,
|
value,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
@ -113,12 +113,12 @@ impl FromGameEventValue for u8 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromGameEventValue for bool {
|
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 {
|
match value {
|
||||||
GameEventValue::Boolean(val) => Ok(val),
|
GameEventValue::Boolean(val) => Ok(val),
|
||||||
_ => Err(ParseError::InvalidGameEvent {
|
_ => Err(ParseError::InvalidGameEvent {
|
||||||
expected_type: GameEventValueType::Boolean,
|
expected_type: GameEventValueType::Boolean,
|
||||||
name: name.to_string(),
|
name,
|
||||||
value,
|
value,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
@ -126,12 +126,12 @@ impl FromGameEventValue for bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromGameEventValue for () {
|
impl FromGameEventValue for () {
|
||||||
fn from_value(value: GameEventValue, name: &str) -> Result<Self> {
|
fn from_value(value: GameEventValue, name: &'static str) -> Result<Self> {
|
||||||
match value {
|
match value {
|
||||||
GameEventValue::Local => Ok(()),
|
GameEventValue::Local => Ok(()),
|
||||||
_ => Err(ParseError::InvalidGameEvent {
|
_ => Err(ParseError::InvalidGameEvent {
|
||||||
expected_type: GameEventValueType::Local,
|
expected_type: GameEventValueType::Local,
|
||||||
name: name.to_string(),
|
name,
|
||||||
value,
|
value,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,12 @@ pub enum ParseError {
|
||||||
StringTableNotFound(u8),
|
StringTableNotFound(u8),
|
||||||
/// A unknown game event type was read
|
/// A unknown game event type was read
|
||||||
UnknownGameEvent(&'static str),
|
UnknownGameEvent(&'static str),
|
||||||
|
/// A malformed game event was read
|
||||||
|
MalformedGameEvent(GameEventError),
|
||||||
/// A read game event doesn't contain the expected values
|
/// A read game event doesn't contain the expected values
|
||||||
InvalidGameEvent {
|
InvalidGameEvent {
|
||||||
expected_type: GameEventValueType,
|
expected_type: GameEventValueType,
|
||||||
name: String,
|
name: &'static str,
|
||||||
value: GameEventValue,
|
value: GameEventValue,
|
||||||
},
|
},
|
||||||
/// Unexpected type of compressed data
|
/// Unexpected type of compressed data
|
||||||
|
|
@ -55,6 +57,11 @@ pub enum ParseError {
|
||||||
InvalidDemo(&'static str),
|
InvalidDemo(&'static str),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum GameEventError {
|
||||||
|
IncorrectValueCount,
|
||||||
|
}
|
||||||
|
|
||||||
impl From<ReadError> for ParseError {
|
impl From<ReadError> for ParseError {
|
||||||
fn from(err: ReadError) -> ParseError {
|
fn from(err: ReadError) -> ParseError {
|
||||||
ParseError::ReadError(err)
|
ParseError::ReadError(err)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,10 @@ pub use bitstream_reader::Result as ReadResult;
|
||||||
|
|
||||||
pub use crate::demo::{
|
pub use crate::demo::{
|
||||||
message::MessageType,
|
message::MessageType,
|
||||||
parser::{DemoParser, MatchState, MessageTypeAnalyser, Parse, ParseError, ParserState, Result},
|
parser::{
|
||||||
|
DemoParser, GameEventError, MatchState, MessageTypeAnalyser, Parse, ParseError,
|
||||||
|
ParserState, Result,
|
||||||
|
},
|
||||||
Demo, Stream,
|
Demo, Stream,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue