extern "C" fn dispatch_thunk<T>(
	serialized_args_ptr: *const u8,
	serialized_args_len: usize,
	state: usize,
	f: ffi::HostFuncIndex,
) -> u64 {
	let serialized_args = unsafe {
		if serialized_args_len == 0 {
			&[]
		} else {
			slice::from_raw_parts(serialized_args_ptr, serialized_args_len)
		}
	};
	let args = Vec::<TypedValue>::decode(&mut &serialized_args[..]).expect(
		"serialized args should be provided by the runtime;
			correctly serialized data should be deserializable;
			qed",
	);

	unsafe {
		// This should be safe since `coerce_host_index_to_func` is called with an argument
		// received in an `dispatch_thunk` implementation, so `f` should point
		// on a valid host function.
		let f = ffi::coerce_host_index_to_func(f);

		// This should be safe since mutable reference to T is passed upon the invocation.
		let state = &mut *(state as *mut T);

		// Pass control flow to the designated function.
		let result = f(state, &args).encode();

		// Leak the result vector and return the pointer to return data.
		let result_ptr = result.as_ptr() as u64;
		let result_len = result.len() as u64;
		mem::forget(result);

		(result_ptr << 32) | result_len
	}
}
/// The primary responsibility of this thunk is to deserialize arguments and
/// call the original function, specified by the index.
The primary responsibility of this thunk is to deserialize arguments and
call the original function, specified by the index.
The primary responsibility of this thunk is to deserialize arguments and call the original function specified by the index .
extern "C" fn dispatch_thunk<T>(
	serialized_args_ptr: *const u8,
	serialized_args_len: usize,
	state: usize,
	f: ffi::HostFuncIndex,
) -> u64 {
	let serialized_args = unsafe {
		if serialized_args_len == 0 {
			&[]
		} else {
			slice::from_raw_parts(serialized_args_ptr, serialized_args_len)
		}
	};
	let args = Vec::<TypedValue>::decode(&mut &serialized_args[..]).expect(
		"serialized args should be provided by the runtime;
			correctly serialized data should be deserializable;
			qed",
	);
	unsafe {
		// This should be safe since `coerce_host_index_to_func` is called with an argument
		// received in an `dispatch_thunk` implementation, so `f` should point
		// on a valid host function.
		let f = ffi::coerce_host_index_to_func(f);
		// This should be safe since mutable reference to T is passed upon the invocation.
		let state = &mut *(state as *mut T);
		// Pass control flow to the designated function.
		let result = f(state, &args).encode();
		// Leak the result vector and return the pointer to return data.
		let result_ptr = result.as_ptr() as u64;
		let result_len = result.len() as u64;
		mem::forget(result);
		(result_ptr << 32) | result_len
	}
}
extern " " fn dispatch_thunk < T > ( serialized_args_ptr : * const u8 , serialized_args_len : usize , state : usize , f : ffi :: HostFuncIndex , ) -> u64 { let serialized_args = unsafe { if serialized_args_len == 0 { & [ ] } else { slice :: from_raw_parts ( serialized_args_ptr , serialized_args_len ) } } ; let args = Vec :: < TypedValue > :: decode ( & mut & serialized_args [ .. ] ) . expect ( " " , ) ; unsafe { // This should be safe since `coerce_host_index_to_func` is called with an argument // received in an `dispatch_thunk` implementation, so `f` should point // on a valid host function. let f = ffi :: coerce_host_index_to_func ( f ) ; // This should be safe since mutable reference to T is passed upon the invocation. let state = & mut * ( state as * mut T ) ; // Pass control flow to the designated function. let result = f ( state , & args ) . encode ( ) ; // Leak the result vector and return the pointer to return data. let result_ptr = result . as_ptr ( ) as u64 ; let result_len = result . len ( ) as u64 ; mem :: forget ( result ) ; ( result_ptr << 32 ) | result_len } }
The primary responsibility of this thunk is to deserialize arguments and
call the original function, specified by the index.
The primary responsibility of this thunk is to deserialize arguments and call the original function specified by the index .
serialized_args_ptr
*const u8
serialized_args_len
usize
state
usize
f
ffi::HostFuncIndex
serialized_args_ptr
*const u8
serialized_args_len
usize
state
usize
f
ffi::HostFuncIndex