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

add serde support for packets

This commit is contained in:
Robin Appelman 2021-07-25 15:09:36 +02:00
commit 03f8b8a424
27 changed files with 556 additions and 490 deletions

6
Cargo.lock generated
View file

@ -79,14 +79,15 @@ dependencies = [
[[package]] [[package]]
name = "bitbuffer" name = "bitbuffer"
version = "0.10.1" version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecda732bb39816e05e1d037def865ab8744579ffd53aa7586a17eb0bc7492170" checksum = "29a6edc6bf48f16337689fb5122a6407713ecc23e57fbbcfde367c51fdb6aec1"
dependencies = [ dependencies = [
"bitbuffer_derive", "bitbuffer_derive",
"err-derive", "err-derive",
"memchr", "memchr",
"num-traits 0.2.14", "num-traits 0.2.14",
"serde",
] ]
[[package]] [[package]]
@ -189,6 +190,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8672257d642ffdd235f6e9c723c2326ac1253c8f3c022e7cfd2e57da55b1131" checksum = "a8672257d642ffdd235f6e9c723c2326ac1253c8f3c022e7cfd2e57da55b1131"
dependencies = [ dependencies = [
"enumflags2_derive", "enumflags2_derive",
"serde",
] ]
[[package]] [[package]]

View file

@ -21,10 +21,10 @@ name = "reencode_demo"
path = "src/bin/reencode.rs" path = "src/bin/reencode.rs"
[dependencies] [dependencies]
bitbuffer = "0.10" bitbuffer = { version = "0.10", features = ["serde"] }
num_enum = "0.5" num_enum = "0.5"
num-traits = "0.2" num-traits = "0.2"
enumflags2 = "0.7" enumflags2 = { version = "0.7", features = ["serde"] }
snap = "1.0" snap = "1.0"
serde = { version = "1", features = ["derive", "rc"] } serde = { version = "1", features = ["derive", "rc"] }
serde_json = "1" serde_json = "1"

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,5 @@
use bitbuffer::{BitRead, BitWrite, BitWriteStream, LittleEndian}; use bitbuffer::{BitRead, BitWrite, BitWriteStream, LittleEndian};
use serde::{Deserialize, Serialize};
use crate::{GameEventError, Result, Stream}; use crate::{GameEventError, Result, Stream};
@ -8,7 +9,7 @@ use crate::demo::message::gameevent::GameEventTypeId;
use parse_display::Display; use parse_display::Display;
use std::cmp::Ordering; use std::cmp::Ordering;
#[derive(Debug, Clone)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GameEventDefinition { pub struct GameEventDefinition {
pub id: GameEventTypeId, pub id: GameEventTypeId,
pub event_type: GameEventType, pub event_type: GameEventType,
@ -35,13 +36,13 @@ impl Ord for GameEventDefinition {
} }
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct GameEventEntry { pub struct GameEventEntry {
pub name: String, pub name: String,
pub kind: GameEventValueType, pub kind: GameEventValueType,
} }
#[derive(BitRead, BitWrite, Debug, Clone, Copy, PartialEq, Display)] #[derive(BitRead, BitWrite, Debug, Clone, Copy, PartialEq, Display, Serialize, Deserialize)]
#[discriminant_bits = 3] #[discriminant_bits = 3]
pub enum GameEventValueType { pub enum GameEventValueType {
None = 0, None = 0,
@ -54,7 +55,7 @@ pub enum GameEventValueType {
Local = 7, Local = 7,
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum GameEventValue { pub enum GameEventValue {
String(String), String(String),
Float(f32), Float(f32),
@ -154,7 +155,7 @@ impl EventValue for () {
} }
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct RawGameEvent { pub struct RawGameEvent {
pub event_type: GameEventType, pub event_type: GameEventType,
pub values: Vec<GameEventValue>, pub values: Vec<GameEventValue>,

View file

@ -1,6 +1,7 @@
use bitbuffer::{BitRead, BitWrite}; use bitbuffer::{BitRead, BitWrite};
use serde::{Deserialize, Serialize};
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
pub struct Header { pub struct Header {
#[size = 8] #[size = 8]
pub demo_type: String, pub demo_type: String,

View file

@ -1,10 +1,11 @@
use bitbuffer::{BitRead, BitWrite, BitWriteSized, BitWriteStream, LittleEndian}; use bitbuffer::{BitRead, BitWrite, BitWriteSized, BitWriteStream, LittleEndian};
use serde::{Deserialize, Serialize};
use crate::demo::sendprop::{read_bit_coord, write_bit_coord}; use crate::demo::sendprop::{read_bit_coord, write_bit_coord};
use crate::demo::vector::Vector; use crate::demo::vector::Vector;
use crate::{ReadResult, Stream}; use crate::{ReadResult, Stream};
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct BSPDecalMessage { pub struct BSPDecalMessage {
pub position: Vector, pub position: Vector,
pub texture_index: u16, pub texture_index: u16,

View file

@ -1,10 +1,11 @@
use bitbuffer::{BitRead, BitReadSized, BitWrite, BitWriteSized, BitWriteStream, LittleEndian}; use bitbuffer::{BitRead, BitReadSized, BitWrite, BitWriteSized, BitWriteStream, LittleEndian};
use serde::{Deserialize, Serialize};
use crate::demo::message::stringtable::log_base2; use crate::demo::message::stringtable::log_base2;
use crate::{ReadResult, Stream}; use crate::{ReadResult, Stream};
use std::cmp::min; use std::cmp::min;
#[derive(BitReadSized, BitWriteSized, Debug, PartialEq)] #[derive(BitReadSized, BitWriteSized, Debug, PartialEq, Serialize, Deserialize)]
pub struct ClassInfoEntry { pub struct ClassInfoEntry {
#[size = "input_size"] #[size = "input_size"]
class_id: u16, class_id: u16,
@ -12,7 +13,7 @@ pub struct ClassInfoEntry {
table_name: String, table_name: String,
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct ClassInfoMessage { pub struct ClassInfoMessage {
count: u16, count: u16,
create: bool, create: bool,

View file

@ -1,5 +1,6 @@
use bitbuffer::{BitRead, BitWrite, BitWriteSized, BitWriteStream, LittleEndian}; use bitbuffer::{BitRead, BitWrite, BitWriteSized, BitWriteStream, LittleEndian};
use parse_display::Display; use parse_display::Display;
use serde::{Deserialize, Serialize};
use crate::demo::gameevent_gen::GameEventType; use crate::demo::gameevent_gen::GameEventType;
use crate::demo::gamevent::{ use crate::demo::gamevent::{
@ -8,7 +9,7 @@ use crate::demo::gamevent::{
use crate::demo::parser::{Encode, ParseBitSkip}; use crate::demo::parser::{Encode, ParseBitSkip};
use crate::{GameEventError, Parse, ParseError, ParserState, ReadResult, Result, Stream}; use crate::{GameEventError, Parse, ParseError, ParserState, ReadResult, Result, Stream};
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct GameEventMessage { pub struct GameEventMessage {
pub event_type_id: GameEventTypeId, pub event_type_id: GameEventTypeId,
pub event: GameEvent, pub event: GameEvent,
@ -114,7 +115,21 @@ impl ParseBitSkip<'_> for GameEventMessage {
} }
} }
#[derive(BitRead, BitWrite, Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Display)] #[derive(
BitRead,
BitWrite,
Debug,
Clone,
Copy,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
Display,
Serialize,
Deserialize,
)]
pub struct GameEventTypeId(#[size = 9] u16); pub struct GameEventTypeId(#[size = 9] u16);
impl From<GameEventTypeId> for usize { impl From<GameEventTypeId> for usize {
@ -129,7 +144,7 @@ impl From<GameEventTypeId> for u16 {
} }
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct GameEventListMessage { pub struct GameEventListMessage {
pub event_list: Vec<GameEventDefinition>, pub event_list: Vec<GameEventDefinition>,
} }

View file

@ -1,38 +1,39 @@
use crate::Stream; use crate::Stream;
/// Messages that consists only of primitives and string and can be derived /// Messages that consists only of primitives and string and can be derived
use bitbuffer::{BitRead, BitWrite, LittleEndian}; use bitbuffer::{BitRead, BitWrite, LittleEndian};
use serde::{Deserialize, Serialize};
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
pub struct FileMessage { pub struct FileMessage {
pub transfer_id: u32, pub transfer_id: u32,
pub file_name: String, pub file_name: String,
pub requested: bool, pub requested: bool,
} }
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
pub struct NetTickMessage { pub struct NetTickMessage {
pub tick: u32, pub tick: u32,
pub frame_time: u16, pub frame_time: u16,
pub std_dev: u16, pub std_dev: u16,
} }
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
pub struct StringCmdMessage { pub struct StringCmdMessage {
pub command: String, pub command: String,
} }
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
pub struct SignOnStateMessage { pub struct SignOnStateMessage {
pub state: u8, pub state: u8,
pub count: u32, pub count: u32,
} }
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
pub struct PrintMessage { pub struct PrintMessage {
pub value: String, pub value: String,
} }
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
pub struct ServerInfoMessage { pub struct ServerInfoMessage {
pub version: u16, pub version: u16,
pub server_count: u32, pub server_count: u32,
@ -53,18 +54,18 @@ pub struct ServerInfoMessage {
pub replay: bool, pub replay: bool,
} }
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
pub struct SetPauseMessage { pub struct SetPauseMessage {
pub pause: bool, pub pause: bool,
} }
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
pub struct SetViewMessage { pub struct SetViewMessage {
#[size = 11] #[size = 11]
pub index: u16, pub index: u16,
} }
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
pub struct FixAngleMessage { pub struct FixAngleMessage {
pub relative: bool, pub relative: bool,
pub x: u16, pub x: u16,
@ -72,8 +73,9 @@ pub struct FixAngleMessage {
pub z: u16, pub z: u16,
} }
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
#[endianness = "LittleEndian"] #[endianness = "LittleEndian"]
#[serde(bound(deserialize = "'a: 'static"))]
pub struct EntityMessage<'a> { pub struct EntityMessage<'a> {
#[size = 11] #[size = 11]
pub index: u16, pub index: u16,
@ -85,14 +87,15 @@ pub struct EntityMessage<'a> {
pub data: Stream<'a>, pub data: Stream<'a>,
} }
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
pub struct PreFetchMessage { pub struct PreFetchMessage {
#[size = 14] #[size = 14]
pub index: u16, pub index: u16,
} }
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
#[endianness = "LittleEndian"] #[endianness = "LittleEndian"]
#[serde(bound(deserialize = "'a: 'static"))]
pub struct MenuMessage<'a> { pub struct MenuMessage<'a> {
pub kind: u16, pub kind: u16,
pub length: u16, pub length: u16,
@ -100,14 +103,15 @@ pub struct MenuMessage<'a> {
pub index: Stream<'a>, pub index: Stream<'a>,
} }
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
pub struct GetCvarValueMessage { pub struct GetCvarValueMessage {
pub cookie: u32, pub cookie: u32,
pub value: String, pub value: String,
} }
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
#[endianness = "LittleEndian"] #[endianness = "LittleEndian"]
#[serde(bound(deserialize = "'a: 'static"))]
pub struct CmdKeyValuesMessage<'a> { pub struct CmdKeyValuesMessage<'a> {
pub length: u32, pub length: u32,
#[size = "length.saturating_mul(8)"] #[size = "length.saturating_mul(8)"]

View file

@ -12,6 +12,7 @@ use crate::demo::message::voice::*;
use crate::demo::parser::{Encode, ParseBitSkip}; use crate::demo::parser::{Encode, ParseBitSkip};
use crate::{Parse, ParserState, Result, Stream}; use crate::{Parse, ParserState, Result, Stream};
use bitbuffer::{BitRead, BitWrite, BitWriteStream, LittleEndian}; use bitbuffer::{BitRead, BitWrite, BitWriteStream, LittleEndian};
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr}; use serde_repr::{Deserialize_repr, Serialize_repr};
pub mod bspdecal; pub mod bspdecal;
@ -61,7 +62,8 @@ pub enum MessageType {
CmdKeyValues = 32, CmdKeyValues = 32,
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(bound(deserialize = "'a: 'static"))]
pub enum Message<'a> { pub enum Message<'a> {
Empty, Empty,
File(FileMessage), File(FileMessage),

View file

@ -49,7 +49,7 @@ pub enum PVS {
Delete = 3, Delete = 3,
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PacketEntity { pub struct PacketEntity {
pub server_class: ClassId, pub server_class: ClassId,
pub entity_index: EntityId, pub entity_index: EntityId,
@ -174,7 +174,7 @@ fn test_bit_var_roundtrip() {
bit_var_normal(123456789); bit_var_normal(123456789);
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct PacketEntitiesMessage { pub struct PacketEntitiesMessage {
pub entities: Vec<PacketEntity>, pub entities: Vec<PacketEntity>,
pub removed_entities: Vec<EntityId>, pub removed_entities: Vec<EntityId>,

View file

@ -1,8 +1,9 @@
use bitbuffer::{BitRead, BitReadStream, BitWrite, BitWriteStream, Endianness}; use bitbuffer::{BitRead, BitReadStream, BitWrite, BitWriteStream, Endianness};
use serde::{Deserialize, Serialize};
use crate::ReadResult; use crate::ReadResult;
#[derive(Debug, BitWrite, PartialEq)] #[derive(Debug, BitWrite, PartialEq, Serialize, Deserialize)]
pub struct ConVar { pub struct ConVar {
key: String, key: String,
value: String, value: String,
@ -20,7 +21,7 @@ impl<E: Endianness> BitRead<'_, E> for ConVar {
} }
} }
#[derive(Debug, BitRead, PartialEq)] #[derive(Debug, BitRead, PartialEq, Serialize, Deserialize)]
pub struct SetConVarMessage { pub struct SetConVarMessage {
length: u8, length: u8,
#[size = "length"] #[size = "length"]

View file

@ -2,6 +2,7 @@ use bitbuffer::{
BitReadBuffer, BitReadStream, BitWrite, BitWriteSized, BitWriteStream, LittleEndian, BitReadBuffer, BitReadStream, BitWrite, BitWriteSized, BitWriteStream, LittleEndian,
}; };
use num_traits::{PrimInt, Unsigned}; use num_traits::{PrimInt, Unsigned};
use serde::{Deserialize, Serialize};
use snap::raw::{decompress_len, Decoder}; use snap::raw::{decompress_len, Decoder};
use crate::demo::lzss::decompress; use crate::demo::lzss::decompress;
@ -13,12 +14,13 @@ use crate::{Parse, ParseError, ParserState, ReadResult, Result, Stream};
use std::borrow::Cow; use std::borrow::Cow;
use std::cmp::min; use std::cmp::min;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(bound(deserialize = "'a: 'static"))]
pub struct CreateStringTableMessage<'a> { pub struct CreateStringTableMessage<'a> {
pub table: StringTable<'a>, pub table: StringTable<'a>,
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct StringTableMeta { pub struct StringTableMeta {
pub max_entries: u16, pub max_entries: u16,
pub fixed_userdata_size: Option<FixedUserDataSize>, pub fixed_userdata_size: Option<FixedUserDataSize>,
@ -233,7 +235,8 @@ fn test_create_string_table_roundtrip() {
); );
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(bound(deserialize = "'a: 'static"))]
pub struct UpdateStringTableMessage<'a> { pub struct UpdateStringTableMessage<'a> {
pub entries: Vec<(u16, StringTableEntry<'a>)>, pub entries: Vec<(u16, StringTableEntry<'a>)>,
pub table_id: u8, pub table_id: u8,

View file

@ -7,13 +7,14 @@ use crate::demo::sendprop::SendProp;
use crate::Result; use crate::Result;
use crate::{Parse, ParseError, ParserState, Stream}; use crate::{Parse, ParseError, ParserState, Stream};
use bitbuffer::{BitWrite, BitWriteSized, BitWriteStream, LittleEndian}; use bitbuffer::{BitWrite, BitWriteSized, BitWriteStream, LittleEndian};
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct TempEntitiesMessage { pub struct TempEntitiesMessage {
pub events: Vec<EventInfo>, pub events: Vec<EventInfo>,
} }
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct EventInfo { pub struct EventInfo {
pub class_id: ClassId, pub class_id: ClassId,
pub fire_delay: f32, pub fire_delay: f32,

View file

@ -5,7 +5,7 @@ use crate::demo::handle_utf8_error;
use crate::{ReadResult, Stream}; use crate::{ReadResult, Stream};
#[derive(BitRead, BitWrite, Clone, Copy, Debug, PartialEq, Eq)] #[derive(BitRead, BitWrite, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[repr(u8)] #[repr(u8)]
#[discriminant_bits = 8] #[discriminant_bits = 8]
pub enum UserMessageType { pub enum UserMessageType {
@ -70,7 +70,8 @@ pub enum UserMessageType {
Unknown = 255, Unknown = 255,
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(bound(deserialize = "'a: 'static"))]
pub enum UserMessage<'a> { pub enum UserMessage<'a> {
SayText2(Box<SayText2Message>), SayText2(Box<SayText2Message>),
Text(Box<TextMessage>), Text(Box<TextMessage>),
@ -204,7 +205,7 @@ impl BitWrite<LittleEndian> for ChatMessageKind {
} }
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SayText2Message { pub struct SayText2Message {
pub client: u8, pub client: u8,
pub raw: u8, pub raw: u8,
@ -312,7 +313,7 @@ fn test_say_text2_roundtrip() {
}); });
} }
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)] #[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[discriminant_bits = 8] #[discriminant_bits = 8]
pub enum HudTextLocation { pub enum HudTextLocation {
PrintNotify = 1, PrintNotify = 1,
@ -321,31 +322,31 @@ pub enum HudTextLocation {
PrintCenter, PrintCenter,
} }
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)] #[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TextMessage { pub struct TextMessage {
pub location: HudTextLocation, pub location: HudTextLocation,
pub text: String, pub text: String,
pub substitute: [String; 4], pub substitute: [String; 4],
} }
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)] #[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ResetHudMessage { pub struct ResetHudMessage {
pub data: u8, pub data: u8,
} }
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)] #[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TrainMessage { pub struct TrainMessage {
pub data: u8, pub data: u8,
} }
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)] #[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct VoiceSubtitleMessage { pub struct VoiceSubtitleMessage {
client: u8, client: u8,
menu: u8, menu: u8,
item: u8, item: u8,
} }
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)] #[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ShakeMessage { pub struct ShakeMessage {
command: u8, command: u8,
amplitude: f32, amplitude: f32,
@ -353,7 +354,8 @@ pub struct ShakeMessage {
duration: f32, duration: f32,
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(bound(deserialize = "'a: 'static"))]
pub struct UnknownUserMessage<'a> { pub struct UnknownUserMessage<'a> {
data: Stream<'a>, data: Stream<'a>,
} }

View file

@ -1,8 +1,9 @@
use bitbuffer::{BitRead, BitWrite, BitWriteSized, BitWriteStream, LittleEndian}; use bitbuffer::{BitRead, BitWrite, BitWriteSized, BitWriteStream, LittleEndian};
use serde::{Deserialize, Serialize};
use crate::{ReadResult, Stream}; use crate::{ReadResult, Stream};
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct VoiceInitMessage { pub struct VoiceInitMessage {
codec: String, codec: String,
quality: u8, quality: u8,
@ -57,8 +58,9 @@ fn test_voice_init_roundtrip() {
}); });
} }
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)] #[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[endianness = "LittleEndian"] #[endianness = "LittleEndian"]
#[serde(bound(deserialize = "'a: 'static"))]
pub struct VoiceDataMessage<'a> { pub struct VoiceDataMessage<'a> {
client: u8, client: u8,
proximity: u8, proximity: u8,
@ -67,7 +69,8 @@ pub struct VoiceDataMessage<'a> {
data: Stream<'a>, data: Stream<'a>,
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(bound(deserialize = "'a: 'static"))]
pub struct ParseSoundsMessage<'a> { pub struct ParseSoundsMessage<'a> {
pub reliable: bool, pub reliable: bool,
pub num: u8, pub num: u8,

View file

@ -1,8 +1,8 @@
use bitbuffer::{BitRead, BitWrite, LittleEndian};
use crate::{ReadResult, Stream}; use crate::{ReadResult, Stream};
use bitbuffer::{BitRead, BitWrite, LittleEndian};
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct ConsoleCmdPacket { pub struct ConsoleCmdPacket {
pub tick: u32, pub tick: u32,
pub command: String, pub command: String,

View file

@ -11,7 +11,20 @@ use std::convert::TryFrom;
use std::iter::once; use std::iter::once;
#[derive( #[derive(
BitRead, BitWrite, Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd, Display, FromStr, BitRead,
BitWrite,
Debug,
Clone,
Copy,
PartialEq,
Eq,
Hash,
Ord,
PartialOrd,
Display,
FromStr,
Serialize,
Deserialize,
)] )]
pub struct ClassId(u16); pub struct ClassId(u16);
@ -54,7 +67,7 @@ impl From<&str> for ServerClassName {
} }
} }
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)] #[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ServerClass { pub struct ServerClass {
pub id: ClassId, pub id: ClassId,
pub name: ServerClassName, pub name: ServerClassName,
@ -96,7 +109,7 @@ impl From<&str> for SendTableName {
} }
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ParseSendTable { pub struct ParseSendTable {
pub name: SendTableName, pub name: SendTableName,
pub props: Vec<RawSendPropDefinition>, pub props: Vec<RawSendPropDefinition>,
@ -318,7 +331,7 @@ impl ParseSendTable {
} }
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SendTable { pub struct SendTable {
pub name: SendTableName, pub name: SendTableName,
pub needs_decoder: bool, pub needs_decoder: bool,
@ -326,7 +339,7 @@ pub struct SendTable {
pub flattened_props: Vec<SendPropDefinition>, pub flattened_props: Vec<SendPropDefinition>,
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct DataTablePacket { pub struct DataTablePacket {
pub tick: u32, pub tick: u32,
pub tables: Vec<ParseSendTable>, pub tables: Vec<ParseSendTable>,

View file

@ -1,11 +1,12 @@
use bitbuffer::{bit_size_of, BitRead, BitWrite, BitWriteStream, Endianness, LittleEndian}; use bitbuffer::{bit_size_of, BitRead, BitWrite, BitWriteStream, Endianness, LittleEndian};
use serde::{Deserialize, Serialize};
use crate::demo::message::{Message, MessageType}; use crate::demo::message::{Message, MessageType};
use crate::demo::parser::Encode; use crate::demo::parser::Encode;
use crate::demo::vector::Vector; use crate::demo::vector::Vector;
use crate::{Parse, ParserState, ReadResult, Result, Stream}; use crate::{Parse, ParserState, ReadResult, Result, Stream};
#[derive(Debug, BitRead, BitWrite, PartialEq)] #[derive(Debug, BitRead, BitWrite, PartialEq, Serialize, Deserialize)]
pub struct MessagePacketMeta { pub struct MessagePacketMeta {
pub flags: u32, // TODO pub flags: u32, // TODO
pub view_angles: ViewAngles, pub view_angles: ViewAngles,
@ -13,14 +14,15 @@ pub struct MessagePacketMeta {
pub sequence_out: u32, pub sequence_out: u32,
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(bound(deserialize = "'a: 'static"))]
pub struct MessagePacket<'a> { pub struct MessagePacket<'a> {
pub tick: u32, pub tick: u32,
pub messages: Vec<Message<'a>>, pub messages: Vec<Message<'a>>,
pub meta: MessagePacketMeta, pub meta: MessagePacketMeta,
} }
#[derive(Clone, Debug, PartialEq, Default)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct ViewAngles { pub struct ViewAngles {
pub origin: (Vector, Vector), pub origin: (Vector, Vector),
pub angles: (Vector, Vector), pub angles: (Vector, Vector),

View file

@ -10,6 +10,7 @@ use self::stringtable::StringTablePacket;
use self::synctick::SyncTickPacket; use self::synctick::SyncTickPacket;
use self::usercmd::UserCmdPacket; use self::usercmd::UserCmdPacket;
use crate::demo::parser::Encode; use crate::demo::parser::Encode;
use serde::{Deserialize, Serialize};
pub mod consolecmd; pub mod consolecmd;
pub mod datatable; pub mod datatable;
@ -19,7 +20,8 @@ pub mod stringtable;
pub mod synctick; pub mod synctick;
pub mod usercmd; pub mod usercmd;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(bound(deserialize = "'a: 'static"))]
pub enum Packet<'a> { pub enum Packet<'a> {
Sigon(MessagePacket<'a>), Sigon(MessagePacket<'a>),
Message(MessagePacket<'a>), Message(MessagePacket<'a>),

View file

@ -1,6 +1,7 @@
use bitbuffer::{BitRead, BitWrite}; use bitbuffer::{BitRead, BitWrite};
use serde::{Deserialize, Serialize};
#[derive(Debug, BitRead, BitWrite, PartialEq)] #[derive(Debug, BitRead, BitWrite, PartialEq, Serialize, Deserialize)]
pub struct StopPacket { pub struct StopPacket {
#[size = 24] #[size = 24]
pub tick: u32, pub tick: u32,

View file

@ -1,6 +1,6 @@
use std::fmt;
use bitbuffer::{BitRead, BitWrite, BitWriteStream, LittleEndian}; use bitbuffer::{BitRead, BitWrite, BitWriteStream, LittleEndian};
use serde::{Deserialize, Serialize};
use std::fmt;
use crate::demo::message::stringtable::StringTableMeta; use crate::demo::message::stringtable::StringTableMeta;
use crate::demo::parser::Encode; use crate::demo::parser::Encode;
@ -8,7 +8,7 @@ use crate::{Parse, ParseError, ParserState, ReadResult, Result, Stream};
use std::borrow::{Borrow, Cow}; use std::borrow::{Borrow, Cow};
use std::cmp::min; use std::cmp::min;
#[derive(BitRead, BitWrite, Clone, Copy, Debug, PartialEq)] #[derive(BitRead, BitWrite, Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct FixedUserDataSize { pub struct FixedUserDataSize {
#[size = 12] #[size = 12]
pub size: u16, pub size: u16,
@ -16,7 +16,8 @@ pub struct FixedUserDataSize {
pub bits: u8, pub bits: u8,
} }
#[derive(Debug)] #[derive(Debug, Serialize, Deserialize)]
#[serde(bound(deserialize = "'a: 'static"))]
pub struct StringTable<'a> { pub struct StringTable<'a> {
pub name: Cow<'a, str>, pub name: Cow<'a, str>,
pub entries: Vec<(u16, StringTableEntry<'a>)>, pub entries: Vec<(u16, StringTableEntry<'a>)>,
@ -144,8 +145,9 @@ fn test_string_table_roundtrip() {
}); });
} }
#[derive(BitRead, BitWrite, Clone, Debug, PartialEq)] #[derive(BitRead, BitWrite, Clone, Debug, PartialEq, Serialize, Deserialize)]
#[endianness = "LittleEndian"] #[endianness = "LittleEndian"]
#[serde(bound(deserialize = "'a: 'static"))]
pub struct ExtraData<'a> { pub struct ExtraData<'a> {
pub byte_len: u16, pub byte_len: u16,
#[size = "byte_len.saturating_mul(8)"] #[size = "byte_len.saturating_mul(8)"]
@ -159,7 +161,8 @@ impl<'a> ExtraData<'a> {
} }
} }
#[derive(Clone, Default, PartialEq)] #[derive(Clone, Default, PartialEq, Serialize, Deserialize)]
#[serde(bound(deserialize = "'a: 'static"))]
pub struct StringTableEntry<'a> { pub struct StringTableEntry<'a> {
pub text: Option<Cow<'a, str>>, pub text: Option<Cow<'a, str>>,
pub extra_data: Option<ExtraData<'a>>, pub extra_data: Option<ExtraData<'a>>,
@ -208,7 +211,8 @@ impl fmt::Debug for StringTableEntry<'_> {
} }
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(bound(deserialize = "'a: 'static"))]
pub struct StringTablePacket<'a> { pub struct StringTablePacket<'a> {
pub tick: u32, pub tick: u32,
pub tables: Vec<StringTable<'a>>, pub tables: Vec<StringTable<'a>>,

View file

@ -1,6 +1,7 @@
use bitbuffer::{BitRead, BitWrite}; use bitbuffer::{BitRead, BitWrite};
use serde::{Deserialize, Serialize};
#[derive(BitRead, BitWrite, Debug, PartialEq)] #[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
pub struct SyncTickPacket { pub struct SyncTickPacket {
pub tick: u32, pub tick: u32,
} }

View file

@ -1,6 +1,7 @@
use bitbuffer::{BitRead, BitReadStream, BitWrite, BitWriteStream, LittleEndian}; use bitbuffer::{BitRead, BitReadStream, BitWrite, BitWriteStream, LittleEndian};
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct UserCmdPacket { pub struct UserCmdPacket {
pub tick: u32, pub tick: u32,
pub sequence_out: u32, pub sequence_out: u32,
@ -30,7 +31,7 @@ impl BitWrite<LittleEndian> for UserCmdPacket {
} }
} }
#[derive(Debug, PartialEq, BitRead, BitWrite)] #[derive(Debug, PartialEq, BitRead, BitWrite, Serialize, Deserialize)]
pub struct UserCmd { pub struct UserCmd {
command_number: Option<u32>, command_number: Option<u32>,
tick_count: Option<u32>, tick_count: Option<u32>,
@ -43,7 +44,7 @@ pub struct UserCmd {
mouse_dy: Option<u16>, mouse_dy: Option<u16>,
} }
#[derive(Debug, PartialEq, BitRead, BitWrite)] #[derive(Debug, PartialEq, BitRead, BitWrite, Serialize, Deserialize)]
pub struct WeaponSelect { pub struct WeaponSelect {
#[size = 11] #[size = 11]
select: u16, select: u16,

View file

@ -14,9 +14,10 @@ use crate::demo::packet::stringtable::StringTableEntry;
use crate::demo::sendprop::SendProp; use crate::demo::sendprop::SendProp;
use crate::nullhasher::NullHasherBuilder; use crate::nullhasher::NullHasherBuilder;
use crate::{Result, Stream}; use crate::{Result, Stream};
use serde::{Deserialize, Serialize};
use std::cell::RefCell; use std::cell::RefCell;
#[derive(Default, Clone)] #[derive(Default, Clone, Serialize, Deserialize)]
pub struct DemoMeta { pub struct DemoMeta {
pub version: u16, pub version: u16,
pub game: String, pub game: String,

View file

@ -58,7 +58,7 @@ impl From<&str> for SendPropName {
} }
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RawSendPropDefinition { pub struct RawSendPropDefinition {
pub prop_type: SendPropType, pub prop_type: SendPropType,
pub name: SendPropName, pub name: SendPropName,
@ -252,7 +252,7 @@ impl BitWrite<LittleEndian> for RawSendPropDefinition {
} }
} }
#[derive(BitRead, BitWrite, Copy, Clone, PartialEq, Debug, Display)] #[derive(BitRead, BitWrite, Copy, Clone, PartialEq, Debug, Display, Serialize, Deserialize)]
#[discriminant_bits = 5] #[discriminant_bits = 5]
pub enum SendPropType { pub enum SendPropType {
Int = 0, Int = 0,
@ -310,7 +310,7 @@ pub enum SendPropFlag {
NormalVarInt = 32, NormalVarInt = 32,
} }
#[derive(Debug, Copy, Clone, PartialEq, Default)] #[derive(Debug, Copy, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct SendPropFlags(BitFlags<SendPropFlag>); pub struct SendPropFlags(BitFlags<SendPropFlag>);
impl BitOr<SendPropFlag> for SendPropFlags { impl BitOr<SendPropFlag> for SendPropFlags {
@ -356,7 +356,7 @@ impl BitWrite<LittleEndian> for SendPropFlags {
} }
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub enum FloatDefinition { pub enum FloatDefinition {
Coord, Coord,
CoordMP, CoordMP,
@ -398,7 +398,7 @@ impl FloatDefinition {
} }
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SendPropDefinition { pub struct SendPropDefinition {
pub identifier: SendPropIdentifier, pub identifier: SendPropIdentifier,
pub parse_definition: SendPropParseDefinition, pub parse_definition: SendPropParseDefinition,
@ -416,7 +416,7 @@ impl TryFrom<&RawSendPropDefinition> for SendPropDefinition {
} }
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SendPropParseDefinition { pub enum SendPropParseDefinition {
NormalVarInt { NormalVarInt {
changes_often: bool, changes_often: bool,
@ -1068,7 +1068,9 @@ impl<'a> TryFrom<&'a SendPropValue> for &'a [SendPropValue] {
} }
} }
#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Display)] #[derive(
Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Display, Serialize, Deserialize,
)]
pub struct SendPropIdentifier(u64); pub struct SendPropIdentifier(u64);
impl SendPropIdentifier { impl SendPropIdentifier {
@ -1084,7 +1086,7 @@ impl From<u64> for SendPropIdentifier {
} }
} }
#[derive(Debug, Clone, Display, PartialEq)] #[derive(Debug, Clone, Display, PartialEq, Serialize, Deserialize)]
#[display("{index} = {value}")] #[display("{index} = {value}")]
pub struct SendProp { pub struct SendProp {
pub index: u32, pub index: u32,

View file

@ -1,3 +1,4 @@
use serde::{Deserialize, Serialize};
use std::hash::{BuildHasher, Hasher}; use std::hash::{BuildHasher, Hasher};
/// A dummy hasher that maps simply returns the hashed u64 /// A dummy hasher that maps simply returns the hashed u64
@ -34,7 +35,7 @@ impl Hasher for NullHasher {
} }
} }
#[derive(Clone)] #[derive(Clone, Serialize, Deserialize, Default)]
pub struct NullHasherBuilder; pub struct NullHasherBuilder;
impl BuildHasher for NullHasherBuilder { impl BuildHasher for NullHasherBuilder {