forked from spacebar/rust-nex
make Read and Write on RmcSerialize ?Sized and start work on rework of
Any
This commit is contained in:
parent
c687b09ab0
commit
ec8b75603f
20 changed files with 162 additions and 98 deletions
|
|
@ -35,6 +35,7 @@ base64 = "0.22.1"
|
|||
sha2 = "0.10.9"
|
||||
urlencoding = "2.1.3"
|
||||
futures = "0.3.32"
|
||||
async-trait = "0.1.89"
|
||||
|
||||
[dev-dependencies]
|
||||
# criterion = "0.7.0"
|
||||
|
|
|
|||
|
|
@ -128,11 +128,11 @@ impl Default for KerberosDateTime {
|
|||
}
|
||||
|
||||
impl RmcSerialize for KerberosDateTime {
|
||||
fn serialize(&self, writer: &mut impl Write) -> Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> {
|
||||
Ok(self.0.serialize(writer)?)
|
||||
}
|
||||
|
||||
fn deserialize(reader: &mut impl Read) -> Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> Result<Self> {
|
||||
Ok(Self(u64::deserialize(reader)?))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -928,5 +928,7 @@ impl Ranking for User {
|
|||
}
|
||||
|
||||
impl MessageDelivery for User {
|
||||
async fn deliver_message(&self, message: Any) {}
|
||||
async fn deliver_message(&self, message: Any) -> Result<(), ErrorCode> {
|
||||
Err(ErrorCode::Core_NotImplemented)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,12 +145,15 @@ impl<'a> Into<String> for &'a StationUrl {
|
|||
}
|
||||
|
||||
impl RmcSerialize for StationUrl {
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
let str = String::deserialize(reader)?;
|
||||
|
||||
Self::try_from(str.as_str()).map_err(|_| StationUrlInvalid)
|
||||
}
|
||||
fn serialize(&self, writer: &mut impl std::io::Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(
|
||||
&self,
|
||||
writer: &mut (impl std::io::Write + ?Sized),
|
||||
) -> crate::rmc::structures::Result<()> {
|
||||
let str: String = self.into();
|
||||
|
||||
str.serialize(writer)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
use macros::{method_id, rmc_proto};
|
||||
|
||||
use crate::rmc::{response::ErrorCode, structures::any::Any};
|
||||
use crate::rmc::{
|
||||
response::ErrorCode,
|
||||
structures::{Error, any::Any},
|
||||
};
|
||||
|
||||
#[rmc_proto(27, NoReturn)]
|
||||
#[rmc_proto(27)]
|
||||
pub trait MessageDelivery {
|
||||
#[method_id(1)]
|
||||
async fn deliver_message(&self, message: Any);
|
||||
async fn deliver_message(&self, message: Any) -> Result<(), ErrorCode>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ pub struct Any {
|
|||
}
|
||||
|
||||
impl RmcSerialize for Any {
|
||||
fn serialize(&self, writer: &mut impl Write) -> Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> {
|
||||
self.name.serialize(writer)?;
|
||||
|
||||
let u32_len = self.data.len() as u32;
|
||||
|
|
@ -18,7 +18,7 @@ impl RmcSerialize for Any {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
fn deserialize(reader: &mut impl Read) -> Result<Self> {
|
||||
fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> Result<Self> {
|
||||
let name = String::deserialize(reader)?;
|
||||
|
||||
// also length ?
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::rmc::structures::RmcSerialize;
|
|||
use std::io::{Read, Write};
|
||||
|
||||
impl<'a> RmcSerialize for &'a [u8] {
|
||||
fn serialize(&self, writer: &mut impl Write) -> Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> {
|
||||
let u32_size = self.len() as u32;
|
||||
writer.write(bytemuck::bytes_of(&u32_size))?;
|
||||
writer.write(self)?;
|
||||
|
|
@ -12,7 +12,7 @@ impl<'a> RmcSerialize for &'a [u8] {
|
|||
}
|
||||
|
||||
/// DO NOT USE (also maybe split off the serialize and deserialize functions at some point)
|
||||
fn deserialize(_reader: &mut impl Read) -> Result<Self> {
|
||||
fn deserialize(_reader: &mut (impl Read + ?Sized)) -> Result<Self> {
|
||||
panic!("cannot deserialize to a u8 slice reference (use this ONLY for writing)")
|
||||
}
|
||||
|
||||
|
|
@ -22,11 +22,11 @@ impl<'a> RmcSerialize for &'a [u8] {
|
|||
}
|
||||
|
||||
impl RmcSerialize for Box<[u8]> {
|
||||
fn serialize(&self, writer: &mut impl Write) -> Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> {
|
||||
(&self[..]).serialize(writer)
|
||||
}
|
||||
|
||||
fn deserialize(reader: &mut impl Read) -> Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> Result<Self> {
|
||||
Vec::deserialize(reader).map(|v| v.into_boxed_slice())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
|
|||
// this is also for implementing `Buffer` this is tecnically not the same as its handled internaly
|
||||
// probably but as it has the same mapping it doesn't matter and simplifies things
|
||||
impl<T: RmcSerialize> RmcSerialize for Vec<T> {
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
let u32_len = self.len() as u32;
|
||||
|
||||
writer.write_all(bytes_of(&u32_len))?;
|
||||
|
|
@ -18,7 +18,7 @@ impl<T: RmcSerialize> RmcSerialize for Vec<T> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
println!("reading list");
|
||||
let len: u32 = reader.read_struct(IS_BIG_ENDIAN)?;
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ impl<T: RmcSerialize> RmcSerialize for Vec<T> {
|
|||
}
|
||||
|
||||
impl<const LEN: usize, T: RmcSerialize> RmcSerialize for [T; LEN] {
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
for i in 0..LEN {
|
||||
self[i].serialize(writer)?;
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ impl<const LEN: usize, T: RmcSerialize> RmcSerialize for [T; LEN] {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
let mut arr = [const { MaybeUninit::<T>::uninit() }; LEN];
|
||||
|
||||
for i in 0..LEN {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use crate::rmc::structures::helpers::DummyWriter;
|
||||
use async_trait::async_trait;
|
||||
use std::io::{Read, Write};
|
||||
use std::string::FromUtf8Error;
|
||||
use std::{fmt, io};
|
||||
|
|
@ -45,7 +46,7 @@ pub mod string_set;
|
|||
pub mod variant;
|
||||
|
||||
pub trait RmcSerialize {
|
||||
fn serialize(&self, writer: &mut impl Write) -> Result<()>;
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()>;
|
||||
fn serialize_write_size(&self) -> Result<u32> {
|
||||
let mut dummy = DummyWriter::new();
|
||||
|
||||
|
|
@ -53,7 +54,7 @@ pub trait RmcSerialize {
|
|||
|
||||
Ok(dummy.get_total_len())
|
||||
}
|
||||
fn deserialize(reader: &mut impl Read) -> Result<Self>
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> Result<Self>
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
|
|
@ -75,14 +76,61 @@ pub trait RmcSerialize {
|
|||
}
|
||||
}
|
||||
|
||||
trait SendWrite: Send + Write {}
|
||||
impl<T: Send + Write> SendWrite for T {}
|
||||
|
||||
// beware that this trait throws away most of the optimizations which come with using
|
||||
// the regular `Serialize` trait, ONLY use this when it is 100% required to have dyn
|
||||
// compatibility
|
||||
#[async_trait]
|
||||
trait DynRmcSerialize: Send + Sync {
|
||||
async fn serialize(&self, writer: &mut dyn SendWrite) -> Result<()>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<T: RmcSerialize + Send + Sync> DynRmcSerialize for T {
|
||||
async fn serialize(&self, writer: &mut dyn SendWrite) -> Result<()> {
|
||||
<Self as RmcSerialize>::serialize(&self, writer)
|
||||
}
|
||||
}
|
||||
|
||||
impl RmcSerialize for () {
|
||||
fn serialize(&self, _writer: &mut impl Write) -> Result<()> {
|
||||
fn serialize(&self, _writer: &mut (impl Write + ?Sized)) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn deserialize(_reader: &mut impl Read) -> Result<Self> {
|
||||
fn deserialize(_reader: &mut (impl Read + ?Sized)) -> Result<Self> {
|
||||
Ok(())
|
||||
}
|
||||
fn serialize_write_size(&self) -> Result<u32> {
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
|
||||
trait RmcInternalAnyUnknownAs<T: RmcStruct>: AsRef<T> + DynRmcSerialize + RmcStructInstance {}
|
||||
|
||||
trait RmcCastable {
|
||||
// consumes box and returns a Box containing a Box with the requested Struct details
|
||||
fn cast_to(self: Box<Self>, destination: &RmcStructInfo) -> Box<dyn std::any::Any>;
|
||||
}
|
||||
|
||||
struct RmcStructInfo {
|
||||
inheritors: Vec<&'static RmcStructInfo>,
|
||||
name: &'static str,
|
||||
deserialize_abstract: fn(&mut dyn Read) -> Box<dyn std::any::Any>,
|
||||
}
|
||||
|
||||
impl RmcStructInfo {
|
||||
fn deserialze_abstract_as<T: RmcStruct>(
|
||||
reader: &impl Read,
|
||||
) -> Box<dyn RmcInternalAnyUnknownAs<T>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
trait RmcStruct {
|
||||
fn get_struct_info() -> &'static RmcStructInfo;
|
||||
}
|
||||
|
||||
trait RmcStructInstance {
|
||||
fn get_self_struct_info(&self) -> &'static RmcStructInfo;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
|||
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
|
||||
|
||||
impl RmcSerialize for SocketAddr {
|
||||
fn deserialize(reader: &mut impl std::io::Read) -> Result<Self>
|
||||
fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> Result<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
|
|
@ -16,7 +16,7 @@ impl RmcSerialize for SocketAddr {
|
|||
v => Err(Error::UnexpectedValue(v as u64)),
|
||||
}
|
||||
}
|
||||
fn serialize(&self, writer: &mut impl Write) -> Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> {
|
||||
match self {
|
||||
SocketAddr::V4(v) => {
|
||||
writer.write_all(&[4])?;
|
||||
|
|
@ -32,14 +32,14 @@ impl RmcSerialize for SocketAddr {
|
|||
}
|
||||
|
||||
impl RmcSerialize for SocketAddrV4 {
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
self.ip().to_bits().serialize(writer)?;
|
||||
self.port().serialize(writer)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
let ip = u32::deserialize(reader)?;
|
||||
let port = u16::deserialize(reader)?;
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ impl RmcSerialize for SocketAddrV4 {
|
|||
}
|
||||
}
|
||||
impl RmcSerialize for SocketAddrV6 {
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
self.ip().to_bits().serialize(writer)?;
|
||||
self.port().serialize(writer)?;
|
||||
self.flowinfo().serialize(writer)?;
|
||||
|
|
@ -59,7 +59,7 @@ impl RmcSerialize for SocketAddrV6 {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
let ip = u128::deserialize(reader)?;
|
||||
let port = u16::deserialize(reader)?;
|
||||
let flowinfo = u32::deserialize(reader)?;
|
||||
|
|
@ -78,13 +78,13 @@ impl RmcSerialize for SocketAddrV6 {
|
|||
}
|
||||
|
||||
impl RmcSerialize for VirtualPort {
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
self.0.serialize(writer)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(Self(u8::deserialize(reader)?))
|
||||
}
|
||||
fn serialize_write_size(&self) -> crate::rmc::structures::Result<u32> {
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
|
|||
|
||||
impl RmcSerialize for u8 {
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
||||
}
|
||||
#[inline(always)]
|
||||
|
|
@ -21,12 +21,12 @@ impl RmcSerialize for u8 {
|
|||
|
||||
impl RmcSerialize for i8 {
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
||||
}
|
||||
#[inline(always)]
|
||||
|
|
@ -37,11 +37,11 @@ impl RmcSerialize for i8 {
|
|||
|
||||
impl RmcSerialize for u16 {
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
||||
}
|
||||
#[inline(always)]
|
||||
|
|
@ -52,11 +52,11 @@ impl RmcSerialize for u16 {
|
|||
|
||||
impl RmcSerialize for i16 {
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
||||
}
|
||||
#[inline(always)]
|
||||
|
|
@ -67,11 +67,11 @@ impl RmcSerialize for i16 {
|
|||
|
||||
impl RmcSerialize for u32 {
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
||||
}
|
||||
#[inline(always)]
|
||||
|
|
@ -82,11 +82,11 @@ impl RmcSerialize for u32 {
|
|||
|
||||
impl RmcSerialize for i32 {
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
||||
}
|
||||
#[inline(always)]
|
||||
|
|
@ -97,11 +97,11 @@ impl RmcSerialize for i32 {
|
|||
|
||||
impl RmcSerialize for u64 {
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
||||
}
|
||||
#[inline(always)]
|
||||
|
|
@ -112,11 +112,11 @@ impl RmcSerialize for u64 {
|
|||
|
||||
impl RmcSerialize for u128 {
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
let mut data = 0u128;
|
||||
reader.read_exact(&mut bytes_of_mut(&mut data))?;
|
||||
Ok(data)
|
||||
|
|
@ -129,11 +129,11 @@ impl RmcSerialize for u128 {
|
|||
|
||||
impl RmcSerialize for i64 {
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
||||
}
|
||||
#[inline(always)]
|
||||
|
|
@ -144,12 +144,12 @@ impl RmcSerialize for i64 {
|
|||
|
||||
impl RmcSerialize for f64 {
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
||||
}
|
||||
#[inline(always)]
|
||||
|
|
@ -160,7 +160,7 @@ impl RmcSerialize for f64 {
|
|||
|
||||
impl RmcSerialize for bool {
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
match self {
|
||||
true => writer.write_all(&[1])?,
|
||||
false => writer.write_all(&[0])?,
|
||||
|
|
@ -169,7 +169,7 @@ impl RmcSerialize for bool {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(u8::deserialize(reader)? != 0)
|
||||
}
|
||||
#[inline(always)]
|
||||
|
|
@ -180,13 +180,13 @@ impl RmcSerialize for bool {
|
|||
|
||||
impl<T: RmcSerialize, U: RmcSerialize> RmcSerialize for (T, U) {
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
self.0.serialize(writer)?;
|
||||
self.1.serialize(writer)?;
|
||||
Ok(())
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
let first = T::deserialize(reader)?;
|
||||
let second = U::deserialize(reader)?;
|
||||
|
||||
|
|
@ -200,14 +200,14 @@ impl<T: RmcSerialize, U: RmcSerialize> RmcSerialize for (T, U) {
|
|||
|
||||
impl<T: RmcSerialize, U: RmcSerialize, V: RmcSerialize> RmcSerialize for (T, U, V) {
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
self.0.serialize(writer)?;
|
||||
self.1.serialize(writer)?;
|
||||
self.2.serialize(writer)?;
|
||||
Ok(())
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
let first = T::deserialize(reader)?;
|
||||
let second = U::deserialize(reader)?;
|
||||
let third = V::deserialize(reader)?;
|
||||
|
|
@ -226,7 +226,7 @@ impl<T: RmcSerialize, U: RmcSerialize, V: RmcSerialize, W: RmcSerialize> RmcSeri
|
|||
for (T, U, V, W)
|
||||
{
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
self.0.serialize(writer)?;
|
||||
self.1.serialize(writer)?;
|
||||
self.2.serialize(writer)?;
|
||||
|
|
@ -234,7 +234,7 @@ impl<T: RmcSerialize, U: RmcSerialize, V: RmcSerialize, W: RmcSerialize> RmcSeri
|
|||
Ok(())
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
let first = T::deserialize(reader)?;
|
||||
let second = U::deserialize(reader)?;
|
||||
let third = V::deserialize(reader)?;
|
||||
|
|
@ -255,7 +255,7 @@ impl<T: RmcSerialize, U: RmcSerialize, V: RmcSerialize, W: RmcSerialize, X: RmcS
|
|||
RmcSerialize for (T, U, V, W, X)
|
||||
{
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
self.0.serialize(writer)?;
|
||||
self.1.serialize(writer)?;
|
||||
self.2.serialize(writer)?;
|
||||
|
|
@ -266,7 +266,7 @@ impl<T: RmcSerialize, U: RmcSerialize, V: RmcSerialize, W: RmcSerialize, X: RmcS
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
let first = T::deserialize(reader)?;
|
||||
let second = U::deserialize(reader)?;
|
||||
let third = V::deserialize(reader)?;
|
||||
|
|
@ -295,7 +295,7 @@ impl<
|
|||
> RmcSerialize for (T, U, V, W, X, Y)
|
||||
{
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
self.0.serialize(writer)?;
|
||||
self.1.serialize(writer)?;
|
||||
self.2.serialize(writer)?;
|
||||
|
|
@ -307,7 +307,7 @@ impl<
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
let first = T::deserialize(reader)?;
|
||||
let second = U::deserialize(reader)?;
|
||||
let third = V::deserialize(reader)?;
|
||||
|
|
@ -339,7 +339,7 @@ impl<
|
|||
> RmcSerialize for (T, U, V, W, X, Y, Z)
|
||||
{
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
self.0.serialize(writer)?;
|
||||
self.1.serialize(writer)?;
|
||||
self.2.serialize(writer)?;
|
||||
|
|
@ -351,7 +351,7 @@ impl<
|
|||
Ok(())
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
let first = T::deserialize(reader)?;
|
||||
let second = U::deserialize(reader)?;
|
||||
let third = V::deserialize(reader)?;
|
||||
|
|
@ -386,7 +386,7 @@ impl<
|
|||
> RmcSerialize for (T, U, V, W, X, Y, Z, A)
|
||||
{
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
self.0.serialize(writer)?;
|
||||
self.1.serialize(writer)?;
|
||||
self.2.serialize(writer)?;
|
||||
|
|
@ -399,7 +399,7 @@ impl<
|
|||
Ok(())
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
let first = T::deserialize(reader)?;
|
||||
let second = U::deserialize(reader)?;
|
||||
let third = V::deserialize(reader)?;
|
||||
|
|
@ -437,7 +437,7 @@ impl<
|
|||
> RmcSerialize for (T, U, V, W, X, Y, Z, A, B)
|
||||
{
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
self.0.serialize(writer)?;
|
||||
self.1.serialize(writer)?;
|
||||
self.2.serialize(writer)?;
|
||||
|
|
@ -451,7 +451,7 @@ impl<
|
|||
Ok(())
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
let first = T::deserialize(reader)?;
|
||||
let second = U::deserialize(reader)?;
|
||||
let third = V::deserialize(reader)?;
|
||||
|
|
@ -482,11 +482,11 @@ impl<
|
|||
|
||||
impl<T: RmcSerialize> RmcSerialize for Box<T> {
|
||||
#[inline(always)]
|
||||
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> {
|
||||
self.as_ref().serialize(writer)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result<Self> {
|
||||
T::deserialize(reader).map(Box::new)
|
||||
}
|
||||
#[inline(always)]
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
use std::io::{Read, Write};
|
||||
use bytemuck::bytes_of;
|
||||
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
|
||||
use crate::rmc::structures::{Result, RmcSerialize};
|
||||
use bytemuck::bytes_of;
|
||||
use std::io::{Read, Write};
|
||||
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct QBuffer(pub Vec<u8>);
|
||||
|
||||
impl RmcSerialize for QBuffer{
|
||||
fn serialize(&self, writer: &mut impl Write) -> Result<()> {
|
||||
impl RmcSerialize for QBuffer {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> {
|
||||
let len_u16 = self.0.len() as u16;
|
||||
|
||||
writer.write(bytes_of(&len_u16))?;
|
||||
|
|
@ -16,7 +16,7 @@ impl RmcSerialize for QBuffer{
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn deserialize(reader: &mut impl Read) -> Result<Self> {
|
||||
fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> Result<Self> {
|
||||
let size: u16 = reader.read_struct(IS_BIG_ENDIAN)?;
|
||||
|
||||
let mut vec = vec![0; size as usize];
|
||||
|
|
@ -25,4 +25,4 @@ impl RmcSerialize for QBuffer{
|
|||
|
||||
Ok(Self(vec))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,12 +26,12 @@ impl QResult {
|
|||
}
|
||||
|
||||
impl RmcSerialize for QResult {
|
||||
fn serialize(&self, writer: &mut impl Write) -> Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> {
|
||||
writer.write(bytes_of(self))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn deserialize(reader: &mut impl Read) -> Result<Self> {
|
||||
fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> Result<Self> {
|
||||
let result: Self = reader.read_struct(IS_BIG_ENDIAN)?;
|
||||
println!("reading qresult: {:x}", result.0);
|
||||
Ok(result)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ impl Write for OnlyWriteVec<'_> {
|
|||
}
|
||||
|
||||
#[cfg(feature = "rmc_struct_header")]
|
||||
pub fn write_struct<T: Write>(
|
||||
pub fn write_struct<T: Write + ?Sized>(
|
||||
writer: &mut T,
|
||||
version: u8,
|
||||
inner_size: u32,
|
||||
|
|
@ -54,7 +54,7 @@ pub fn write_struct<T: Write>(
|
|||
}
|
||||
|
||||
#[cfg(not(feature = "rmc_struct_header"))]
|
||||
pub fn write_struct<T: Write>(
|
||||
pub fn write_struct<T: Write + ?Sized>(
|
||||
writer: &mut T,
|
||||
_version: u8,
|
||||
_inner_size: u32,
|
||||
|
|
@ -63,12 +63,12 @@ pub fn write_struct<T: Write>(
|
|||
pred(writer)
|
||||
}
|
||||
|
||||
pub struct SubRead<'a, T: Read> {
|
||||
pub struct SubRead<'a, T: Read + ?Sized> {
|
||||
left_to_read: usize,
|
||||
origin: &'a mut T,
|
||||
}
|
||||
|
||||
impl<'a, T: Read> SubRead<'a, T> {
|
||||
impl<'a, T: Read + ?Sized> SubRead<'a, T> {
|
||||
pub const fn new(origin: &'a mut T, left_to_read: usize) -> Self {
|
||||
Self {
|
||||
left_to_read,
|
||||
|
|
@ -77,7 +77,7 @@ impl<'a, T: Read> SubRead<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Read> Read for SubRead<'_, T> {
|
||||
impl<T: Read + ?Sized> Read for SubRead<'_, T> {
|
||||
#[inline(always)]
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
let max_read = max(self.left_to_read, buf.len());
|
||||
|
|
@ -100,8 +100,8 @@ impl<T: Read> Read for SubRead<'_, T> {
|
|||
}
|
||||
|
||||
#[cfg(feature = "rmc_struct_header")]
|
||||
pub fn read_struct<T: Sized, R: Read>(
|
||||
reader: &mut R,
|
||||
pub fn read_struct<T: Sized, R: Read + ?Sized>(
|
||||
mut reader: &mut R,
|
||||
version: u8,
|
||||
pred: impl FnOnce(&mut SubRead<R>) -> Result<T>,
|
||||
) -> Result<T> {
|
||||
|
|
@ -120,7 +120,7 @@ pub fn read_struct<T: Sized, R: Read>(
|
|||
}
|
||||
|
||||
#[cfg(not(feature = "rmc_struct_header"))]
|
||||
pub fn read_struct<T: Sized, R: Read>(
|
||||
pub fn read_struct<T: Sized, R: Read + ?Sized>(
|
||||
mut reader: &mut R,
|
||||
_version: u8,
|
||||
pred: impl FnOnce(&mut R) -> Result<T>,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use std::io::{Read, Write};
|
|||
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
|
||||
|
||||
impl RmcSerialize for String {
|
||||
fn deserialize(reader: &mut impl Read) -> Result<Self> {
|
||||
fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> Result<Self> {
|
||||
let len: u16 = reader.read_struct(IS_BIG_ENDIAN)?;
|
||||
if len == 0 {
|
||||
return Ok("".to_string());
|
||||
|
|
@ -19,7 +19,7 @@ impl RmcSerialize for String {
|
|||
|
||||
Ok(String::from_utf8(data)?)
|
||||
}
|
||||
fn serialize(&self, writer: &mut impl Write) -> Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> {
|
||||
(&self[..]).serialize(writer)
|
||||
}
|
||||
fn serialize_write_size(&self) -> Result<u32> {
|
||||
|
|
@ -28,10 +28,10 @@ impl RmcSerialize for String {
|
|||
}
|
||||
|
||||
impl RmcSerialize for &str {
|
||||
fn deserialize(_reader: &mut impl Read) -> Result<Self> {
|
||||
fn deserialize(_reader: &mut (impl Read + ?Sized)) -> Result<Self> {
|
||||
panic!("cannot serialize to &str")
|
||||
}
|
||||
fn serialize(&self, writer: &mut impl Write) -> Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> {
|
||||
let u16_len: u16 = (self.len() + 1) as u16;
|
||||
writer.write_all(bytes_of(&u16_len))?;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
use std::{collections::HashSet, hash::Hash, str::FromStr, string::ToString};
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
hash::Hash,
|
||||
io::{Read, Write},
|
||||
str::FromStr,
|
||||
string::ToString,
|
||||
};
|
||||
|
||||
use rnex_core::rmc::structures::RmcSerialize;
|
||||
|
||||
|
|
@ -55,13 +61,13 @@ impl<T: FromStr + ToString + Eq + Hash> RmcSerialize for StringSet<T>
|
|||
where
|
||||
<T as FromStr>::Err: std::error::Error + Send + Sync + 'static,
|
||||
{
|
||||
fn deserialize(reader: &mut impl std::io::prelude::Read) -> super::Result<Self>
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> super::Result<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
Self::from_str(&String::deserialize(reader)?).map_err(super::Error::Other)
|
||||
}
|
||||
fn serialize(&self, writer: &mut impl std::io::prelude::Write) -> super::Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> super::Result<()> {
|
||||
self.to_string().serialize(writer)
|
||||
}
|
||||
fn serialize_write_size(&self) -> super::Result<u32> {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ pub enum Variant {
|
|||
}
|
||||
|
||||
impl RmcSerialize for Variant {
|
||||
fn serialize(&self, writer: &mut impl Write) -> Result<()> {
|
||||
fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> {
|
||||
match self {
|
||||
Variant::None => {
|
||||
writer.write_all(&[0])?;
|
||||
|
|
@ -50,7 +50,7 @@ impl RmcSerialize for Variant {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn deserialize(reader: &mut impl Read) -> Result<Self> {
|
||||
fn deserialize(reader: &mut (impl Read + ?Sized)) -> Result<Self> {
|
||||
match u8::deserialize(reader)? {
|
||||
0 => Ok(Variant::None),
|
||||
1 => Ok(Variant::SInt64(i64::deserialize(reader)?)),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{PID, prudp::socket_addr::PRUDPSockAddr};
|
||||
use macros::RmcSerialize;
|
||||
|
||||
#[derive(Debug, RmcSerialize, PartialEq, Eq)]
|
||||
#[derive(Debug, PartialEq, Eq, RmcSerialize)]
|
||||
#[rmc_struct(0)]
|
||||
pub struct ConnectionInitData {
|
||||
pub prudpsock_addr: PRUDPSockAddr,
|
||||
|
|
|
|||
Loading…
Reference in a new issue