rust-nex/rnex-core/src/rmc/structures/qresult.rs

42 lines
1.1 KiB
Rust
Raw Normal View History

use crate::rmc::response::ErrorCode;
use crate::rmc::structures::{Result, RmcSerialize};
use bytemuck::{Pod, Zeroable, bytes_of};
use std::io::{Read, Write};
2025-09-21 15:59:27 +02:00
use v_byte_helpers::SwapEndian;
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
pub const ERROR_MASK: u32 = 1 << 31;
#[derive(Pod, Zeroable, Copy, Clone, SwapEndian, Debug)]
#[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 {
2025-11-12 22:41:34 +01:00
fn serialize(&self, writer: &mut impl Write) -> Result<()> {
writer.write(bytes_of(self))?;
Ok(())
}
2025-11-13 10:06:58 +01:00
fn deserialize(reader: &mut impl Read) -> Result<Self> {
let result: Self = reader.read_struct(IS_BIG_ENDIAN)?;
println!("reading qresult: {:x}", result.0);
Ok(result)
}
fn serialize_write_size(&self) -> Result<u32> {
Ok(4)
}
}