2026-03-24 23:17:22 +01:00
|
|
|
use crate::rmc::structures::helpers::DummyWriter;
|
2025-02-01 17:31:13 +01:00
|
|
|
use std::io::{Read, Write};
|
2025-01-26 12:09:56 +01:00
|
|
|
use std::string::FromUtf8Error;
|
2026-03-24 23:17:22 +01:00
|
|
|
use std::{fmt, io};
|
2025-01-26 12:09:56 +01:00
|
|
|
use thiserror::Error;
|
|
|
|
|
//ideas for the future: make a proc macro library which allows generation of struct reads
|
|
|
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
2026-03-24 23:17:22 +01:00
|
|
|
pub enum Error {
|
2025-01-26 12:09:56 +01:00
|
|
|
#[error("Io Error: {0}")]
|
|
|
|
|
Io(#[from] io::Error),
|
|
|
|
|
#[error("UTF8 conversion Error: {0}")]
|
2025-02-04 22:07:22 +01:00
|
|
|
Utf8(#[from] FromUtf8Error),
|
|
|
|
|
#[error("unexpected value: {0}")]
|
|
|
|
|
UnexpectedValue(u64),
|
|
|
|
|
#[error("version mismatch: {0}")]
|
|
|
|
|
VersionMismatch(u8),
|
2025-05-12 10:28:54 +02:00
|
|
|
#[error("an error occurred reading the station url")]
|
2025-11-12 22:41:34 +01:00
|
|
|
StationUrlInvalid,
|
|
|
|
|
#[error("error formatting text: {0}")]
|
2026-03-24 23:17:22 +01:00
|
|
|
FormatError(#[from] fmt::Error),
|
2025-01-26 12:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
2025-03-23 10:54:01 +01:00
|
|
|
pub type Result<T> = std::result::Result<T, Error>;
|
2025-01-26 12:09:56 +01:00
|
|
|
|
2025-01-26 23:21:35 +01:00
|
|
|
pub mod any;
|
2025-02-02 20:25:22 +01:00
|
|
|
pub mod buffer;
|
|
|
|
|
pub mod connection_data;
|
2026-03-24 23:17:22 +01:00
|
|
|
pub mod helpers;
|
2025-02-02 20:25:22 +01:00
|
|
|
pub mod list;
|
2025-02-04 22:07:22 +01:00
|
|
|
pub mod matchmake;
|
2025-11-12 22:41:34 +01:00
|
|
|
pub mod networking;
|
2026-03-24 23:17:22 +01:00
|
|
|
pub mod primitives;
|
|
|
|
|
pub mod qbuffer;
|
|
|
|
|
pub mod qresult;
|
|
|
|
|
pub mod ranking;
|
|
|
|
|
pub mod rmc_struct;
|
|
|
|
|
pub mod string;
|
|
|
|
|
pub mod variant;
|
2025-01-26 23:21:35 +01:00
|
|
|
|
2026-03-24 23:17:22 +01:00
|
|
|
pub trait RmcSerialize {
|
2025-11-12 22:41:34 +01:00
|
|
|
fn serialize(&self, writer: &mut impl Write) -> Result<()>;
|
2026-03-24 23:17:22 +01:00
|
|
|
fn serialize_write_size(&self) -> Result<u32> {
|
2025-11-12 22:41:34 +01:00
|
|
|
let mut dummy = DummyWriter::new();
|
|
|
|
|
|
|
|
|
|
self.serialize(&mut dummy)?;
|
|
|
|
|
|
|
|
|
|
Ok(dummy.get_total_len())
|
|
|
|
|
}
|
2026-03-24 23:17:22 +01:00
|
|
|
fn deserialize(reader: &mut impl Read) -> Result<Self>
|
|
|
|
|
where
|
|
|
|
|
Self: Sized;
|
2025-11-12 22:41:34 +01:00
|
|
|
|
2026-03-24 23:17:22 +01:00
|
|
|
fn to_data(&self) -> Result<Vec<u8>> {
|
|
|
|
|
let expected_size = self.serialize_write_size()?;
|
|
|
|
|
let mut data = Vec::with_capacity(expected_size as usize);
|
2025-06-13 10:05:38 +02:00
|
|
|
|
2025-11-12 22:41:34 +01:00
|
|
|
self.serialize(&mut data)?;
|
2025-06-13 10:05:38 +02:00
|
|
|
|
2026-03-24 23:17:22 +01:00
|
|
|
debug_assert_eq!(expected_size, data.len() as u32);
|
2025-06-13 10:05:38 +02:00
|
|
|
|
2025-11-12 22:41:34 +01:00
|
|
|
Ok(data)
|
2025-06-13 10:05:38 +02:00
|
|
|
}
|
2026-04-25 14:15:42 +02:00
|
|
|
fn name() -> &'static str {
|
|
|
|
|
"NoNameSpecified"
|
|
|
|
|
}
|
2025-03-23 10:54:01 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 23:17:22 +01:00
|
|
|
impl RmcSerialize for () {
|
2025-11-12 22:41:34 +01:00
|
|
|
fn serialize(&self, _writer: &mut impl Write) -> Result<()> {
|
2025-03-23 10:54:01 +01:00
|
|
|
Ok(())
|
|
|
|
|
}
|
2025-11-12 22:41:34 +01:00
|
|
|
fn deserialize(_reader: &mut impl Read) -> Result<Self> {
|
2025-03-23 10:54:01 +01:00
|
|
|
Ok(())
|
|
|
|
|
}
|
2025-11-12 22:41:34 +01:00
|
|
|
fn serialize_write_size(&self) -> Result<u32> {
|
|
|
|
|
Ok(0)
|
|
|
|
|
}
|
2026-03-24 23:17:22 +01:00
|
|
|
}
|