mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
better json serialize for event type
This commit is contained in:
parent
7ed264cae4
commit
2b01b3ba7c
3 changed files with 124 additions and 58 deletions
|
|
@ -3,7 +3,7 @@ use crate::demo::data::MaybeUtf8String;
|
|||
use crate::demo::Stream;
|
||||
use crate::{ParseError, Result};
|
||||
use bitbuffer::{BitRead, BitWrite, BitWriteStream, LittleEndian};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
fn read_value<'a, T: EventValue + BitRead<'a, LittleEndian> + Default>(
|
||||
stream: &mut Stream<'a>,
|
||||
entry: Option<&GameEventEntry>,
|
||||
|
|
@ -6712,7 +6712,7 @@ pub enum GameEvent {
|
|||
Unknown(RawGameEvent),
|
||||
}
|
||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum GameEventType {
|
||||
ServerSpawn,
|
||||
ServerChangeLevelFailed,
|
||||
|
|
@ -7117,6 +7117,23 @@ pub enum GameEventType {
|
|||
ReplayServerError,
|
||||
Unknown(String),
|
||||
}
|
||||
impl Serialize for GameEventType {
|
||||
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str(self.as_str())
|
||||
}
|
||||
}
|
||||
impl<'de> Deserialize<'de> for GameEventType {
|
||||
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let str = <&str>::deserialize(deserializer)?;
|
||||
Ok(GameEventType::from_type_name(str))
|
||||
}
|
||||
}
|
||||
impl GameEventType {
|
||||
pub fn from_type_name(name: &str) -> Self {
|
||||
match name {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue