Function hdk::prelude::allocation::write_bytes [−][src]
pub fn write_bytes(slice: &[u8]) -> u32
Attempt to write a slice of bytes into a length prefixed allocation.
This is identical to the following:
- host has some slice of bytes
- host calls __allocate with the slice length
- guest returns GuestPtr to the host
- host writes a length prefix and the slice bytes into the guest at GuestPtr location
- host hands the GuestPtr back to the guest
In this case everything happens within the guest and a GuestPtr is returned if successful.
This also leaks the written bytes, exactly like the above process.
This facilitates the guest handing a GuestPtr back to the host as the return value of guest functions so that the host can read the output of guest logic from a length-prefixed pointer.
A good host will call __deallocate with the GuestPtr produced here once it has read the bytes out of the guest, otherwise the bytes will be permanently leaked for the lifetime of the guest.