mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-04 02:24:12 +02:00
borrowed data
This commit is contained in:
parent
fed1da5cb0
commit
a4ddd586dd
27 changed files with 181 additions and 176 deletions
|
|
@ -8,7 +8,7 @@ pub struct ConsoleCmdPacket {
|
|||
command: String,
|
||||
}
|
||||
|
||||
impl BitRead<LittleEndian> for ConsoleCmdPacket {
|
||||
impl BitRead<'_, LittleEndian> for ConsoleCmdPacket {
|
||||
fn read(stream: &mut Stream) -> ReadResult<Self> {
|
||||
let tick = stream.read_int(32)?;
|
||||
let len = stream.read_int::<usize>(32)?;
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ pub struct DataTablePacket {
|
|||
pub server_classes: Vec<ServerClass>,
|
||||
}
|
||||
|
||||
impl Parse for DataTablePacket {
|
||||
impl Parse<'_> for DataTablePacket {
|
||||
fn parse(stream: &mut Stream, state: &ParserState) -> Result<Self> {
|
||||
let tick = stream.read()?;
|
||||
let len = stream.read_int::<usize>(32)?;
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ pub struct MessagePacketMeta {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MessagePacket {
|
||||
pub struct MessagePacket<'a> {
|
||||
pub tick: u32,
|
||||
pub messages: Vec<Message>,
|
||||
pub meta: LazyBitRead<MessagePacketMeta, LittleEndian>,
|
||||
pub messages: Vec<Message<'a>>,
|
||||
pub meta: LazyBitRead<'a, MessagePacketMeta, LittleEndian>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
@ -26,7 +26,7 @@ pub struct ViewAngles {
|
|||
pub local_angles: (Vector, Vector),
|
||||
}
|
||||
|
||||
impl<E: Endianness> BitRead<E> for ViewAngles {
|
||||
impl<E: Endianness> BitRead<'_, E> for ViewAngles {
|
||||
fn read(stream: &mut bitbuffer::BitReadStream<E>) -> ReadResult<Self> {
|
||||
let view_origin_1 = Vector::read(stream)?;
|
||||
let view_angle_1 = Vector::read(stream)?;
|
||||
|
|
@ -46,8 +46,8 @@ impl<E: Endianness> BitRead<E> for ViewAngles {
|
|||
}
|
||||
}
|
||||
|
||||
impl Parse for MessagePacket {
|
||||
fn parse(stream: &mut Stream, state: &ParserState) -> Result<Self> {
|
||||
impl<'a> Parse<'a> for MessagePacket<'a> {
|
||||
fn parse(stream: &mut Stream<'a>, state: &ParserState) -> Result<Self> {
|
||||
let tick = stream.read()?;
|
||||
|
||||
let meta = stream.read()?;
|
||||
|
|
|
|||
|
|
@ -20,15 +20,15 @@ pub mod synctick;
|
|||
pub mod usercmd;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Packet {
|
||||
Sigon(MessagePacket),
|
||||
Message(MessagePacket),
|
||||
pub enum Packet<'a> {
|
||||
Sigon(MessagePacket<'a>),
|
||||
Message(MessagePacket<'a>),
|
||||
SyncTick(SyncTickPacket),
|
||||
ConsoleCmd(ConsoleCmdPacket),
|
||||
UserCmd(UserCmdPacket),
|
||||
DataTables(DataTablePacket),
|
||||
Stop(StopPacket),
|
||||
StringTables(StringTablePacket),
|
||||
StringTables(StringTablePacket<'a>),
|
||||
}
|
||||
|
||||
#[derive(BitRead, TryFromPrimitive, Debug, Clone, Copy)]
|
||||
|
|
@ -45,8 +45,8 @@ pub enum PacketType {
|
|||
StringTables = 8,
|
||||
}
|
||||
|
||||
impl Parse for Packet {
|
||||
fn parse(stream: &mut Stream, state: &ParserState) -> Result<Self> {
|
||||
impl<'a> Parse<'a> for Packet<'a> {
|
||||
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)?),
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::{ReadResult, Stream};
|
|||
#[derive(Debug)]
|
||||
pub struct StopPacket;
|
||||
|
||||
impl BitRead<LittleEndian> for StopPacket {
|
||||
impl BitRead<'_, LittleEndian> for StopPacket {
|
||||
fn read(_stream: &mut Stream) -> ReadResult<Self> {
|
||||
Ok(StopPacket)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,16 +15,16 @@ pub struct FixedUserDataSize {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct StringTable {
|
||||
pub struct StringTable<'a> {
|
||||
pub name: String,
|
||||
pub entries: Vec<(u16, StringTableEntry)>,
|
||||
pub entries: Vec<(u16, StringTableEntry<'a>)>,
|
||||
pub max_entries: u16,
|
||||
pub fixed_user_data_size: Option<FixedUserDataSize>,
|
||||
pub client_entries: Option<Vec<StringTableEntry>>,
|
||||
pub client_entries: Option<Vec<StringTableEntry<'a>>>,
|
||||
pub compressed: bool,
|
||||
}
|
||||
|
||||
impl StringTable {
|
||||
impl StringTable<'_> {
|
||||
pub fn get_table_meta(&self) -> StringTableMeta {
|
||||
StringTableMeta {
|
||||
fixed_userdata_size: self.fixed_user_data_size,
|
||||
|
|
@ -33,8 +33,8 @@ impl StringTable {
|
|||
}
|
||||
}
|
||||
|
||||
impl BitRead<LittleEndian> for StringTable {
|
||||
fn read(stream: &mut Stream) -> ReadResult<Self> {
|
||||
impl<'a> BitRead<'a, LittleEndian> for StringTable<'a> {
|
||||
fn read(stream: &mut Stream<'a>) -> ReadResult<Self> {
|
||||
let name = stream.read()?;
|
||||
let entry_count = stream.read_int(16)?;
|
||||
let mut entries = Vec::with_capacity(min(entry_count, 128) as usize);
|
||||
|
|
@ -63,33 +63,33 @@ impl BitRead<LittleEndian> for StringTable {
|
|||
|
||||
#[derive(BitRead, Clone, Debug)]
|
||||
#[endianness = "LittleEndian"]
|
||||
pub struct ExtraData {
|
||||
pub struct ExtraData<'a> {
|
||||
pub byte_len: u16,
|
||||
#[size = "byte_len.saturating_mul(8)"]
|
||||
pub data: Stream,
|
||||
pub data: Stream<'a>,
|
||||
}
|
||||
|
||||
impl ExtraData {
|
||||
pub fn new(data: Stream) -> Self {
|
||||
impl<'a> ExtraData<'a> {
|
||||
pub fn new(data: Stream<'a>) -> Self {
|
||||
let byte_len = (data.bit_len() / 8) as u16;
|
||||
ExtraData { byte_len, data }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct StringTableEntry {
|
||||
pub struct StringTableEntry<'a> {
|
||||
pub text: Option<String>,
|
||||
pub extra_data: Option<ExtraData>,
|
||||
pub extra_data: Option<ExtraData<'a>>,
|
||||
}
|
||||
|
||||
impl StringTableEntry {
|
||||
impl StringTableEntry<'_> {
|
||||
pub fn text(&self) -> &str {
|
||||
self.text.as_ref().map(|s| s.as_str()).unwrap_or("")
|
||||
}
|
||||
}
|
||||
|
||||
impl BitRead<LittleEndian> for StringTableEntry {
|
||||
fn read(stream: &mut Stream) -> ReadResult<Self> {
|
||||
impl<'a> BitRead<'a, LittleEndian> for StringTableEntry<'a> {
|
||||
fn read(stream: &mut Stream<'a>) -> ReadResult<Self> {
|
||||
Ok(StringTableEntry {
|
||||
text: Some(stream.read()?),
|
||||
extra_data: stream.read()?,
|
||||
|
|
@ -97,7 +97,7 @@ impl BitRead<LittleEndian> for StringTableEntry {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for StringTableEntry {
|
||||
impl fmt::Debug for StringTableEntry<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match &self.extra_data {
|
||||
None => write!(f, "StringTableEntry {{ text: \"{}\" }}", self.text()),
|
||||
|
|
@ -112,13 +112,13 @@ impl fmt::Debug for StringTableEntry {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct StringTablePacket {
|
||||
pub struct StringTablePacket<'a> {
|
||||
pub tick: u32,
|
||||
pub tables: Vec<StringTable>,
|
||||
pub tables: Vec<StringTable<'a>>,
|
||||
}
|
||||
|
||||
impl Parse for StringTablePacket {
|
||||
fn parse(stream: &mut Stream, _state: &ParserState) -> Result<Self> {
|
||||
impl<'a> Parse<'a> for StringTablePacket<'a> {
|
||||
fn parse(stream: &mut Stream<'a>, _state: &ParserState) -> Result<Self> {
|
||||
let tick = stream.read_int(32)?;
|
||||
let length: usize = stream.read_int(32)?;
|
||||
let mut packet_data = stream.read_bits(length.saturating_mul(8))?;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ pub struct UserCmdPacket {
|
|||
sequence_out: u32,
|
||||
}
|
||||
|
||||
impl BitRead<LittleEndian> for UserCmdPacket {
|
||||
impl BitRead<'_, LittleEndian> for UserCmdPacket {
|
||||
fn read(stream: &mut Stream) -> ReadResult<Self> {
|
||||
let tick = stream.read()?;
|
||||
let sequence_out = stream.read()?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue