mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
better sendpropvaluetype error
This commit is contained in:
parent
d538d79368
commit
e678a35654
2 changed files with 29 additions and 8 deletions
|
|
@ -2,7 +2,7 @@ use crate::demo::gamevent::GameEventValueType;
|
|||
use crate::demo::message::gameevent::GameEventTypeId;
|
||||
use crate::demo::message::packetentities::EntityId;
|
||||
use crate::demo::packet::datatable::{ClassId, SendTableName};
|
||||
use crate::demo::sendprop::SendPropIdentifier;
|
||||
use crate::demo::sendprop::{SendPropIdentifier, SendPropValue};
|
||||
use bitbuffer::BitError;
|
||||
use err_derive::Error;
|
||||
use std::str::Utf8Error;
|
||||
|
|
@ -94,7 +94,10 @@ pub enum MalformedSendPropDefinitionError {
|
|||
#[error(display = "SendProp value out of range")]
|
||||
OutOfRange,
|
||||
#[error(display = "Wrong prop value type for definition")]
|
||||
WrongPropType,
|
||||
WrongPropType {
|
||||
expected: &'static str,
|
||||
value: SendPropValue,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
|
|
|||
|
|
@ -1031,7 +1031,10 @@ impl TryFrom<&SendPropValue> for i64 {
|
|||
fn try_from(value: &SendPropValue) -> std::result::Result<Self, Self::Error> {
|
||||
match value {
|
||||
SendPropValue::Integer(val) => Ok(*val),
|
||||
_ => Err(MalformedSendPropDefinitionError::WrongPropType),
|
||||
_ => Err(MalformedSendPropDefinitionError::WrongPropType {
|
||||
expected: "integer",
|
||||
value: value.clone(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1041,7 +1044,10 @@ impl TryFrom<&SendPropValue> for Vector {
|
|||
fn try_from(value: &SendPropValue) -> std::result::Result<Self, Self::Error> {
|
||||
match value {
|
||||
SendPropValue::Vector(val) => Ok(*val),
|
||||
_ => Err(MalformedSendPropDefinitionError::WrongPropType),
|
||||
_ => Err(MalformedSendPropDefinitionError::WrongPropType {
|
||||
expected: "vector",
|
||||
value: value.clone(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1051,7 +1057,10 @@ impl TryFrom<&SendPropValue> for VectorXY {
|
|||
fn try_from(value: &SendPropValue) -> std::result::Result<Self, Self::Error> {
|
||||
match value {
|
||||
SendPropValue::VectorXY(val) => Ok(*val),
|
||||
_ => Err(MalformedSendPropDefinitionError::WrongPropType),
|
||||
_ => Err(MalformedSendPropDefinitionError::WrongPropType {
|
||||
expected: "vectorxy",
|
||||
value: value.clone(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1061,7 +1070,10 @@ impl TryFrom<&SendPropValue> for f32 {
|
|||
fn try_from(value: &SendPropValue) -> std::result::Result<Self, Self::Error> {
|
||||
match value {
|
||||
SendPropValue::Float(val) => Ok(*val),
|
||||
_ => Err(MalformedSendPropDefinitionError::WrongPropType),
|
||||
_ => Err(MalformedSendPropDefinitionError::WrongPropType {
|
||||
expected: "float",
|
||||
value: value.clone(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1071,7 +1083,10 @@ impl<'a> TryFrom<&'a SendPropValue> for &'a str {
|
|||
fn try_from(value: &'a SendPropValue) -> std::result::Result<Self, Self::Error> {
|
||||
match value {
|
||||
SendPropValue::String(val) => Ok(val.as_str()),
|
||||
_ => Err(MalformedSendPropDefinitionError::WrongPropType),
|
||||
_ => Err(MalformedSendPropDefinitionError::WrongPropType {
|
||||
expected: "string",
|
||||
value: value.clone(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1081,7 +1096,10 @@ impl<'a> TryFrom<&'a SendPropValue> for &'a [SendPropValue] {
|
|||
fn try_from(value: &'a SendPropValue) -> std::result::Result<Self, Self::Error> {
|
||||
match value {
|
||||
SendPropValue::Array(val) => Ok(val.as_slice()),
|
||||
_ => Err(MalformedSendPropDefinitionError::WrongPropType),
|
||||
_ => Err(MalformedSendPropDefinitionError::WrongPropType {
|
||||
expected: "array",
|
||||
value: value.clone(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue