Function sp_runtime_interface::pack_ptr_and_len
source · Expand description
Pack a pointer and length into an u64
.
Examples found in repository?
More examples
src/impls.rs (line 170)
160 161 162 163 164 165 166 167 168 169 170 171
fn into_ffi_value(self, context: &mut dyn FunctionContext) -> Result<u64> {
let vec: Cow<'_, [u8]> = if TypeId::of::<T>() == TypeId::of::<u8>() {
unsafe { Cow::Borrowed(mem::transmute(&self[..])) }
} else {
Cow::Owned(self.encode())
};
let ptr = context.allocate_memory(vec.as_ref().len() as u32)?;
context.write_memory(ptr, &vec)?;
Ok(pack_ptr_and_len(ptr.into(), vec.len() as u32))
}