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

37 lines
940 B
Rust
Raw Normal View History

use std::io::{Read, Write};
use bytemuck::{bytes_of, Pod, Zeroable};
2025-09-21 15:59:27 +02:00
use v_byte_helpers::SwapEndian;
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
use crate::rmc::response::ErrorCode;
use crate::rmc::structures::{RmcSerialize, Result};
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> {
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
}
}