mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
more usable name types
This commit is contained in:
parent
5da913cc5d
commit
5c10ef1a0c
2 changed files with 50 additions and 10 deletions
|
|
@ -12,6 +12,7 @@ use std::borrow::Cow;
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::iter::once;
|
use std::iter::once;
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||||
#[derive(
|
#[derive(
|
||||||
|
|
@ -127,6 +128,20 @@ impl PartialEq<&str> for SendTableName {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AsRef<str> for SendTableName {
|
||||||
|
fn as_ref(&self) -> &str {
|
||||||
|
self.0.as_ref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for SendTableName {
|
||||||
|
type Target = str;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
self.0.deref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct ParseSendTable {
|
pub struct ParseSendTable {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,3 @@
|
||||||
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};
|
|
||||||
|
|
||||||
use super::packet::datatable::ParseSendTable;
|
use super::packet::datatable::ParseSendTable;
|
||||||
use super::vector::{Vector, VectorXY};
|
use super::vector::{Vector, VectorXY};
|
||||||
use crate::consthash::ConstFnvHash;
|
use crate::consthash::ConstFnvHash;
|
||||||
|
|
@ -14,13 +5,20 @@ use crate::demo::message::stringtable::log_base2;
|
||||||
use crate::demo::packet::datatable::SendTableName;
|
use crate::demo::packet::datatable::SendTableName;
|
||||||
use crate::demo::parser::MalformedSendPropDefinitionError;
|
use crate::demo::parser::MalformedSendPropDefinitionError;
|
||||||
use crate::demo::sendprop_gen::get_prop_names;
|
use crate::demo::sendprop_gen::get_prop_names;
|
||||||
|
use crate::{ParseError, ReadResult, Result, Stream};
|
||||||
|
use bitbuffer::{
|
||||||
|
BitRead, BitReadStream, BitWrite, BitWriteSized, BitWriteStream, Endianness, LittleEndian,
|
||||||
|
};
|
||||||
|
use enumflags2::{bitflags, BitFlags};
|
||||||
use num_traits::Signed;
|
use num_traits::Signed;
|
||||||
use parse_display::Display;
|
use parse_display::Display;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use std::convert::{TryFrom, TryInto};
|
use std::convert::{TryFrom, TryInto};
|
||||||
use std::fmt::{self, Display, Formatter};
|
use std::fmt::{self, Display, Formatter};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::ops::BitOr;
|
use std::ops::{BitOr, Deref};
|
||||||
|
|
||||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||||
#[derive(
|
#[derive(
|
||||||
|
|
@ -58,6 +56,20 @@ impl From<&'static str> for SendPropName {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AsRef<str> for SendPropName {
|
||||||
|
fn as_ref(&self) -> &str {
|
||||||
|
self.0.as_ref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for SendPropName {
|
||||||
|
type Target = str;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
self.0.deref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct RawSendPropDefinition {
|
pub struct RawSendPropDefinition {
|
||||||
|
|
@ -1113,13 +1125,26 @@ impl SendPropIdentifier {
|
||||||
SendPropIdentifier(hasher.finish())
|
SendPropIdentifier(hasher.finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This returns an option because only props known at compile time will return a name here
|
||||||
|
///
|
||||||
|
/// If you need to know the name of every property you need to keep a map yourself
|
||||||
pub fn table_name(&self) -> Option<SendTableName> {
|
pub fn table_name(&self) -> Option<SendTableName> {
|
||||||
get_prop_names(*self).map(|(table, _)| table.into())
|
get_prop_names(*self).map(|(table, _)| table.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This returns an option because only props known at compile time will return a name here
|
||||||
|
///
|
||||||
|
/// If you need to know the name of every property you need to keep a map yourself
|
||||||
pub fn prop_name(&self) -> Option<SendPropName> {
|
pub fn prop_name(&self) -> Option<SendPropName> {
|
||||||
get_prop_names(*self).map(|(_, prop)| prop.into())
|
get_prop_names(*self).map(|(_, prop)| prop.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This returns an option because only props known at compile time will return a name here
|
||||||
|
///
|
||||||
|
/// If you need to know the name of every property you need to keep a map yourself
|
||||||
|
pub fn names(&self) -> Option<(SendTableName, SendPropName)> {
|
||||||
|
get_prop_names(*self).map(|(table, prop)| (table.into(), prop.into()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u64> for SendPropIdentifier {
|
impl From<u64> for SendPropIdentifier {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue