1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-03 10:14:06 +02:00

accept different size int game event values for improved backwards compatibility

This commit is contained in:
Robin Appelman 2020-01-20 12:40:18 +01:00
commit fcccdd8505

View file

@ -116,6 +116,8 @@ impl FromGameEventValue for u32 {
fn from_value(value: Option<GameEventValue>, name: &'static str) -> Result<Self> { fn from_value(value: Option<GameEventValue>, name: &'static str) -> Result<Self> {
match value { match value {
Some(GameEventValue::Long(val)) => Ok(val), Some(GameEventValue::Long(val)) => Ok(val),
Some(GameEventValue::Short(val)) => Ok(val as u32),
Some(GameEventValue::Byte(val)) => Ok(val as u32),
None => Ok(u32::default()), None => Ok(u32::default()),
Some(value) => Err(ParseError::InvalidGameEvent { Some(value) => Err(ParseError::InvalidGameEvent {
expected_type: GameEventValueType::Long, expected_type: GameEventValueType::Long,
@ -129,7 +131,9 @@ impl FromGameEventValue for u32 {
impl FromGameEventValue for u16 { impl FromGameEventValue for u16 {
fn from_value(value: Option<GameEventValue>, name: &'static str) -> Result<Self> { fn from_value(value: Option<GameEventValue>, name: &'static str) -> Result<Self> {
match value { match value {
Some(GameEventValue::Long(val)) => Ok(val as u16),
Some(GameEventValue::Short(val)) => Ok(val), Some(GameEventValue::Short(val)) => Ok(val),
Some(GameEventValue::Byte(val)) => Ok(val as u16),
None => Ok(u16::default()), None => Ok(u16::default()),
Some(value) => Err(ParseError::InvalidGameEvent { Some(value) => Err(ParseError::InvalidGameEvent {
expected_type: GameEventValueType::Short, expected_type: GameEventValueType::Short,
@ -143,6 +147,8 @@ impl FromGameEventValue for u16 {
impl FromGameEventValue for u8 { impl FromGameEventValue for u8 {
fn from_value(value: Option<GameEventValue>, name: &'static str) -> Result<Self> { fn from_value(value: Option<GameEventValue>, name: &'static str) -> Result<Self> {
match value { match value {
Some(GameEventValue::Long(val)) => Ok(val as u8),
Some(GameEventValue::Short(val)) => Ok(val as u8),
Some(GameEventValue::Byte(val)) => Ok(val), Some(GameEventValue::Byte(val)) => Ok(val),
None => Ok(u8::default()), None => Ok(u8::default()),
Some(value) => Err(ParseError::InvalidGameEvent { Some(value) => Err(ParseError::InvalidGameEvent {