mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
handler multiplexer
This commit is contained in:
parent
5f6cfe077e
commit
1709082228
8 changed files with 47 additions and 12 deletions
|
|
@ -32,7 +32,7 @@ impl MessageHandler for AllMessages {
|
|||
|
||||
fn handle_string_entry(&mut self, table: &String, _index: usize, entry: &StringTableEntry) {}
|
||||
|
||||
fn get_output(self, state: ParserState) -> Self::Output {
|
||||
fn get_output(self, state: &ParserState) -> Self::Output {
|
||||
test::black_box(true)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ impl MessageHandler for SendPropAnalyser {
|
|||
false
|
||||
}
|
||||
|
||||
fn get_output(self, state: ParserState) -> Self::Output {
|
||||
fn get_output(self, state: &ParserState) -> Self::Output {
|
||||
state
|
||||
.send_tables
|
||||
.into_iter()
|
||||
.iter()
|
||||
.map(|v| ParseSendTable {
|
||||
name: v.name,
|
||||
props: v.props,
|
||||
name: v.name.clone(),
|
||||
props: v.props.clone(),
|
||||
needs_decoder: v.needs_decoder,
|
||||
})
|
||||
.collect()
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ impl MessageHandler for Analyser {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_output(self, state: ParserState) -> MatchState {
|
||||
fn get_output(self, state: &ParserState) -> MatchState {
|
||||
MatchState {
|
||||
start_tick: self.start_tick,
|
||||
interval_per_tick: state.demo_meta.interval_per_tick,
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ impl MessageHandler for GameStateAnalyser {
|
|||
.collect();
|
||||
}
|
||||
|
||||
fn get_output(self, state: ParserState) -> Self::Output {
|
||||
fn get_output(self, state: &ParserState) -> Self::Output {
|
||||
self.state
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,42 @@ pub trait MessageHandler {
|
|||
|
||||
fn handle_data_tables(&mut self, tables: &[ParseSendTable], server_classes: &[ServerClass]) {}
|
||||
|
||||
fn get_output(self, state: ParserState) -> Self::Output;
|
||||
fn get_output(self, state: &ParserState) -> Self::Output;
|
||||
}
|
||||
|
||||
pub struct MultiplexMessageHandler<A: MessageHandler, B: MessageHandler> {
|
||||
handler_a: A,
|
||||
handler_b: B,
|
||||
}
|
||||
|
||||
impl<A: MessageHandler, B: MessageHandler> MessageHandler for MultiplexMessageHandler<A, B> {
|
||||
type Output = (A::Output, B::Output);
|
||||
|
||||
fn does_handle(message_type: MessageType) -> bool {
|
||||
A::does_handle(message_type) || B::does_handle(message_type)
|
||||
}
|
||||
|
||||
fn handle_message(&mut self, message: &Message, tick: u32) {
|
||||
self.handler_a.handle_message(message, tick);
|
||||
self.handler_b.handle_message(message, tick);
|
||||
}
|
||||
|
||||
fn handle_string_entry(&mut self, table: &String, index: usize, entries: &StringTableEntry) {
|
||||
self.handler_a.handle_string_entry(table, index, entries);
|
||||
self.handler_b.handle_string_entry(table, index, entries);
|
||||
}
|
||||
|
||||
fn handle_data_tables(&mut self, tables: &[ParseSendTable], server_classes: &[ServerClass]) {
|
||||
self.handler_a.handle_data_tables(tables, server_classes);
|
||||
self.handler_b.handle_data_tables(tables, server_classes);
|
||||
}
|
||||
|
||||
fn get_output(self, state: &ParserState) -> Self::Output {
|
||||
(
|
||||
self.handler_a.get_output(state),
|
||||
self.handler_b.get_output(state),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DemoHandler<T: MessageHandler> {
|
||||
|
|
@ -129,7 +164,7 @@ impl<T: MessageHandler> DemoHandler<T> {
|
|||
}
|
||||
|
||||
pub fn get_output(self) -> T::Output {
|
||||
self.analyser.get_output(self.state_handler)
|
||||
self.analyser.get_output(&self.state_handler)
|
||||
}
|
||||
|
||||
pub fn get_parser_state(&self) -> &ParserState {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ impl MessageHandler for MessageTypeAnalyser {
|
|||
|
||||
fn handle_string_entry(&mut self, table: &String, _index: usize, entry: &StringTableEntry) {}
|
||||
|
||||
fn get_output(self, state: ParserState) -> Self::Output {
|
||||
fn get_output(self, state: &ParserState) -> Self::Output {
|
||||
self.packet_types
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ impl MessageHandler for EntityDumper {
|
|||
|
||||
fn handle_string_entry(&mut self, table: &String, _index: usize, entry: &StringTableEntry) {}
|
||||
|
||||
fn get_output(self, state: ParserState) -> Self::Output {
|
||||
fn get_output(self, state: &ParserState) -> Self::Output {
|
||||
self.entities
|
||||
.into_iter()
|
||||
.map(|(tick, entity)| EntityDump::from_entity(entity, tick, &state.server_classes))
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ impl MessageHandler for SendPropAnalyser {
|
|||
self.tables = tables.to_vec()
|
||||
}
|
||||
|
||||
fn get_output(self, state: ParserState) -> Self::Output {
|
||||
fn get_output(self, state: &ParserState) -> Self::Output {
|
||||
self.tables
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue