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

more usefull Debug for SendProp

This commit is contained in:
Robin Appelman 2022-04-10 19:33:51 +02:00
commit a9a527fb5c

View file

@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize};
use std::borrow::Cow; 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, Debug, Display, Formatter};
use std::hash::Hash; use std::hash::Hash;
use std::ops::{BitOr, Deref}; use std::ops::{BitOr, Deref};
@ -635,11 +635,11 @@ impl PartialEq for SendPropValue {
impl fmt::Display for SendPropValue { impl fmt::Display for SendPropValue {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
SendPropValue::Vector(vector) => vector.fmt(f), SendPropValue::Vector(vector) => Display::fmt(vector, f),
SendPropValue::VectorXY(vector) => vector.fmt(f), SendPropValue::VectorXY(vector) => Display::fmt(vector, f),
SendPropValue::Integer(int) => int.fmt(f), SendPropValue::Integer(int) => Display::fmt(int, f),
SendPropValue::Float(float) => float.fmt(f), SendPropValue::Float(float) => Display::fmt(float, f),
SendPropValue::String(string) => string.fmt(f), SendPropValue::String(string) => Display::fmt(string, f),
SendPropValue::Array(array) => { SendPropValue::Array(array) => {
write!(f, "[")?; write!(f, "[")?;
for child in array { for child in array {
@ -1169,7 +1169,7 @@ impl Display for SendPropIdentifier {
} }
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Display, PartialEq, Serialize, Deserialize)] #[derive(Clone, Display, PartialEq, Serialize, Deserialize)]
#[display("{index} = {value}")] #[display("{index} = {value}")]
pub struct SendProp { pub struct SendProp {
pub index: u32, pub index: u32,
@ -1177,6 +1177,12 @@ pub struct SendProp {
pub value: SendPropValue, pub value: SendPropValue,
} }
impl Debug for SendProp {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{} = {}", self.identifier, self.value)
}
}
pub fn read_var_int(stream: &mut Stream, signed: bool) -> ReadResult<i32> { pub fn read_var_int(stream: &mut Stream, signed: bool) -> ReadResult<i32> {
let abs_int = crate::demo::message::stringtable::read_var_int(stream)? as i32; let abs_int = crate::demo::message::stringtable::read_var_int(stream)? as i32;