mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
clippy fixes
This commit is contained in:
parent
f1608357ad
commit
11c7fb507f
13 changed files with 42 additions and 54 deletions
|
|
@ -30,8 +30,6 @@ impl MessageHandler for AllMessages {
|
|||
test::black_box(message);
|
||||
}
|
||||
|
||||
fn handle_string_entry(&mut self, table: &String, _index: usize, entry: &StringTableEntry) {}
|
||||
|
||||
fn get_output(self, state: &ParserState) -> Self::Output {
|
||||
test::black_box(true)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,9 +60,9 @@ pub struct PacketEntity {
|
|||
|
||||
impl fmt::Display for PacketEntity {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}({}) {{\n", self.entity_index, self.server_class)?;
|
||||
writeln!(f, "{}({}) {{", self.entity_index, self.server_class)?;
|
||||
for child in self.props.iter() {
|
||||
write!(f, "\t{}\n", child)?;
|
||||
writeln!(f, "\t{}", child)?;
|
||||
}
|
||||
write!(f, "}}")
|
||||
}
|
||||
|
|
@ -251,10 +251,10 @@ impl PacketEntitiesMessage {
|
|||
});
|
||||
}
|
||||
None => {
|
||||
return Err(ParseError::from(ParseError::PropIndexOutOfBounds {
|
||||
return Err(ParseError::PropIndexOutOfBounds {
|
||||
index,
|
||||
prop_count: send_table.flattened_props.len(),
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ impl Parse for UpdateStringTableMessage {
|
|||
|
||||
let entries = match state.string_tables.get(table_id as usize) {
|
||||
Some(table) => parse_string_table_update(&mut data, table, changed),
|
||||
None => return Err(ParseError::StringTableNotFound(table_id).into()),
|
||||
None => return Err(ParseError::StringTableNotFound(table_id)),
|
||||
}?;
|
||||
|
||||
Ok(UpdateStringTableMessage { table_id, entries })
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ impl BitRead<LittleEndian> for UserMessage {
|
|||
|
||||
impl ParseBitSkip for UserMessage {
|
||||
fn parse_skip(stream: &mut Stream) -> Result<()> {
|
||||
let _ = stream.skip_bits(8)?;
|
||||
stream.skip_bits(8)?;
|
||||
let length: u32 = stream.read_int(11)?;
|
||||
stream.skip_bits(length as usize).map_err(ParseError::from)
|
||||
}
|
||||
|
|
@ -163,7 +163,7 @@ impl BitRead<LittleEndian> for SayText2Message {
|
|||
if first == 7 {
|
||||
let _color = stream.read_string(Some(6))?;
|
||||
} else {
|
||||
let _ = stream.skip_bits(8)?;
|
||||
stream.skip_bits(8)?;
|
||||
}
|
||||
|
||||
let text: String = stream.read().or_else(handle_utf8_error)?;
|
||||
|
|
@ -179,12 +179,12 @@ impl BitRead<LittleEndian> for SayText2Message {
|
|||
(ChatMessageKind::ChatAll, None, text)
|
||||
}
|
||||
} else {
|
||||
let _ = stream.set_pos(stream.pos() - 8)?;
|
||||
stream.set_pos(stream.pos() - 8)?;
|
||||
|
||||
let kind = stream.read()?;
|
||||
let from = stream.read().or_else(handle_utf8_error)?;
|
||||
let text = stream.read().or_else(handle_utf8_error)?;
|
||||
let _ = stream.skip_bits(16)?;
|
||||
stream.skip_bits(16)?;
|
||||
(kind, Some(from), text)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ impl Parse for MessagePacket {
|
|||
let message = Message::from_type(message_type, &mut packet_data, state)?;
|
||||
messages.push(message);
|
||||
} else {
|
||||
let _ = Message::skip_type(message_type, &mut packet_data)?;
|
||||
Message::skip_type(message_type, &mut packet_data)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ impl BitRead<LittleEndian> for UserCmdPacket {
|
|||
let tick = stream.read()?;
|
||||
let sequence_out = stream.read()?;
|
||||
let len: u32 = stream.read()?;
|
||||
let _ = stream.skip_bits(len as usize * 8)?;
|
||||
stream.skip_bits(len as usize * 8)?;
|
||||
// TODO parse the packet data
|
||||
Ok(UserCmdPacket { tick, sequence_out })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -263,8 +263,8 @@ impl MessageHandler for Analyser {
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_string_entry(&mut self, table: &String, _index: usize, entry: &StringTableEntry) {
|
||||
match table.as_str() {
|
||||
fn handle_string_entry(&mut self, table: &str, _index: usize, entry: &StringTableEntry) {
|
||||
match table {
|
||||
"userinfo" => {
|
||||
if let (Some(text), Some(data)) = (&entry.text, &entry.extra_data) {
|
||||
if data.byte_len > 32 {
|
||||
|
|
@ -334,12 +334,14 @@ impl Analyser {
|
|||
}
|
||||
|
||||
fn parse_user_info(&mut self, text: &str, mut data: Stream) -> ReadResult<()> {
|
||||
let name: String = data.read_sized(32).unwrap_or("Malformed Name".into());
|
||||
let name: String = data
|
||||
.read_sized(32)
|
||||
.unwrap_or_else(|_| "Malformed Name".into());
|
||||
let user_id = data.read::<u32>()?.into();
|
||||
let steam_id: String = data.read()?;
|
||||
|
||||
match text.parse() {
|
||||
Ok(entity_id) if (steam_id.len() > 0) => {
|
||||
Ok(entity_id) if !steam_id.is_empty() => {
|
||||
self.users.insert(
|
||||
user_id,
|
||||
UserInfo {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub trait MessageHandler {
|
|||
|
||||
fn handle_message(&mut self, message: &Message, tick: u32) {}
|
||||
|
||||
fn handle_string_entry(&mut self, table: &String, index: usize, entries: &StringTableEntry) {}
|
||||
fn handle_string_entry(&mut self, table: &str, index: usize, entries: &StringTableEntry) {}
|
||||
|
||||
fn handle_data_tables(&mut self, tables: &[ParseSendTable], server_classes: &[ServerClass]) {}
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ impl<A: MessageHandler, B: MessageHandler> MessageHandler for MultiplexMessageHa
|
|||
self.handler_b.handle_message(message, tick);
|
||||
}
|
||||
|
||||
fn handle_string_entry(&mut self, table: &String, index: usize, entries: &StringTableEntry) {
|
||||
fn handle_string_entry(&mut self, table: &str, index: usize, entries: &StringTableEntry) {
|
||||
self.handler_a.handle_string_entry(table, index, entries);
|
||||
self.handler_b.handle_string_entry(table, index, entries);
|
||||
}
|
||||
|
|
@ -68,6 +68,12 @@ impl DemoHandler<Analyser> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for DemoHandler<Analyser> {
|
||||
fn default() -> Self {
|
||||
DemoHandler::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: MessageHandler> DemoHandler<T> {
|
||||
pub fn with_analyser(analyser: T) -> Self {
|
||||
let state_handler = ParserState::new(T::does_handle, false);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use crate::demo::parser::handler::MessageHandler;
|
|||
use crate::demo::vector::Vector;
|
||||
use crate::{ParserState, ReadResult, Stream};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct MessageTypeAnalyser {
|
||||
packet_types: Vec<MessageType>,
|
||||
}
|
||||
|
|
@ -30,17 +31,7 @@ impl MessageHandler for MessageTypeAnalyser {
|
|||
self.packet_types.push(message.get_message_type())
|
||||
}
|
||||
|
||||
fn handle_string_entry(&mut self, table: &String, _index: usize, entry: &StringTableEntry) {}
|
||||
|
||||
fn get_output(self, state: &ParserState) -> Self::Output {
|
||||
self.packet_types
|
||||
}
|
||||
}
|
||||
|
||||
impl MessageTypeAnalyser {
|
||||
pub fn new() -> Self {
|
||||
MessageTypeAnalyser {
|
||||
packet_types: Vec::with_capacity(1024),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,8 +197,8 @@ impl ParserState {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn handle_string_entry(&mut self, table: &String, _index: usize, entry: &StringTableEntry) {
|
||||
match table.as_str() {
|
||||
pub fn handle_string_entry(&mut self, table: &str, _index: usize, entry: &StringTableEntry) {
|
||||
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());
|
||||
|
|
|
|||
|
|
@ -167,10 +167,7 @@ impl SendPropDefinition {
|
|||
let mut low_value = None;
|
||||
let mut high_value = None;
|
||||
let mut bit_count = None;
|
||||
if prop_type == SendPropType::DataTable {
|
||||
table_name = Some(stream.read()?);
|
||||
} else {
|
||||
if flags.contains(SendPropFlag::Exclude) {
|
||||
if flags.contains(SendPropFlag::Exclude) || prop_type == SendPropType::DataTable {
|
||||
table_name = Some(stream.read()?);
|
||||
} else if prop_type == SendPropType::Array {
|
||||
element_count = Some(stream.read_int(10)?);
|
||||
|
|
@ -179,7 +176,6 @@ impl SendPropDefinition {
|
|||
high_value = Some(stream.read()?);
|
||||
bit_count = Some(stream.read_int(7)?);
|
||||
}
|
||||
}
|
||||
|
||||
if flags.contains(SendPropFlag::NoScale) {
|
||||
if prop_type == SendPropType::Float {
|
||||
|
|
@ -403,10 +399,8 @@ impl SendPropValue {
|
|||
read_var_int(stream, !definition.flags.contains(SendPropFlag::Unsigned))
|
||||
.map_err(ParseError::from)
|
||||
.map(|int| int as i64)
|
||||
} else {
|
||||
if definition.flags.contains(SendPropFlag::Unsigned) {
|
||||
let unsigned: u32 =
|
||||
stream.read_sized(definition.bit_count.unwrap_or(32) as usize)?;
|
||||
} else if definition.flags.contains(SendPropFlag::Unsigned) {
|
||||
let unsigned: u32 = stream.read_sized(definition.bit_count.unwrap_or(32) as usize)?;
|
||||
//const MAX: u32 = std::i32::MAX as u32;
|
||||
Ok(unsigned as i64)
|
||||
} else {
|
||||
|
|
@ -415,7 +409,6 @@ impl SendPropValue {
|
|||
.map_err(ParseError::from)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn read_array(
|
||||
stream: &mut Stream,
|
||||
|
|
|
|||
|
|
@ -107,8 +107,6 @@ impl MessageHandler for EntityDumper {
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_string_entry(&mut self, table: &String, _index: usize, entry: &StringTableEntry) {}
|
||||
|
||||
fn get_output(self, state: &ParserState) -> Self::Output {
|
||||
self.entities
|
||||
.into_iter()
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ fn test_message_types(input_file: &str, snapshot_file: &str) {
|
|||
let file = fs::read(input_file).expect("Unable to read file");
|
||||
let demo = Demo::new(file);
|
||||
let (_, message_types) =
|
||||
DemoParser::parse_with_analyser(demo.get_stream(), MessageTypeAnalyser::new()).unwrap();
|
||||
DemoParser::parse_with_analyser(demo.get_stream(), MessageTypeAnalyser::default()).unwrap();
|
||||
|
||||
let expected: Vec<MessageType> = serde_json::from_slice(
|
||||
fs::read(snapshot_file)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue