1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-04 02:24:12 +02:00

some error refactoring

This commit is contained in:
Robin Appelman 2019-08-23 12:31:51 +02:00
commit 77180520ef
12 changed files with 1671 additions and 1298 deletions

View file

@ -1,7 +1,8 @@
use bitstream_reader::{BitRead, LittleEndian};
use crate::demo::parser::MalformedSendPropDefinitionError;
use crate::demo::sendprop::{SendPropDefinition, SendPropFlag, SendPropName, SendPropType};
use crate::{Parse, ParseError, ParserState, ReadResult, Result, Stream};
use crate::{MalformedDemoError, Parse, ParseError, ParserState, ReadResult, Result, Stream};
use serde::{Deserialize, Serialize};
use std::cell::{Cell, RefCell};
use std::fmt;
@ -63,16 +64,12 @@ impl Parse for ParseSendTable {
let prop: SendPropDefinition = SendPropDefinition::read(stream, name.clone())?;
if prop.flags.contains(SendPropFlag::InsideArray) {
if array_element_prop.is_some() || prop.flags.contains(SendPropFlag::ChangesOften) {
return Err(ParseError::InvalidSendProp(
"Array contents can't have the 'ChangesOften' flag",
));
return Err(MalformedSendPropDefinitionError::ArrayChangesOften.into());
}
array_element_prop = Some(prop);
} else if let Some(array_element) = array_element_prop {
if prop.prop_type != SendPropType::Array {
return Err(ParseError::InvalidSendProp(
"Array contents can without array",
));
return Err(MalformedSendPropDefinitionError::UntypedArray.into());
}
array_element_prop = None;
props.push(prop.with_array_property(array_element));
@ -222,7 +219,7 @@ impl Parse for DataTablePacket {
let server_classes = packet_data.read_sized(server_class_count)?;
if packet_data.bits_left() > 7 {
Err(ParseError::DataRemaining(packet_data.bits_left()))
Err(MalformedDemoError::DataRemaining(packet_data.bits_left()).into())
} else {
Ok(DataTablePacket {
tick,

View file

@ -3,10 +3,10 @@ use std::fmt;
use bitstream_reader::{BitRead, LittleEndian};
use crate::demo::message::stringtable::StringTableMeta;
use crate::{Parse, ParseError, ParserState, ReadResult, Result, Stream};
use crate::{MalformedDemoError, Parse, ParseError, ParserState, ReadResult, Result, Stream};
#[derive(BitRead, Clone, Copy, Debug)]
pub struct FixedUserdataSize {
pub struct FixedUserDataSize {
#[size = 12]
pub size: u16,
#[size = 4]
@ -18,7 +18,7 @@ pub struct StringTable {
pub name: String,
pub entries: Vec<(u16, StringTableEntry)>,
pub max_entries: u16,
pub fixed_userdata_size: Option<FixedUserdataSize>,
pub fixed_user_data_size: Option<FixedUserDataSize>,
pub client_entries: Option<Vec<StringTableEntry>>,
pub compressed: bool,
}
@ -26,7 +26,7 @@ pub struct StringTable {
impl StringTable {
pub fn get_table_meta(&self) -> StringTableMeta {
StringTableMeta {
fixed_userdata_size: self.fixed_userdata_size,
fixed_userdata_size: self.fixed_user_data_size,
max_entries: self.max_entries,
}
}
@ -53,7 +53,7 @@ impl BitRead<LittleEndian> for StringTable {
name,
entries,
max_entries: entry_count,
fixed_userdata_size: None,
fixed_user_data_size: None,
client_entries,
compressed: false,
})
@ -125,7 +125,7 @@ impl Parse for StringTablePacket {
let tables = packet_data.read_sized(count)?;
if packet_data.bits_left() > 7 {
Err(ParseError::DataRemaining(packet_data.bits_left()))
Err(MalformedDemoError::DataRemaining(packet_data.bits_left()).into())
} else {
Ok(StringTablePacket { tick, tables })
}