Implement yunq server in rust.

This commit is contained in:
Drew Galbraith 2024-07-31 19:59:46 -07:00
parent dbc4e7e2ad
commit 76f8795a46
12 changed files with 312 additions and 23 deletions

View file

@ -4,13 +4,23 @@ use mammoth::zion::z_cap_t;
use mammoth::zion::ZError;
pub const MESSAGE_IDENT: u32 = 0x33441122;
const SENTINEL: u32 = 0xBEEFDEAD;
pub const MESSAGE_HEADER_SIZE: usize = 24; // 4x uint32, 1x uint64
const SENTINEL: u32 = 0xBEEFDEAD;
const SERIALIZE_HEADER_SIZE: u32 = 0x10;
pub fn field_offset(offset: usize, field_index: usize) -> usize {
offset + MESSAGE_HEADER_SIZE + (8 * field_index)
}
pub fn serialize_error<const N: usize>(buf: &mut ByteBuffer<N>, err: ZError) {
buf.write_at(0, SENTINEL)
.expect("Failed to serialize SENTINEL");
buf.write_at(4, SERIALIZE_HEADER_SIZE)
.expect("Failed to serialize size");
buf.write_at(8, err as u64)
.expect("Failed to serialize error");
}
pub trait YunqMessage {
fn parse<const N: usize>(
buf: &ByteBuffer<N>,
@ -31,11 +41,6 @@ pub trait YunqMessage {
return Err(ZError::INVALID_RESPONSE);
}
let resp_code: u64 = buf.at(8)?;
if resp_code != 0 {
return Err(ZError::from(resp_code));
}
Ok(Self::parse(&buf, 16, &caps)?)
}