2025-02-04 22:07:22 +01:00
|
|
|
use std::io::{Read, Write};
|
|
|
|
|
use bytemuck::bytes_of;
|
2025-09-21 15:59:27 +02:00
|
|
|
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
|
2025-02-04 22:07:22 +01:00
|
|
|
use crate::rmc::structures::RmcSerialize;
|
|
|
|
|
|
|
|
|
|
impl RmcSerialize for u8{
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
Ok(writer.write_all(bytes_of(self))?)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-12 10:28:54 +02:00
|
|
|
impl RmcSerialize for i8{
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
Ok(writer.write_all(bytes_of(self))?)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-04 22:07:22 +01:00
|
|
|
impl RmcSerialize for u16{
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
Ok(writer.write_all(bytes_of(self))?)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-12 10:28:54 +02:00
|
|
|
impl RmcSerialize for i16{
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
Ok(writer.write_all(bytes_of(self))?)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-04 22:07:22 +01:00
|
|
|
impl RmcSerialize for u32{
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
Ok(writer.write_all(bytes_of(self))?)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-12 10:28:54 +02:00
|
|
|
impl RmcSerialize for i32{
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
Ok(writer.write_all(bytes_of(self))?)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-04 22:07:22 +01:00
|
|
|
impl RmcSerialize for u64{
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
Ok(writer.write_all(bytes_of(self))?)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RmcSerialize for i64{
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
Ok(writer.write_all(bytes_of(self))?)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RmcSerialize for f64{
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
Ok(writer.write_all(bytes_of(self))?)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RmcSerialize for bool{
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
match self{
|
|
|
|
|
true => writer.write_all(&[1])?,
|
|
|
|
|
false => writer.write_all(&[0])?,
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-07 08:46:09 +01:00
|
|
|
fn deserialize(reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
2025-02-04 22:07:22 +01:00
|
|
|
Ok(u8::deserialize(reader)? != 0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl<T: RmcSerialize, U: RmcSerialize> RmcSerialize for (T, U){
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
self.0.serialize(writer)?;
|
|
|
|
|
self.1.serialize(writer)?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
let first = T::deserialize(reader)?;
|
|
|
|
|
let second = U::deserialize(reader)?;
|
|
|
|
|
|
|
|
|
|
Ok((first, second))
|
|
|
|
|
}
|
2025-03-23 10:54:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: RmcSerialize, U: RmcSerialize, V: RmcSerialize> RmcSerialize for (T, U, V){
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
self.0.serialize(writer)?;
|
|
|
|
|
self.1.serialize(writer)?;
|
|
|
|
|
self.2.serialize(writer)?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
let first = T::deserialize(reader)?;
|
|
|
|
|
let second = U::deserialize(reader)?;
|
|
|
|
|
let third = V::deserialize(reader)?;
|
|
|
|
|
|
|
|
|
|
Ok((first, second, third))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: RmcSerialize, U: RmcSerialize, V: RmcSerialize, W: RmcSerialize> RmcSerialize for (T, U, V, W){
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
self.0.serialize(writer)?;
|
|
|
|
|
self.1.serialize(writer)?;
|
|
|
|
|
self.2.serialize(writer)?;
|
|
|
|
|
self.3.serialize(writer)?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
let first = T::deserialize(reader)?;
|
|
|
|
|
let second = U::deserialize(reader)?;
|
|
|
|
|
let third = V::deserialize(reader)?;
|
|
|
|
|
let fourth = W::deserialize(reader)?;
|
|
|
|
|
|
|
|
|
|
Ok((first, second, third, fourth))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: RmcSerialize, U: RmcSerialize, V: RmcSerialize, W: RmcSerialize, X: RmcSerialize> RmcSerialize for (T, U, V, W, X){
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
self.0.serialize(writer)?;
|
|
|
|
|
self.1.serialize(writer)?;
|
|
|
|
|
self.2.serialize(writer)?;
|
|
|
|
|
self.3.serialize(writer)?;
|
|
|
|
|
self.4.serialize(writer)?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
let first = T::deserialize(reader)?;
|
|
|
|
|
let second = U::deserialize(reader)?;
|
|
|
|
|
let third = V::deserialize(reader)?;
|
|
|
|
|
let fourth = W::deserialize(reader)?;
|
|
|
|
|
let fifth = X::deserialize(reader)?;
|
|
|
|
|
|
|
|
|
|
Ok((first, second, third, fourth, fifth))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: RmcSerialize, U: RmcSerialize, V: RmcSerialize, W: RmcSerialize, X: RmcSerialize, Y: RmcSerialize> RmcSerialize for (T, U, V, W, X, Y){
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
self.0.serialize(writer)?;
|
|
|
|
|
self.1.serialize(writer)?;
|
|
|
|
|
self.2.serialize(writer)?;
|
|
|
|
|
self.3.serialize(writer)?;
|
|
|
|
|
self.4.serialize(writer)?;
|
|
|
|
|
self.5.serialize(writer)?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
let first = T::deserialize(reader)?;
|
|
|
|
|
let second = U::deserialize(reader)?;
|
|
|
|
|
let third = V::deserialize(reader)?;
|
|
|
|
|
let fourth = W::deserialize(reader)?;
|
|
|
|
|
let fifth = X::deserialize(reader)?;
|
|
|
|
|
let sixth = Y::deserialize(reader)?;
|
|
|
|
|
|
|
|
|
|
Ok((first, second, third, fourth, fifth, sixth))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: RmcSerialize, U: RmcSerialize, V: RmcSerialize, W: RmcSerialize, X: RmcSerialize, Y: RmcSerialize, Z: RmcSerialize> RmcSerialize for (T, U, V, W, X, Y, Z){
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
self.0.serialize(writer)?;
|
|
|
|
|
self.1.serialize(writer)?;
|
|
|
|
|
self.2.serialize(writer)?;
|
|
|
|
|
self.3.serialize(writer)?;
|
|
|
|
|
self.4.serialize(writer)?;
|
|
|
|
|
self.5.serialize(writer)?;
|
|
|
|
|
self.6.serialize(writer)?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
let first = T::deserialize(reader)?;
|
|
|
|
|
let second = U::deserialize(reader)?;
|
|
|
|
|
let third = V::deserialize(reader)?;
|
|
|
|
|
let fourth = W::deserialize(reader)?;
|
|
|
|
|
let fifth = X::deserialize(reader)?;
|
|
|
|
|
let sixth = Y::deserialize(reader)?;
|
|
|
|
|
let seventh = Z::deserialize(reader)?;
|
|
|
|
|
|
|
|
|
|
Ok((first, second, third, fourth, fifth, sixth, seventh))
|
|
|
|
|
}
|
2025-06-29 11:40:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: RmcSerialize> RmcSerialize for Box<T>{
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
|
|
|
|
self.as_ref().serialize(writer)
|
|
|
|
|
}
|
|
|
|
|
fn deserialize(reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
|
|
|
|
T::deserialize(reader).map(Box::new)
|
|
|
|
|
}
|
2025-02-04 22:07:22 +01:00
|
|
|
}
|