Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

pass ByteBuffer pointer instead of struct #619

Merged
merged 1 commit into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions rust/xaynet-mobile/src/ffi/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,19 +241,24 @@ pub unsafe extern "C" fn xaynet_ffi_participant_save(
/// assert(n_read == fsize);
/// fclose(f);
/// Participant *restored =
/// xaynet_ffi_participant_restore("http://localhost:8081", buf);
/// xaynet_ffi_participant_restore("http://localhost:8081", &buf);
/// free(buf.data);
/// ```
#[no_mangle]
pub unsafe extern "C" fn xaynet_ffi_participant_restore(
url: FfiStr,
buffer: ByteBuffer,
buffer: *const ByteBuffer,
) -> *mut Participant {
let url = match url.as_opt_str() {
Some(url) => url,
None => return ptr::null_mut(),
};

let buffer: &ByteBuffer = match unsafe { buffer.as_ref() } {
Some(ptr) => ptr,
None => return ptr::null_mut(),
};

if let Ok(participant) = Participant::restore(buffer.as_slice(), url) {
Box::into_raw(Box::new(participant))
} else {
Expand Down
2 changes: 1 addition & 1 deletion rust/xaynet-mobile/tests/ffi_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static char *test_participant_save_and_restore() {

// restore the participant
Participant *restored =
xaynet_ffi_participant_restore("http://localhost:8081", restore_buf);
xaynet_ffi_participant_restore("http://localhost:8081", &restore_buf);
mu_assert("failed to restore participant", restored != NULL);

// free memory
Expand Down
4 changes: 2 additions & 2 deletions rust/xaynet-mobile/xaynet_ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,11 @@ const ByteBuffer *xaynet_ffi_participant_save(Participant *participant);
* assert(n_read == fsize);
* fclose(f);
* Participant *restored =
* xaynet_ffi_participant_restore("http://localhost:8081", buf);
* xaynet_ffi_participant_restore("http://localhost:8081", &buf);
* free(buf.data);
* ```
*/
Participant *xaynet_ffi_participant_restore(FfiStr url, ByteBuffer buffer);
Participant *xaynet_ffi_participant_restore(FfiStr url, const ByteBuffer *buffer);

/**
* Set the participant's model. Usually this should be called when the value returned
Expand Down