1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-04 02:24:12 +02:00

remove the need to allocate all messages in a packet

This commit is contained in:
Robin Appelman 2020-12-06 19:29:11 +01:00
commit 25f24b63f6
7 changed files with 65 additions and 32 deletions

View file

@ -101,7 +101,7 @@ pub enum Message<'a> {
}
impl<'a> Parse<'a> for Message<'a> {
fn parse(stream: &mut Stream<'a>, state: &ParserState) -> Result<Self> {
fn parse(stream: &mut Stream<'a>, state: &ParserState<'a>) -> 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,
state: &ParserState<'a>,
) -> Result<Self> {
Ok(match message_type {
MessageType::Empty => Message::Empty,

View file

@ -31,7 +31,7 @@ impl From<&StringTable<'_>> for StringTableMeta {
}
impl<'a> Parse<'a> for CreateStringTableMessage<'a> {
fn parse(stream: &mut Stream<'a>, _state: &ParserState) -> Result<Self> {
fn parse(stream: &mut Stream<'a>, _state: &ParserState<'a>) -> 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) -> Result<Self> {
fn parse(stream: &mut Stream<'a>, state: &ParserState<'a>) -> Result<Self> {
let table_id = stream.read_sized(5)?;
let changed: u16 = if stream.read()? { stream.read()? } else { 1 };