@@ -19,7 +19,6 @@ use alloc::string::ToString;
1919use alloc:: vec:: Vec ;
2020use core:: slice:: from_raw_parts;
2121
22- use flatbuffers:: FlatBufferBuilder ;
2322use hyperlight_common:: flatbuffer_wrappers:: function_call:: { FunctionCall , FunctionCallType } ;
2423use hyperlight_common:: flatbuffer_wrappers:: function_types:: {
2524 FunctionCallResult , ParameterValue , ReturnType , ReturnValue ,
@@ -28,7 +27,9 @@ use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
2827use hyperlight_common:: flatbuffer_wrappers:: guest_log_data:: GuestLogData ;
2928use hyperlight_common:: flatbuffer_wrappers:: guest_log_level:: LogLevel ;
3029use hyperlight_common:: flatbuffer_wrappers:: host_function_details:: HostFunctionDetails ;
31- use hyperlight_common:: flatbuffer_wrappers:: util:: estimate_flatbuffer_capacity;
30+ use hyperlight_common:: flatbuffer_wrappers:: util:: {
31+ decode, encode, encode_extend, estimate_flatbuffer_capacity,
32+ } ;
3233use hyperlight_common:: outb:: OutBAction ;
3334use tracing:: instrument;
3435
@@ -124,10 +125,15 @@ impl GuestHandle {
124125 return_type,
125126 ) ;
126127
127- let mut builder = FlatBufferBuilder :: with_capacity ( estimated_capacity) ;
128-
129- let host_function_call_buffer = host_function_call. encode ( & mut builder) ;
130- self . push_shared_output_data ( host_function_call_buffer) ?;
128+ let host_function_call_buffer = Vec :: with_capacity ( estimated_capacity) ;
129+ let host_function_call_buffer =
130+ encode_extend ( & host_function_call, host_function_call_buffer) . map_err ( |e| {
131+ HyperlightGuestError :: new (
132+ ErrorCode :: GuestError ,
133+ format ! ( "Error serializing host function call to flatbuffer: {}" , e) ,
134+ )
135+ } ) ?;
136+ self . push_shared_output_data ( & host_function_call_buffer) ?;
131137
132138 unsafe {
133139 out32 ( OutBAction :: CallFunction as u16 , 0 ) ;
@@ -163,8 +169,7 @@ impl GuestHandle {
163169 let host_function_details_slice: & [ u8 ] =
164170 unsafe { from_raw_parts ( host_function_details_buffer, host_function_details_size) } ;
165171
166- host_function_details_slice
167- . try_into ( )
172+ decode ( host_function_details_slice)
168173 . expect ( "Failed to convert buffer to HostFunctionDetails" )
169174 }
170175
@@ -189,9 +194,8 @@ impl GuestHandle {
189194 line,
190195 ) ;
191196
192- let bytes: Vec < u8 > = guest_log_data
193- . try_into ( )
194- . expect ( "Failed to convert GuestLogData to bytes" ) ;
197+ let bytes: Vec < u8 > =
198+ encode ( & guest_log_data) . expect ( "Failed to convert GuestLogData to bytes" ) ;
195199
196200 self . push_shared_output_data ( & bytes)
197201 . expect ( "Unable to push log data to shared output data" ) ;
0 commit comments