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

refcount propnames

This commit is contained in:
Robin Appelman 2019-08-11 14:42:01 +02:00
commit e54f0f35fc
2 changed files with 34 additions and 5 deletions

View file

@ -1,6 +1,6 @@
use bitstream_reader::{BitRead, LittleEndian};
use crate::demo::sendprop::{SendPropDefinition, SendPropFlag, SendPropType};
use crate::demo::sendprop::{SendPropDefinition, SendPropFlag, SendPropName, SendPropType};
use crate::{Parse, ParseError, ParserState, ReadResult, Result, Stream};
use serde::{Deserialize, Serialize};
use std::cell::{Cell, RefCell};
@ -166,12 +166,12 @@ impl ParseSendTable {
#[derive(Clone)]
struct Exclude<'a> {
table: &'a SendTableName,
prop: &'a str,
prop: &'a SendPropName,
}
impl<'a> Exclude<'a> {
pub fn matches(&self, prop: &SendPropDefinition) -> bool {
self.table == &prop.owner_table && self.prop == prop.name
self.table == &prop.owner_table && *self.prop == prop.name
}
}

View file

@ -9,11 +9,40 @@ use super::vector::{Vector, VectorXY};
use crate::demo::message::stringtable::log_base2;
use crate::demo::packet::datatable::SendTableName;
use std::convert::TryInto;
use std::fmt;
use std::rc::Rc;
#[derive(PartialEq, Eq, Hash, Debug)]
pub struct SendPropName(Rc<String>);
impl Clone for SendPropName {
fn clone(&self) -> Self {
SendPropName(Rc::clone(&self.0))
}
}
impl fmt::Display for SendPropName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<String> for SendPropName {
fn from(value: String) -> Self {
Self(Rc::new(value))
}
}
impl BitRead<LittleEndian> for SendPropName {
fn read(stream: &mut Stream) -> ReadResult<Self> {
String::read(stream).map(SendPropName::from)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct SendPropDefinition {
pub prop_type: SendPropType,
pub name: String,
pub name: SendPropName,
pub flags: SendPropFlags,
pub table_name: Option<SendTableName>,
pub owner_table: SendTableName,
@ -55,7 +84,7 @@ impl SendPropDefinition {
pub fn read(stream: &mut Stream, owner_table: SendTableName) -> ReadResult<Self> {
let prop_type = SendPropType::read(stream)?;
let name = stream.read_string(None)?;
let name = stream.read_string(None)?.into();
let flags = SendPropFlags::read(stream)?;
let mut table_name = None;
let mut element_count = None;