Function plugy_core::guest::read_msg
source · pub unsafe fn read_msg<T: DeserializeOwned>(value: u64) -> TExpand description
Deserializes a value using bincode from a combined representation.
This function takes a combined representation obtained from the write_msg
function, which includes a pointer and length of a serialized buffer. The
function safely deserializes the buffer back into a value implementing the
serde::de::DeserializeOwned trait and returns it. The ownership of the buffer
is transferred to the function, which takes care of proper deallocation.
Arguments
value- The combined representation of the serialized buffer’s pointer and length, obtained from thewrite_msgfunction.
Returns
The deserialized value of type T.
Safety
This function is marked as unsafe because it involves working with raw pointers
and memory management. The provided value parameter must be a valid combined
representation obtained from the write_msg function, and incorrect usage can lead
to memory corruption or other issues.
Examples
use plugy_core::guest::read_msg;
#[derive(serde::Deserialize)]
struct MyStruct {
// Fields of MyStruct...
}
let combined: u64 = 0;/* ptr on the host side */;
let my_instance: MyStruct = unsafe { read_msg(combined) };