mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
propnames
This commit is contained in:
parent
5976b43d56
commit
b8d3540069
9 changed files with 5643 additions and 88 deletions
104
Cargo.lock
generated
104
Cargo.lock
generated
|
|
@ -68,9 +68,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "bitbuffer"
|
||||
version = "0.10.3"
|
||||
version = "0.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "650346fecc0be01be480d078b014cc0deb000d26790a53f6ef854dda35f87d62"
|
||||
checksum = "2a1011b65695f83be55d63eadf310a4c28da66550b196bca815eb94ec8885da8"
|
||||
dependencies = [
|
||||
"bitbuffer_derive",
|
||||
"err-derive",
|
||||
|
|
@ -94,9 +94,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.72"
|
||||
version = "1.0.73"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
|
||||
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
|
|
@ -119,9 +119,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ctor"
|
||||
version = "0.1.21"
|
||||
version = "0.1.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ccc0a48a9b826acdf4028595adc9db92caea352f7af011a3034acd172a52a0aa"
|
||||
checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
|
|
@ -135,9 +135,9 @@ checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499"
|
|||
|
||||
[[package]]
|
||||
name = "dyn-clone"
|
||||
version = "1.0.4"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee2626afccd7561a06cf1367e2950c4718ea04565e20fb5029b6c7d8ad09abcf"
|
||||
checksum = "21e50f3adc76d6a43f5ed73b698a87d0760ca74617f60f7c3b879003536fdd28"
|
||||
|
||||
[[package]]
|
||||
name = "encode_unicode"
|
||||
|
|
@ -156,9 +156,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "enumflags2"
|
||||
version = "0.7.3"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a25c90b056b3f84111cf183cbeddef0d3a0bbe9a674f057e1a1533c315f24def"
|
||||
checksum = "1b3ab37dc79652c9d85f1f7b6070d77d321d2467f5fe7b00d6b7a86c57b092ae"
|
||||
dependencies = [
|
||||
"enumflags2_derive",
|
||||
"serde",
|
||||
|
|
@ -166,9 +166,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "enumflags2_derive"
|
||||
version = "0.7.3"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "144ec79496cbab6f84fa125dc67be9264aef22eb8a28da8454d9c33f15108da4"
|
||||
checksum = "f58dc3c5e468259f19f2d46304a6b28f1c3d034442e14b322d2b850e36f6d5ae"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -177,9 +177,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "err-derive"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcc7f65832b62ed38939f98966824eb6294911c3629b0e9a262bfb80836d9686"
|
||||
checksum = "c34a887c8df3ed90498c1c437ce21f211c8e27672921a8ffa293cb8d6d4caa9e"
|
||||
dependencies = [
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
|
|
@ -248,15 +248,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.117"
|
||||
version = "0.2.122"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c"
|
||||
checksum = "ec647867e2bf0772e28c8bcde4f0d19a9216916e890543b5a03ed8ef27b8f259"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.14"
|
||||
version = "0.4.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
|
||||
checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
|
@ -390,18 +390,18 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "num_enum"
|
||||
version = "0.5.6"
|
||||
version = "0.5.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "720d3ea1055e4e4574c0c0b0f8c3fd4f24c4cdaf465948206dea090b57b526ad"
|
||||
checksum = "cf5395665662ef45796a4ff5486c5d41d29e0c09640af4c5f17fd94ee2c119c9"
|
||||
dependencies = [
|
||||
"num_enum_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_enum_derive"
|
||||
version = "0.5.6"
|
||||
version = "0.5.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d992b768490d7fe0d8586d9b5745f6c49f557da6d81dc982b1d167ad4edbb21"
|
||||
checksum = "3b0498641e53dd6ac1a4f22547548caa6864cc4933784319cd1775271c5a46ce"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
|
|
@ -420,24 +420,24 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.9.0"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
|
||||
checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
|
||||
|
||||
[[package]]
|
||||
name = "output_vt100"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9"
|
||||
checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parse-display"
|
||||
version = "0.5.3"
|
||||
version = "0.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "898bf4c2a569dedbfd4e6c3f0bbd0ae825e5b6b0b69bae3e3c1000158689334a"
|
||||
checksum = "813e91c6232dbeb2e9deba0eb0dc5c967bd6f380676fd34419f9ddd71411faa7"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"parse-display-derive",
|
||||
|
|
@ -446,9 +446,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "parse-display-derive"
|
||||
version = "0.5.3"
|
||||
version = "0.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1779d1e28ab04568223744c2af4aa4e642e67b92c76bdce0929a6d2c36267199"
|
||||
checksum = "007ed61a69cf7d9b95cc5dc18489dbb4f70d4adb0a0c100e2dd46f0be241711a"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
|
|
@ -467,9 +467,9 @@ checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c"
|
|||
|
||||
[[package]]
|
||||
name = "pretty_assertions"
|
||||
version = "1.1.0"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76d5b548b725018ab5496482b45cb8bef21e9fed1858a6d674e3a8a0f0bb5d50"
|
||||
checksum = "c89f989ac94207d048d92db058e4f6ec7342b0971fc58d1271ca148b799b3563"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"ctor",
|
||||
|
|
@ -479,9 +479,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "1.1.0"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83"
|
||||
checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
"toml",
|
||||
|
|
@ -513,27 +513,27 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.36"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
|
||||
checksum = "ec757218438d5fda206afc041538b2f6d889286160d649a86a24d37e1235afd1"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.15"
|
||||
version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145"
|
||||
checksum = "632d02bff7f874a36f33ea8bb416cd484b90cc66c1194b1a1110d067a7013f58"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.5.4"
|
||||
version = "1.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
|
||||
checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
|
|
@ -630,9 +630,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.78"
|
||||
version = "1.0.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d23c1ba4cf0efd44be32017709280b32d1cea5c3f1275c3b6d9e8bc54f758085"
|
||||
checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
|
|
@ -711,9 +711,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.86"
|
||||
version = "1.0.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b"
|
||||
checksum = "b683b2b825c8eef438b77c36a06dc262294da3d5a5813fac20da149241dcd44d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -834,9 +834,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tracing"
|
||||
version = "0.1.30"
|
||||
version = "0.1.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d8d93354fe2a8e50d5953f5ae2e47a3fc2ef03292e7ea46e3cc38f549525fb9"
|
||||
checksum = "4a1bdf54a7c28a2bbf701e1d2233f6c77f473486b94bee4f9678da5a148dca7f"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"pin-project-lite",
|
||||
|
|
@ -846,9 +846,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.19"
|
||||
version = "0.1.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8276d9a4a3a558d7b7ad5303ad50b53d58264641b82914b7ada36bd762e7a716"
|
||||
checksum = "2e65ce065b4b5c53e73bb28912318cb8c9e9ad3921f1d669eb0e68b4c8143a2b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -857,9 +857,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.22"
|
||||
version = "0.1.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03cfcb51380632a72d3111cb8d3447a8d908e577d31beeac006f836383d29a23"
|
||||
checksum = "90442985ee2f57c9e1b548ee72ae842f4a9a20e3f417cc38dbc5dc684d9bb4ee"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"valuable",
|
||||
|
|
@ -878,9 +878,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.3.8"
|
||||
version = "0.3.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "74786ce43333fcf51efe947aed9718fbe46d5c7328ec3f1029e818083966d9aa"
|
||||
checksum = "b9df98b037d039d03400d9dd06b0f8ce05486b5f25e9a2d7d36196e142ebbc52"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"lazy_static",
|
||||
|
|
|
|||
|
|
@ -72,8 +72,7 @@ pub fn generate_prop_names(demo: Demo) -> TokenStream {
|
|||
.unwrap();
|
||||
|
||||
let imports = quote!(
|
||||
use tf_demo_parser::demo::packet::datatable::SendTableName;
|
||||
use tf_demo_parser::demo::sendprop::{SendPropIdentifier, SendPropName};
|
||||
use crate::demo::sendprop::SendPropIdentifier;
|
||||
);
|
||||
|
||||
let matches = props.into_iter().map(|prop| {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use crate::demo::message::packetentities::EntityId;
|
||||
use crate::demo::packet::stringtable::{ExtraData, StringTableEntry};
|
||||
use crate::demo::parser::analyser::UserId;
|
||||
use crate::{ReadResult, Stream};
|
||||
use bitbuffer::{BitRead, BitReadBuffer, BitReadStream, BitWrite, BitWriteStream, LittleEndian};
|
||||
|
||||
|
|
@ -24,7 +25,7 @@ struct RawPlayerInfo {
|
|||
pub struct PlayerInfo {
|
||||
#[size = 32]
|
||||
pub name: String,
|
||||
pub user_id: u32,
|
||||
pub user_id: UserId,
|
||||
#[size = 32]
|
||||
pub steam_id: String,
|
||||
pub extra: u32, // all my sources say these 4 bytes don't exist
|
||||
|
|
@ -44,7 +45,7 @@ impl From<RawPlayerInfo> for PlayerInfo {
|
|||
name: String::from_utf8_lossy(&raw.name_bytes)
|
||||
.trim_end_matches('\0')
|
||||
.to_string(),
|
||||
user_id: raw.user_id,
|
||||
user_id: raw.user_id.into(),
|
||||
steam_id: raw.steam_id,
|
||||
extra: raw.extra,
|
||||
friends_id: raw.friends_id,
|
||||
|
|
|
|||
|
|
@ -38,6 +38,18 @@ impl From<u32> for EntityId {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<EntityId> for u32 {
|
||||
fn from(id: EntityId) -> Self {
|
||||
id.0
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<u32> for EntityId {
|
||||
fn eq(&self, other: &u32) -> bool {
|
||||
self.0 == *other
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||
#[derive(
|
||||
BitRead, BitWrite, Clone, Copy, Debug, PartialEq, Eq, Serialize_repr, Deserialize_repr,
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ pub mod message;
|
|||
pub mod packet;
|
||||
pub mod parser;
|
||||
pub mod sendprop;
|
||||
mod sendprop_gen;
|
||||
pub mod vector;
|
||||
|
||||
pub type Buffer<'a> = BitReadBuffer<'a, LittleEndian>;
|
||||
|
|
|
|||
|
|
@ -3,9 +3,12 @@ use crate::demo::sendprop::{
|
|||
RawSendPropDefinition, SendPropDefinition, SendPropFlag, SendPropIdentifier, SendPropType,
|
||||
};
|
||||
use crate::{Parse, ParseError, ParserState, Result, Stream};
|
||||
use bitbuffer::{BitRead, BitWrite, BitWriteSized, BitWriteStream, LittleEndian};
|
||||
use bitbuffer::{
|
||||
BitRead, BitReadStream, BitWrite, BitWriteSized, BitWriteStream, Endianness, LittleEndian,
|
||||
};
|
||||
use parse_display::{Display, FromStr};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::borrow::Cow;
|
||||
use std::cmp::min;
|
||||
use std::convert::TryFrom;
|
||||
use std::iter::once;
|
||||
|
|
@ -79,7 +82,6 @@ pub struct ServerClass {
|
|||
|
||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||
#[derive(
|
||||
BitRead,
|
||||
BitWrite,
|
||||
PartialEq,
|
||||
Eq,
|
||||
|
|
@ -93,23 +95,29 @@ pub struct ServerClass {
|
|||
Ord,
|
||||
Default,
|
||||
)]
|
||||
pub struct SendTableName(String);
|
||||
pub struct SendTableName(Cow<'static, str>);
|
||||
|
||||
impl SendTableName {
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.0.as_str()
|
||||
self.0.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Endianness> BitRead<'_, E> for SendTableName {
|
||||
fn read(stream: &mut BitReadStream<'_, E>) -> bitbuffer::Result<Self> {
|
||||
String::read(stream).map(SendTableName::from)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for SendTableName {
|
||||
fn from(value: String) -> Self {
|
||||
Self(value)
|
||||
Self(Cow::Owned(value))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for SendTableName {
|
||||
fn from(value: &str) -> Self {
|
||||
Self(value.into())
|
||||
impl From<&'static str> for SendTableName {
|
||||
fn from(value: &'static str) -> Self {
|
||||
Self(Cow::Borrowed(value))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use crate::demo::packet::stringtable::StringTableEntry;
|
|||
use crate::demo::parser::handler::{BorrowMessageHandler, MessageHandler};
|
||||
use crate::demo::vector::Vector;
|
||||
use crate::{ParserState, ReadResult, Stream};
|
||||
use bitbuffer::{BitWrite, BitWriteStream, Endianness};
|
||||
use num_enum::TryFromPrimitive;
|
||||
use parse_display::{Display, FromStr};
|
||||
use serde::de::Error;
|
||||
|
|
@ -211,6 +212,12 @@ impl From<HashMap<Class, u8>> for ClassList {
|
|||
)]
|
||||
pub struct UserId(pub u8);
|
||||
|
||||
impl<E: Endianness> BitWrite<E> for UserId {
|
||||
fn write(&self, stream: &mut BitWriteStream<E>) -> ReadResult<()> {
|
||||
(self.0 as u32).write(stream)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for UserId {
|
||||
fn from(int: u32) -> Self {
|
||||
UserId((int & 255) as u8)
|
||||
|
|
@ -223,6 +230,24 @@ impl From<u16> for UserId {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<UserId> for u8 {
|
||||
fn from(id: UserId) -> Self {
|
||||
id.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<UserId> for u32 {
|
||||
fn from(id: UserId) -> Self {
|
||||
id.0 as u32
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<u8> for UserId {
|
||||
fn eq(&self, other: &u8) -> bool {
|
||||
self.0 == *other
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Spawn {
|
||||
pub user: UserId,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
use bitbuffer::{BitRead, BitWrite, BitWriteSized, BitWriteStream, LittleEndian};
|
||||
use bitbuffer::{
|
||||
BitRead, BitReadStream, BitWrite, BitWriteSized, BitWriteStream, Endianness, LittleEndian,
|
||||
};
|
||||
use enumflags2::{bitflags, BitFlags};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::{ParseError, ReadResult, Result, Stream};
|
||||
|
||||
|
|
@ -10,52 +13,48 @@ use crate::consthash::ConstFnvHash;
|
|||
use crate::demo::message::stringtable::log_base2;
|
||||
use crate::demo::packet::datatable::SendTableName;
|
||||
use crate::demo::parser::MalformedSendPropDefinitionError;
|
||||
use crate::demo::sendprop_gen::get_prop_names;
|
||||
use num_traits::Signed;
|
||||
use parse_display::Display;
|
||||
use std::cmp::min;
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::fmt;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::hash::Hash;
|
||||
use std::ops::BitOr;
|
||||
|
||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||
#[derive(
|
||||
BitRead,
|
||||
BitWrite,
|
||||
PartialEq,
|
||||
Eq,
|
||||
Hash,
|
||||
Debug,
|
||||
Display,
|
||||
Clone,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Ord,
|
||||
PartialOrd,
|
||||
BitWrite, PartialEq, Eq, Hash, Debug, Display, Clone, Serialize, Deserialize, Ord, PartialOrd,
|
||||
)]
|
||||
pub struct SendPropName(String);
|
||||
pub struct SendPropName(Cow<'static, str>);
|
||||
|
||||
impl SendPropName {
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.0.as_str()
|
||||
self.0.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Endianness> BitRead<'_, E> for SendPropName {
|
||||
fn read(stream: &mut BitReadStream<'_, E>) -> bitbuffer::Result<Self> {
|
||||
String::read(stream).map(SendPropName::from)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<&str> for SendPropName {
|
||||
fn eq(&self, other: &&str) -> bool {
|
||||
self.0.as_str() == *other
|
||||
self.as_str() == *other
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for SendPropName {
|
||||
fn from(value: String) -> Self {
|
||||
Self(value)
|
||||
Self(Cow::Owned(value))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for SendPropName {
|
||||
fn from(value: &str) -> Self {
|
||||
value.to_string().into()
|
||||
impl From<&'static str> for SendPropName {
|
||||
fn from(value: &'static str) -> Self {
|
||||
SendPropName(Cow::Borrowed(value))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1105,9 +1104,7 @@ impl<'a> TryFrom<&'a SendPropValue> for &'a [SendPropValue] {
|
|||
}
|
||||
|
||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||
#[derive(
|
||||
Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Display, Serialize, Deserialize,
|
||||
)]
|
||||
#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||
pub struct SendPropIdentifier(u64);
|
||||
|
||||
impl SendPropIdentifier {
|
||||
|
|
@ -1115,6 +1112,14 @@ impl SendPropIdentifier {
|
|||
let hasher = ConstFnvHash::new().push_string(table).push_string(prop);
|
||||
SendPropIdentifier(hasher.finish())
|
||||
}
|
||||
|
||||
pub fn table_name(&self) -> Option<SendTableName> {
|
||||
get_prop_names(*self).map(|(table, _)| table.into())
|
||||
}
|
||||
|
||||
pub fn prop_name(&self) -> Option<SendPropName> {
|
||||
get_prop_names(*self).map(|(_, prop)| prop.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for SendPropIdentifier {
|
||||
|
|
@ -1123,6 +1128,21 @@ impl From<u64> for SendPropIdentifier {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<SendPropIdentifier> for u64 {
|
||||
fn from(identifier: SendPropIdentifier) -> Self {
|
||||
identifier.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for SendPropIdentifier {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
match get_prop_names(*self) {
|
||||
Some((table, prop)) => write!(f, "{}.{}", table, prop),
|
||||
None => write!(f, "Prop name {} not known", self.0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||
#[derive(Debug, Clone, Display, PartialEq, Serialize, Deserialize)]
|
||||
#[display("{index} = {value}")]
|
||||
|
|
|
|||
5489
src/demo/sendprop_gen.rs
Normal file
5489
src/demo/sendprop_gen.rs
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue