mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
make parserstate static
This commit is contained in:
parent
25f24b63f6
commit
e5e54de65d
8 changed files with 20 additions and 20 deletions
|
|
@ -101,7 +101,7 @@ pub enum Message<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Parse<'a> for Message<'a> {
|
||||
fn parse(stream: &mut Stream<'a>, state: &ParserState<'a>) -> Result<Self> {
|
||||
fn parse(stream: &mut Stream<'a>, state: &ParserState) -> Result<Self> {
|
||||
let message_type = MessageType::parse(stream, state)?;
|
||||
Self::from_type(message_type, stream, state)
|
||||
}
|
||||
|
|
@ -144,7 +144,7 @@ impl<'a> Message<'a> {
|
|||
pub fn from_type(
|
||||
message_type: MessageType,
|
||||
stream: &mut Stream<'a>,
|
||||
state: &ParserState<'a>,
|
||||
state: &ParserState,
|
||||
) -> Result<Self> {
|
||||
Ok(match message_type {
|
||||
MessageType::Empty => Message::Empty,
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ pub struct PacketEntitiesMessage {
|
|||
pub updated_base_line: bool,
|
||||
}
|
||||
|
||||
fn get_send_table<'a, 'b>(state: &'b ParserState<'a>, class: ClassId) -> Result<&'b SendTable> {
|
||||
fn get_send_table<'a, 'b>(state: &'b ParserState, class: ClassId) -> Result<&'b SendTable> {
|
||||
state
|
||||
.send_tables
|
||||
.get(usize::from(class))
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ impl From<&StringTable<'_>> for StringTableMeta {
|
|||
}
|
||||
|
||||
impl<'a> Parse<'a> for CreateStringTableMessage<'a> {
|
||||
fn parse(stream: &mut Stream<'a>, _state: &ParserState<'a>) -> Result<Self> {
|
||||
fn parse(stream: &mut Stream<'a>, _state: &ParserState) -> Result<Self> {
|
||||
let name = stream.read()?;
|
||||
let max_entries: u16 = stream.read()?;
|
||||
let encode_bits = log_base2(max_entries);
|
||||
|
|
@ -116,7 +116,7 @@ pub struct UpdateStringTableMessage<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Parse<'a> for UpdateStringTableMessage<'a> {
|
||||
fn parse(stream: &mut Stream<'a>, state: &ParserState<'a>) -> Result<Self> {
|
||||
fn parse(stream: &mut Stream<'a>, state: &ParserState) -> Result<Self> {
|
||||
let table_id = stream.read_sized(5)?;
|
||||
|
||||
let changed: u16 = if stream.read()? { stream.read()? } else { 1 };
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ impl<'a> MessageIterator<'a> {
|
|||
MessageIterator { packet_data }
|
||||
}
|
||||
|
||||
pub fn next(&mut self, state: &ParserState<'a>) -> Option<Result<Message<'a>>> {
|
||||
pub fn next(&mut self, state: &ParserState) -> Option<Result<Message<'a>>> {
|
||||
while self.packet_data.bits_left() > 6 {
|
||||
let message_type = match MessageType::parse(&mut self.packet_data, state) {
|
||||
Ok(message_type) => message_type,
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ pub enum PacketType {
|
|||
}
|
||||
|
||||
impl<'a> Parse<'a> for Packet<'a> {
|
||||
fn parse(stream: &mut Stream<'a>, state: &ParserState<'a>) -> Result<Self> {
|
||||
fn parse(stream: &mut Stream<'a>, state: &ParserState) -> Result<Self> {
|
||||
let packet_type = PacketType::read(stream)?;
|
||||
Ok(match packet_type {
|
||||
PacketType::Sigon => Packet::Sigon(MessagePacket::parse(stream, state)?),
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ pub struct DemoHandler<'a, T: MessageHandler> {
|
|||
pub tick: u32,
|
||||
string_table_names: Vec<Cow<'a, str>>,
|
||||
analyser: T,
|
||||
pub state_handler: ParserState<'a>,
|
||||
pub state_handler: ParserState,
|
||||
}
|
||||
|
||||
impl<'a> DemoHandler<'a, Analyser> {
|
||||
|
|
@ -145,7 +145,7 @@ impl<'a, T: MessageHandler> DemoHandler<'a, T> {
|
|||
self.analyser.into_output(&self.state_handler)
|
||||
}
|
||||
|
||||
pub fn get_parser_state(&'a self) -> &ParserState<'a> {
|
||||
pub fn get_parser_state(&'a self) -> &ParserState {
|
||||
&self.state_handler
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ pub use self::error::*;
|
|||
use crate::demo::parser::handler::BorrowMessageHandler;
|
||||
|
||||
pub trait Parse<'a>: Sized {
|
||||
fn parse(stream: &mut Stream<'a>, state: &ParserState<'a>) -> Result<Self>;
|
||||
fn parse(stream: &mut Stream<'a>, state: &ParserState) -> Result<Self>;
|
||||
}
|
||||
|
||||
impl<'a, T: BitRead<'a, LittleEndian>> Parse<'a> for T {
|
||||
fn parse(stream: &mut Stream<'a>, _state: &ParserState<'a>) -> Result<Self> {
|
||||
fn parse(stream: &mut Stream<'a>, _state: &ParserState) -> Result<Self> {
|
||||
Self::read(stream).map_err(ParseError::from)
|
||||
}
|
||||
}
|
||||
|
|
@ -105,7 +105,7 @@ impl<'a> RawPacketStream<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn next(&mut self, state: &ParserState<'a>) -> Result<Option<Packet<'a>>> {
|
||||
pub fn next(&mut self, state: &ParserState) -> Result<Option<Packet<'a>>> {
|
||||
if self.ended {
|
||||
Ok(None)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ pub struct DemoMeta {
|
|||
pub interval_per_tick: f32,
|
||||
}
|
||||
|
||||
pub struct ParserState<'a> {
|
||||
pub static_baselines: HashMap<ClassId, StaticBaseline<'a>, NullHasherBuilder>,
|
||||
pub struct ParserState {
|
||||
pub static_baselines: HashMap<ClassId, StaticBaseline, NullHasherBuilder>,
|
||||
pub parsed_static_baselines: RefCell<HashMap<ClassId, Vec<SendProp>, NullHasherBuilder>>,
|
||||
pub event_definitions: Vec<GameEventDefinition>,
|
||||
pub string_tables: Vec<StringTableMeta>,
|
||||
|
|
@ -38,13 +38,13 @@ pub struct ParserState<'a> {
|
|||
parse_all: bool,
|
||||
}
|
||||
|
||||
pub struct StaticBaseline<'a> {
|
||||
pub struct StaticBaseline {
|
||||
pub class_id: ClassId,
|
||||
pub raw: Stream<'a>,
|
||||
pub raw: Stream<'static>,
|
||||
}
|
||||
|
||||
impl<'a> StaticBaseline<'a> {
|
||||
fn new(class_id: ClassId, raw: Stream<'a>) -> Self {
|
||||
impl StaticBaseline {
|
||||
fn new(class_id: ClassId, raw: Stream<'static>) -> Self {
|
||||
StaticBaseline { class_id, raw }
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ impl<'a> StaticBaseline<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> ParserState<'a> {
|
||||
impl<'a> ParserState {
|
||||
pub fn new(analyser_handles: fn(message_type: MessageType) -> bool, parse_all: bool) -> Self {
|
||||
ParserState {
|
||||
static_baselines: HashMap::with_hasher(NullHasherBuilder),
|
||||
|
|
@ -205,7 +205,7 @@ impl<'a> ParserState<'a> {
|
|||
match table {
|
||||
"instancebaseline" => {
|
||||
if let (Some(extra), Ok(class_id)) = (&entry.extra_data, entry.text().parse()) {
|
||||
let baseline = StaticBaseline::new(class_id, extra.data.clone());
|
||||
let baseline = StaticBaseline::new(class_id, extra.data.to_owned());
|
||||
self.static_baselines.insert(class_id, baseline);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue