change how Any is deserialized
This commit is contained in:
parent
6a70df89ed
commit
f48e2d232b
2 changed files with 58 additions and 5 deletions
|
|
@ -1,3 +1,4 @@
|
|||
use log::warn;
|
||||
use rnex_core::rmc::structures::{Result, RmcSerialize};
|
||||
use std::io::{Cursor, Read, Write};
|
||||
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
|
||||
|
|
@ -21,11 +22,23 @@ impl RmcSerialize for Any {
|
|||
fn deserialize(reader: &mut impl Read) -> Result<Self> {
|
||||
let name = String::deserialize(reader)?;
|
||||
|
||||
// also length ?
|
||||
let _len2: u32 = reader.read_struct(IS_BIG_ENDIAN)?;
|
||||
let data = Vec::deserialize(reader)?;
|
||||
let mut cursor = Cursor::new(&data);
|
||||
// also length ?
|
||||
let len2: u32 = cursor.read_struct(IS_BIG_ENDIAN)?;
|
||||
|
||||
Ok(Any { name, data })
|
||||
if len2 as usize != data.len().overflowing_sub(4).0 {
|
||||
warn!(
|
||||
"mismatched sizes on any: {} vs {}",
|
||||
data.len().overflowing_sub(4).0,
|
||||
len2
|
||||
);
|
||||
}
|
||||
|
||||
Ok(Any {
|
||||
name,
|
||||
data: (&data[4..]).to_owned(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,3 +56,43 @@ impl Any {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::rmc::structures::{
|
||||
any::Any,
|
||||
matchmake::{Gathering, MatchmakeSession},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
let sess = MatchmakeSession {
|
||||
gathering: Gathering {
|
||||
self_gid: 0,
|
||||
owner_pid: 0,
|
||||
host_pid: 0,
|
||||
minimum_participants: 2,
|
||||
maximum_participants: 2,
|
||||
participant_policy: 98,
|
||||
policy_argument: 0,
|
||||
flags: 32,
|
||||
state: 0,
|
||||
description: "Doors Friend Invite".into(),
|
||||
},
|
||||
gamemode: 0,
|
||||
attributes: [2, 3, 0, 0, 0, 0].into(),
|
||||
open_participation: false,
|
||||
matchmake_system_type: 2,
|
||||
application_buffer: [1, 2, 3].into(),
|
||||
participation_count: 0,
|
||||
progress_score: 0,
|
||||
session_key: [].into(),
|
||||
};
|
||||
|
||||
let any = Any::new(&sess).unwrap();
|
||||
|
||||
let sess2: MatchmakeSession = any.try_get().unwrap().unwrap();
|
||||
|
||||
assert_eq!(sess, sess2);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use rnex_core::rmc::structures::variant::Variant;
|
|||
use rnex_core::PID;
|
||||
|
||||
// rmc structure
|
||||
#[derive(RmcSerialize, Debug, Clone, Default)]
|
||||
#[derive(RmcSerialize, Debug, Clone, Default, PartialEq)]
|
||||
#[rmc_struct(0)]
|
||||
pub struct Gathering {
|
||||
pub self_gid: u32,
|
||||
|
|
@ -54,7 +54,7 @@ cfg_if! {
|
|||
pub system_password_enabled: bool,
|
||||
}
|
||||
} else {
|
||||
#[derive(RmcSerialize, Debug, Clone, Default)]
|
||||
#[derive(RmcSerialize, Debug, Clone, Default, PartialEq)]
|
||||
#[rmc_struct(0)]
|
||||
pub struct MatchmakeSession {
|
||||
//inherits from
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue