2025-02-02 20:25:22 +01:00
|
|
|
use std::io::{Read, Write};
|
|
|
|
|
use bytemuck::{bytes_of, Pod, Zeroable};
|
|
|
|
|
use v_byte_macros::SwapEndian;
|
|
|
|
|
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
|
|
|
|
|
use crate::rmc::response::ErrorCode;
|
|
|
|
|
use crate::rmc::structures::{RmcSerialize, Result};
|
|
|
|
|
|
2025-02-03 20:37:31 +01:00
|
|
|
pub const ERROR_MASK: u32 = 1 << 31;
|
2025-02-02 20:25:22 +01:00
|
|
|
|
2025-03-24 23:31:25 +01:00
|
|
|
#[derive(Pod, Zeroable, Copy, Clone, SwapEndian, Debug)]
|
2025-02-02 20:25:22 +01:00
|
|
|
#[repr(transparent)]
|
|
|
|
|
pub struct QResult(u32);
|
|
|
|
|
|
|
|
|
|
impl QResult{
|
|
|
|
|
pub fn success(error_code: ErrorCode) -> Self{
|
|
|
|
|
let val: u32 = error_code.into();
|
|
|
|
|
|
|
|
|
|
Self(val & (!ERROR_MASK))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn error(error_code: ErrorCode) -> Self{
|
|
|
|
|
let val: u32 = error_code.into();
|
|
|
|
|
|
|
|
|
|
Self(val | ERROR_MASK)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RmcSerialize for QResult{
|
|
|
|
|
fn serialize(&self, writer: &mut dyn Write) -> Result<()> {
|
|
|
|
|
writer.write(bytes_of(self))?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize(mut reader: &mut dyn Read) -> Result<Self> {
|
|
|
|
|
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
|
|
|
|
}
|
|
|
|
|
}
|