Skip to content

Commit 804f4bf

Browse files
committed
update README.md to use new macros
Signed-off-by: Jorge Prendes <[email protected]>
1 parent 9d80744 commit 804f4bf

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

README.md

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -74,54 +74,33 @@ fn main() -> hyperlight_host::Result<()> {
7474
#![no_main]
7575
extern crate alloc;
7676

77-
use alloc::string::ToString;
7877
use alloc::vec::Vec;
78+
use alloc::string::String;
7979
use hyperlight_common::flatbuffer_wrappers::function_call::FunctionCall;
80-
use hyperlight_common::flatbuffer_wrappers::function_types::{
81-
ParameterType, ParameterValue, ReturnType,
82-
};
8380
use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
84-
use hyperlight_common::flatbuffer_wrappers::util::get_flatbuffer_result;
85-
86-
use hyperlight_guest::error::{HyperlightGuestError, Result};
87-
use hyperlight_guest_bin::guest_function::definition::GuestFunctionDefinition;
88-
use hyperlight_guest_bin::guest_function::register::register_function;
89-
use hyperlight_guest_bin::host_comm::call_host_function;
90-
91-
fn print_output(function_call: &FunctionCall) -> Result<Vec<u8>> {
92-
if let ParameterValue::String(message) = function_call.parameters.clone().unwrap()[0].clone() {
93-
let result = call_host_function::<i32>(
94-
"HostPrint",
95-
Some(Vec::from(&[ParameterValue::String(message.to_string())])),
96-
ReturnType::Int,
97-
)?;
98-
Ok(get_flatbuffer_result(result))
99-
} else {
100-
Err(HyperlightGuestError::new(
101-
ErrorCode::GuestFunctionParameterTypeMismatch,
102-
"Invalid parameters passed to simple_print_output".to_string(),
103-
))
104-
}
81+
82+
use hyperlight_guest::bail;
83+
use hyperlight_guest::error::Result;
84+
use hyperlight_guest_bin::{guest_function, host_function};
85+
86+
#[host_function("HostPrint")]
87+
fn host_print(message: String) -> Result<i32>;
88+
89+
#[guest_function("PrintOutput")]
90+
fn print_output(message: String) -> Result<i32> {
91+
let result = host_print(message)?;
92+
Ok(result)
10593
}
10694

10795
#[no_mangle]
10896
pub extern "C" fn hyperlight_main() {
109-
let print_output_def = GuestFunctionDefinition::new(
110-
"PrintOutput".to_string(),
111-
Vec::from(&[ParameterType::String]),
112-
ReturnType::Int,
113-
print_output as usize,
114-
);
115-
register_function(print_output_def);
97+
// any initialization code goes here
11698
}
11799

118100
#[no_mangle]
119101
pub fn guest_dispatch_function(function_call: FunctionCall) -> Result<Vec<u8>> {
120-
let function_name = function_call.function_name.clone();
121-
return Err(HyperlightGuestError::new(
122-
ErrorCode::GuestFunctionNotFound,
123-
function_name,
124-
));
102+
let function_name = function_call.function_name;
103+
bail!(ErrorCode::GuestFunctionNotFound => "{function_name}");
125104
}
126105
```
127106

0 commit comments

Comments
 (0)