mirror of
https://codeberg.org/demostf/parser.git
synced 2026-11-30 02:30:46 +01:00
make SetConVarMessage use Cow instead of String
This commit is contained in:
parent
541e175cdd
commit
1f7a80468e
3 changed files with 21 additions and 15 deletions
|
|
@ -1,3 +1,7 @@
|
|||
## 0.7.3
|
||||
|
||||
- `SetConVar` message now uses `Cow` instead of `String`
|
||||
|
||||
## 0.7.2
|
||||
|
||||
- Compress string tables, this fixes playback of encoded demos with large string
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ pub enum Message<'a> {
|
|||
File(FileMessage),
|
||||
NetTick(NetTickMessage),
|
||||
StringCmd(StringCmdMessage),
|
||||
SetConVar(SetConVarMessage),
|
||||
SetConVar(SetConVarMessage<'a>),
|
||||
SignOnState(SignOnStateMessage),
|
||||
Print(PrintMessage),
|
||||
ServerInfo(Box<ServerInfoMessage>),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
use bitbuffer::{BitRead, BitReadStream, Endianness};
|
||||
#[cfg(feature = "write")]
|
||||
use bitbuffer::{BitWrite, BitWriteStream};
|
||||
|
|
@ -8,33 +10,33 @@ use crate::ReadResult;
|
|||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "write", derive(BitWrite))]
|
||||
pub struct ConVar {
|
||||
pub key: String,
|
||||
pub value: String,
|
||||
pub struct ConVar<'a> {
|
||||
pub key: Cow<'a, str>,
|
||||
pub value: Cow<'a, str>,
|
||||
}
|
||||
|
||||
impl<E: Endianness> BitRead<'_, E> for ConVar {
|
||||
fn read(stream: &mut BitReadStream<'_, E>) -> ReadResult<Self> {
|
||||
impl<'a, E: Endianness> BitRead<'a, E> for ConVar<'a> {
|
||||
fn read(stream: &mut BitReadStream<'a, E>) -> ReadResult<Self> {
|
||||
let key = stream
|
||||
.read()
|
||||
.unwrap_or_else(|_| "Malformed cvar name".to_string());
|
||||
.unwrap_or_else(|_| "Malformed cvar name".into());
|
||||
let value = stream
|
||||
.read()
|
||||
.unwrap_or_else(|_| "Malformed cvar value".to_string());
|
||||
.unwrap_or_else(|_| "Malformed cvar value".into());
|
||||
Ok(ConVar { key, value })
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||
#[derive(Debug, BitRead, PartialEq, Serialize, Deserialize, Clone)]
|
||||
pub struct SetConVarMessage {
|
||||
pub struct SetConVarMessage<'a> {
|
||||
pub length: u8,
|
||||
#[size = "length"]
|
||||
pub vars: Vec<ConVar>,
|
||||
pub vars: Vec<ConVar<'a>>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "write")]
|
||||
impl<E: Endianness> BitWrite<E> for SetConVarMessage {
|
||||
impl<E: Endianness> BitWrite<E> for SetConVarMessage<'_> {
|
||||
fn write(&self, stream: &mut BitWriteStream<E>) -> ReadResult<()> {
|
||||
self.length.write(stream)?;
|
||||
self.vars.write(stream)
|
||||
|
|
@ -51,12 +53,12 @@ fn test_set_con_var_roundtrip() {
|
|||
length: 2,
|
||||
vars: vec![
|
||||
ConVar {
|
||||
key: "foo1".to_string(),
|
||||
value: "bar1".to_string(),
|
||||
key: "foo1".into(),
|
||||
value: "bar1".into(),
|
||||
},
|
||||
ConVar {
|
||||
key: "foo2".to_string(),
|
||||
value: "bar2".to_string(),
|
||||
key: "foo2".into(),
|
||||
value: "bar2".into(),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue