@@ -278,12 +278,11 @@ namespace detail
278
278
279
279
ret = std::apply ( thunk, thunk_args );
280
280
281
- std::string s;
282
- ret.SerializeToString ( &s );
283
- KOINOS_ASSERT ( s.size () <= ret_len, insufficient_return_buffer_exception, " return buffer is not large enough for the return value" );
284
- #pragma message "TODO: We should avoid making copies where possible (Issue #473)"
285
- std::memcpy ( ret_ptr, s.c_str (), s.size () );
286
- *bytes_written = uint32_t ( s.size () );
281
+ std::size_t byte_size = ret.ByteSizeLong ();
282
+ KOINOS_ASSERT ( byte_size <= ret_len, insufficient_return_buffer_exception, " return buffer is not large enough for the return value" );
283
+
284
+ ret.SerializeToArray ( ret_ptr, uint32_t ( byte_size ) );
285
+ *bytes_written = uint32_t ( byte_size );
287
286
}
288
287
289
288
} // detail
@@ -325,8 +324,7 @@ class thunk_dispatcher
325
324
{
326
325
ArgStruct args;
327
326
ctx.resource_meter ().use_compute_bandwidth ( ctx.get_compute_bandwidth ( " deserialize_message_per_byte" ) * arg_len );
328
- std::string s ( arg_ptr, arg_len );
329
- args.ParseFromString ( s );
327
+ args.ParseFromArray ( arg_ptr, arg_len );
330
328
detail::call_thunk_impl< ArgStruct, RetStruct >( thunk, ctx, ret_ptr, ret_len, args, bytes_written );
331
329
});
332
330
_pass_through_map.insert_or_assign ( id, thunk );
0 commit comments