pub fn write_msg<T: Serialize>(value: &T) -> u64Expand description
Serializes a value using bincode and returns a combined representation.
This function serializes a value implementing the serde::ser::Serialize trait
using the bincode serialization format. The serialized data is stored in a Vec<u8>
buffer, and a combined representation of the buffer’s pointer and length is
obtained using the into_bitwise function. The ownership of the buffer is
transferred to the caller, who is responsible for deallocating it using the
dealloc function.
§Arguments
value- A reference to the value to be serialized.
§Returns
A combined representation of the serialized buffer’s pointer and length.
§Examples
use plugy_core::guest::dealloc;
use plugy_core::guest::write_msg;
#[derive(serde::Serialize)]
struct MyStruct {
// Fields of MyStruct...
}
let my_instance = MyStruct { /* initialize fields */ };
let combined = write_msg(&my_instance);
// Deallocate the buffer when no longer needed.
unsafe { dealloc(combined) };