implement friendships
This commit is contained in:
parent
58c9e43fa3
commit
20fc294a36
7 changed files with 196 additions and 21 deletions
|
|
@ -1,8 +1,8 @@
|
|||
use rnex_core::rmc::structures::{Result, RmcSerialize};
|
||||
use std::io::{Read, Write};
|
||||
use std::io::{Cursor, Read, Write};
|
||||
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct Any {
|
||||
pub name: String,
|
||||
pub data: Vec<u8>,
|
||||
|
|
@ -14,7 +14,7 @@ impl RmcSerialize for Any {
|
|||
|
||||
let u32_len = self.data.len() as u32;
|
||||
|
||||
u32_len.serialize(writer)?;
|
||||
(u32_len + 4).serialize(writer)?;
|
||||
u32_len.serialize(writer)?;
|
||||
|
||||
self.data.serialize(writer)?;
|
||||
|
|
@ -35,3 +35,18 @@ impl RmcSerialize for Any {
|
|||
Ok(Any { name, data })
|
||||
}
|
||||
}
|
||||
|
||||
impl Any {
|
||||
pub fn try_get<T: RmcSerialize>(&self) -> Option<Result<T>> {
|
||||
if self.name != T::name() {
|
||||
return None;
|
||||
}
|
||||
return Some(T::deserialize(&mut Cursor::new(&self.data[..])));
|
||||
}
|
||||
pub fn new<T: RmcSerialize>(val: &T) -> Result<Self> {
|
||||
return Ok(Self {
|
||||
name: T::name().to_owned(),
|
||||
data: val.to_data()?,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue