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

entity reading wip

This commit is contained in:
Robin Appelman 2019-08-26 23:07:14 +02:00
commit e90bc53852
11 changed files with 509 additions and 114 deletions

View file

@ -4,19 +4,39 @@ use crate::demo::parser::MalformedSendPropDefinitionError;
use crate::demo::sendprop::{SendPropDefinition, SendPropFlag, SendPropName, SendPropType};
use crate::{MalformedDemoError, Parse, ParseError, ParserState, ReadResult, Result, Stream};
use serde::{Deserialize, Serialize};
use std::borrow::Borrow;
use std::cell::{Cell, RefCell};
use std::fmt;
use std::num::ParseIntError;
use std::ops::Deref;
use std::rc::Rc;
use std::str::FromStr;
#[derive(BitRead, Debug)]
pub struct ServerClass {
pub id: u16,
pub name: String,
pub data_table: String,
#[derive(BitRead, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ClassId(u16);
impl FromStr for ClassId {
type Err = ParseIntError;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
u16::from_str(s).map(|num| ClassId(num))
}
}
#[derive(PartialEq, Eq, Hash, Debug, Serialize, Deserialize)]
impl From<u16> for ClassId {
fn from(int: u16) -> Self {
ClassId(int)
}
}
#[derive(BitRead, Debug, Clone)]
pub struct ServerClass {
pub id: ClassId,
pub name: String,
pub data_table: SendTableName,
}
#[derive(BitRead, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)]
pub struct SendTableName(Rc<String>);
impl Clone for SendTableName {
@ -37,12 +57,6 @@ impl From<String> for SendTableName {
}
}
impl BitRead<LittleEndian> for SendTableName {
fn read(stream: &mut Stream) -> ReadResult<Self> {
String::read(stream).map(SendTableName::from)
}
}
#[derive(Debug)]
pub struct ParseSendTable {
pub name: SendTableName,
@ -184,7 +198,7 @@ pub struct SendTable {
pub struct DataTablePacket {
pub tick: u32,
pub tables: Vec<SendTable>,
pub server_classes: Vec<ServerClass>,
pub server_classes: Vec<Rc<ServerClass>>,
}
impl Parse for DataTablePacket {