mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
minor cleanip
This commit is contained in:
parent
c9781dc15e
commit
a333e26a6d
5 changed files with 54 additions and 55 deletions
|
|
@ -18,6 +18,49 @@ pub struct SendTable {
|
|||
pub flattened_props: Option<Vec<SendPropDefinition>>,
|
||||
}
|
||||
|
||||
impl Parse for SendTable {
|
||||
fn parse(stream: &mut Stream, _state: &ParserState) -> Result<Self> {
|
||||
let needs_decoder = stream.read()?;
|
||||
let name: String = stream.read()?;
|
||||
let prop_count = stream.read_int(10)?;
|
||||
|
||||
let mut array_element_prop = None;
|
||||
let mut props = Vec::with_capacity(prop_count);
|
||||
|
||||
for _ in 0..prop_count {
|
||||
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::InvalidSendPropArray(
|
||||
"Array contents can't have the 'ChangesOften' flag".to_owned(),
|
||||
));
|
||||
}
|
||||
array_element_prop = Some(prop);
|
||||
} else if let Some(array_element) = array_element_prop {
|
||||
if prop.prop_type != SendPropType::Array {
|
||||
return Err(ParseError::InvalidSendPropArray(
|
||||
"Array contents can without array".to_owned(),
|
||||
));
|
||||
}
|
||||
array_element_prop = None;
|
||||
props.push(prop.with_array_property(array_element));
|
||||
} else {
|
||||
props.push(prop);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(SendTable {
|
||||
name,
|
||||
flattened_props: None,
|
||||
needs_decoder,
|
||||
props,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DataTablePacket {
|
||||
pub tick: u32,
|
||||
|
|
@ -26,51 +69,14 @@ pub struct DataTablePacket {
|
|||
}
|
||||
|
||||
impl Parse for DataTablePacket {
|
||||
fn parse(stream: &mut Stream, _state: &ParserState) -> Result<Self> {
|
||||
fn parse(stream: &mut Stream, state: &ParserState) -> Result<Self> {
|
||||
let tick = stream.read()?;
|
||||
let len = stream.read_int::<usize>(32)?;
|
||||
let mut packet_data = stream.read_bits(len * 8)?;
|
||||
|
||||
let mut tables = vec![];
|
||||
let mut tables = Vec::new();
|
||||
while packet_data.read_bool()? {
|
||||
let needs_decoder = packet_data.read()?;
|
||||
let name: String = packet_data.read()?;
|
||||
let prop_count = packet_data.read_int(10)?;
|
||||
|
||||
let mut array_element_prop = None;
|
||||
let mut props = Vec::with_capacity(prop_count);
|
||||
|
||||
for _ in 0..prop_count {
|
||||
let prop: SendPropDefinition =
|
||||
SendPropDefinition::read(&mut packet_data, name.clone())?;
|
||||
if prop.flags.contains(SendPropFlag::InsideArray) {
|
||||
if array_element_prop.is_some()
|
||||
|| prop.flags.contains(SendPropFlag::ChangesOften)
|
||||
{
|
||||
return Err(ParseError::InvalidSendPropArray(
|
||||
"Array contents can't have the 'ChangesOften' flag".to_owned(),
|
||||
));
|
||||
}
|
||||
array_element_prop = Some(prop);
|
||||
} else if let Some(array_element) = array_element_prop {
|
||||
if prop.prop_type != SendPropType::Array {
|
||||
return Err(ParseError::InvalidSendPropArray(
|
||||
"Array contents can without array".to_owned(),
|
||||
));
|
||||
}
|
||||
array_element_prop = None;
|
||||
props.push(prop.with_array_property(array_element));
|
||||
} else {
|
||||
props.push(prop);
|
||||
}
|
||||
}
|
||||
|
||||
let table = SendTable {
|
||||
name,
|
||||
flattened_props: None,
|
||||
needs_decoder,
|
||||
props,
|
||||
};
|
||||
let table = SendTable::parse(&mut packet_data, state)?;
|
||||
tables.push(table);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -87,15 +87,10 @@ impl DemoParser {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn read<T: Parse>(&mut self) -> Result<T> {
|
||||
T::parse(&mut self.stream, self.handler.get_parser_state())
|
||||
}
|
||||
|
||||
pub fn parse_demo(mut self) -> Result<(Header, MatchState)> {
|
||||
let header = self.read::<Header>()?;
|
||||
let header = Header::read(&mut self.stream)?;
|
||||
loop {
|
||||
let packet = self.read::<Packet>()?;
|
||||
let packet = Packet::parse(&mut self.stream, self.handler.get_parser_state())?;
|
||||
match packet {
|
||||
Packet::Stop(_) => break,
|
||||
packet => self.handler.handle_packet(packet),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue