mirror of
https://github.com/logos-messaging/logos-messaging-rust-bindings.git
synced 2026-01-02 14:03:12 +00:00
fix: don't panic when unserializing json
This commit is contained in:
parent
e64fb485d9
commit
657d5a2084
@ -7,10 +7,15 @@ use std::ffi::{c_char, CStr};
|
||||
pub fn decode_and_free_response<T: DeserializeOwned>(response_ptr: *mut c_char) -> Result<T> {
|
||||
let response = unsafe { CStr::from_ptr(response_ptr) }
|
||||
.to_str()
|
||||
.expect("Response should always succeed to load to a &str");
|
||||
.map_err(|err| {
|
||||
format!(
|
||||
"could not retrieve response from pointer returned by waku: {}",
|
||||
err
|
||||
)
|
||||
})?;
|
||||
|
||||
let response: JsonResponse<T> =
|
||||
serde_json::from_str(response).expect("JsonResponse should always succeed to deserialize");
|
||||
let response: JsonResponse<T> = serde_json::from_str(response)
|
||||
.map_err(|err| format!("could not deserialize waku JsonResponse: {}", err))?;
|
||||
|
||||
unsafe {
|
||||
waku_sys::waku_utils_free(response_ptr);
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 6c34b2714154a1a73b7cbd4df7050342288da463
|
||||
Subproject commit 30811f4d9203973783a80a552d64ef5b9f719957
|
||||
Loading…
x
Reference in New Issue
Block a user