forked from M-Labs/nac3
1
0
Fork 0

rpc: added `#[repr(C)]` for structs.

This commit is contained in:
pca006132 2020-07-16 15:48:17 +08:00
parent 4457af7277
commit 84630d66e3
1 changed files with 3 additions and 0 deletions

View File

@ -73,6 +73,7 @@ async unsafe fn recv_value<F>(stream: &TcpStream, tag: Tag<'async_recursion>, da
Ok(()) Ok(())
} }
Tag::List(it) | Tag::Array(it) => { Tag::List(it) | Tag::Array(it) => {
#[repr(C)]
struct List { elements: *mut (), length: u32 }; struct List { elements: *mut (), length: u32 };
consume_value!(List, |ptr| { consume_value!(List, |ptr| {
(*ptr).length = proto_async::read_i32(stream).await? as u32; (*ptr).length = proto_async::read_i32(stream).await? as u32;
@ -174,6 +175,7 @@ unsafe fn send_value<W>(writer: &mut W, tag: Tag, data: &mut *const ())
Ok(()) Ok(())
} }
Tag::Keyword(it) => { Tag::Keyword(it) => {
#[repr(C)]
struct Keyword<'a> { name: CSlice<'a, u8> }; struct Keyword<'a> { name: CSlice<'a, u8> };
consume_value!(Keyword, |ptr| { consume_value!(Keyword, |ptr| {
writer.write_string(str::from_utf8((*ptr).name.as_ref()).unwrap())?; writer.write_string(str::from_utf8((*ptr).name.as_ref()).unwrap())?;
@ -185,6 +187,7 @@ unsafe fn send_value<W>(writer: &mut W, tag: Tag, data: &mut *const ())
// to accurately advance data. // to accurately advance data.
} }
Tag::Object => { Tag::Object => {
#[repr(C)]
struct Object { id: u32 }; struct Object { id: u32 };
consume_value!(*const Object, |ptr| consume_value!(*const Object, |ptr|
writer.write_u32((**ptr).id)) writer.write_u32((**ptr).id))