From 1b22fdc6299ca16a9be9e6f6ed36391f33b1cb9a Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Fri, 14 Jun 2024 10:56:23 +0200 Subject: [PATCH 1/7] Pollable rpc implementation --- wasm-rpc-stubgen/src/cargo.rs | 8 + wasm-rpc-stubgen/src/lib.rs | 1 + wasm-rpc-stubgen/src/rust.rs | 337 +++++++++---- wasm-rpc-stubgen/src/wit.rs | 151 ++++-- wasm-rpc/Cargo.toml | 3 + wasm-rpc/src/bindings.rs | 921 +++++++++++++++++++++++++++++++++- wasm-rpc/src/lib.rs | 7 +- wasm-rpc/wit/deps/io/poll.wit | 41 ++ wasm-rpc/wit/wasm-rpc.wit | 9 + 9 files changed, 1315 insertions(+), 163 deletions(-) create mode 100644 wasm-rpc/wit/deps/io/poll.wit diff --git a/wasm-rpc-stubgen/src/cargo.rs b/wasm-rpc-stubgen/src/cargo.rs index b104ae8b..2acc0c48 100644 --- a/wasm-rpc-stubgen/src/cargo.rs +++ b/wasm-rpc-stubgen/src/cargo.rs @@ -88,6 +88,14 @@ pub fn generate_cargo_toml(def: &StubDefinition) -> anyhow::Result<()> { path: "wit/deps/wasm-rpc".to_string(), }, ); + + wit_dependencies.insert( + "wasi:io".to_string(), + WitDependency { + path: "wit/deps/io".to_string(), + }, + ); + for dep in &def.unresolved_deps { let dep_package = &dep.name; let stub_package_name = format!("{}-stub", def.root_package_name); diff --git a/wasm-rpc-stubgen/src/lib.rs b/wasm-rpc-stubgen/src/lib.rs index 9cd4b83c..e02209be 100644 --- a/wasm-rpc-stubgen/src/lib.rs +++ b/wasm-rpc-stubgen/src/lib.rs @@ -79,6 +79,7 @@ pub struct GenerateArgs { /// the latest version of `wasm-rpc` will be used. #[clap(long)] pub wasm_rpc_path_override: Option, + } /// Build an RPC stub for a WASM component diff --git a/wasm-rpc-stubgen/src/rust.rs b/wasm-rpc-stubgen/src/rust.rs index 447d6014..dcca641b 100644 --- a/wasm-rpc-stubgen/src/rust.rs +++ b/wasm-rpc-stubgen/src/rust.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::stub::{FunctionResultStub, FunctionStub, StubDefinition}; +use crate::stub::{FunctionResultStub, FunctionStub, InterfaceStub, StubDefinition}; use anyhow::anyhow; use heck::{ToShoutySnakeCase, ToSnakeCase, ToUpperCamelCase}; use proc_macro2::{Ident, Span, TokenStream}; @@ -71,8 +71,35 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> { #(#struct_fns)* } }); + + for function in &interface.functions { + if !function.results.is_empty() { + let result_wrapper = result_wrapper_ident(function); + struct_defs.push(quote! { + pub struct #result_wrapper { + pub future_invoke_result: FutureInvokeResult + } + }) + } + } + for function in &interface.static_functions { + if !function.results.is_empty() { + let result_wrapper = result_wrapper_ident(function); + struct_defs.push(quote! { + pub struct #result_wrapper { + pub future_invoke_result: FutureInvokeResult + } + }) + } + } } + let stub_interface_name = format!("stub-{}", def.source_world_name()?); + let stub_interface_name = Ident::new( + &to_rust_ident(&stub_interface_name).to_snake_case(), + Span::call_site(), + ); + let mut interface_impls = Vec::new(); for interface in &def.interfaces { let interface_ident = to_rust_ident(&interface.name).to_upper_camel_case(); @@ -82,17 +109,45 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> { let mut fn_impls = Vec::new(); for function in &interface.functions { + let mode = if interface.is_resource() { + FunctionMode::Method + } else { + FunctionMode::Global + }; fn_impls.push(generate_function_stub_source( def, function, interface.interface_name(), interface.resource_name(), - if interface.is_resource() { - FunctionMode::Method - } else { - FunctionMode::Global - }, + mode, )?); + + if !function.results.is_empty() { + let result_wrapper = result_wrapper_ident(function); + let result_wrapper_interface = result_wrapper_interface_ident(function); + + let subscribe = quote! { + fn subscribe(&self) -> bindings::wasi::io::poll::Pollable { + let pollable = self.future_invoke_result.subscribe(); + let pollable = unsafe { + bindings::wasi::io::poll::Pollable::from_handle( + pollable.into_handle() + ) + }; + pollable + } + }; + + let get = generate_result_wrapper_get_source(def, interface, function, mode)?; + + let result_wrapper_impl = quote! { + impl crate::bindings::exports::#root_ns::#root_name::#stub_interface_name::#result_wrapper_interface for #result_wrapper { + #subscribe + #get + } + }; + interface_impls.push(result_wrapper_impl); + } } for function in &interface.static_functions { @@ -103,13 +158,39 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> { interface.resource_name(), FunctionMode::Static, )?); - } - let stub_interface_name = format!("stub-{}", def.source_world_name()?); - let stub_interface_name = Ident::new( - &to_rust_ident(&stub_interface_name).to_snake_case(), - Span::call_site(), - ); + if !function.results.is_empty() { + let result_wrapper = result_wrapper_ident(function); + let result_wrapper_interface = result_wrapper_interface_ident(function); + + let subscribe = quote! { + fn subscribe(&self) -> bindings::wasi::io::poll::Pollable { + let pollable = self.future_invoke_result.subscribe(); + let pollable = unsafe { + bindings::wasi::io::poll::Pollable::from_handle( + pollable.into_handle() + ) + }; + pollable + } + }; + + let get = generate_result_wrapper_get_source( + def, + interface, + function, + FunctionMode::Static, + )?; + + let result_wrapper_impl = quote! { + impl crate::bindings::exports::#root_ns::#root_name::#stub_interface_name::#result_wrapper_interface for #result_wrapper { + #subscribe + #get + } + }; + interface_impls.push(result_wrapper_impl); + } + } let constructor = if interface.is_resource() { let constructor_stub = FunctionStub { @@ -198,6 +279,44 @@ enum FunctionMode { Constructor, } +fn result_wrapper_ident(function: &FunctionStub) -> Ident { + Ident::new( + &to_rust_ident(&format!("future-{}-result", function.name)).to_upper_camel_case(), + Span::call_site(), + ) +} + +fn result_wrapper_interface_ident(function: &FunctionStub) -> Ident { + Ident::new( + &to_rust_ident(&format!("guest-future-{}-result", function.name)).to_upper_camel_case(), + Span::call_site(), + ) +} + +fn generate_result_wrapper_get_source( + def: &StubDefinition, + interface: &InterfaceStub, + function: &FunctionStub, + mode: FunctionMode, +) -> anyhow::Result { + let result_type = get_result_type_source(def, function)?; + let output_values = get_output_values_source(def, function, mode)?; + + let remote_function_name = get_remote_function_name( + def, + &function.name, + interface.interface_name().as_ref(), + interface.resource_name().as_ref(), + ); + + Ok(quote! { + fn get(&self) -> #result_type { + let result = self.future_invoke_result.get().expect(&format!("Failed to invoke remote {}", #remote_function_name));; + (#(#output_values),*) + } + }) +} + fn generate_function_stub_source( def: &StubDefinition, function: &FunctionStub, @@ -208,7 +327,6 @@ fn generate_function_stub_source( let function_name = Ident::new(&to_rust_ident(&function.name), Span::call_site()); let mut params = Vec::new(); let mut input_values = Vec::new(); - let mut output_values = Vec::new(); if mode != FunctionMode::Static && mode != FunctionMode::Constructor { params.push(quote! {&self}); @@ -241,70 +359,8 @@ fn generate_function_stub_source( )?); } - let result_type = match &function.results { - FunctionResultStub::Single(typ) => { - let typ = type_to_rust_ident(typ, &def.resolve)?; - quote! { - #typ - } - } - FunctionResultStub::Multi(params) => { - let mut results = Vec::new(); - for param in params { - let param_name = Ident::new(&to_rust_ident(¶m.name), Span::call_site()); - let param_typ = type_to_rust_ident(¶m.typ, &def.resolve)?; - results.push(quote! { - #param_name: #param_typ - }); - } - if results.is_empty() { - quote! { - () - } - } else { - quote! { - (#(#results),*) - } - } - } - FunctionResultStub::SelfType => quote! { Self }, - }; - - match &function.results { - FunctionResultStub::Single(typ) => { - output_values.push(extract_from_wit_value( - typ, - &def.resolve, - quote! { result.tuple_element(0).expect("tuple not found") }, - )?); - } - FunctionResultStub::Multi(params) => { - for (n, param) in params.iter().enumerate() { - output_values.push(extract_from_wit_value( - ¶m.typ, - &def.resolve, - quote! { result.tuple_element(#n).expect("tuple not found") }, - )?); - } - } - FunctionResultStub::SelfType if mode == FunctionMode::Constructor => { - output_values.push(quote! { - { - let (uri, id) = result.tuple_element(0).expect("tuple not found").handle().expect("handle not found"); - Self { - rpc, - id, - uri - } - } - }); - } - FunctionResultStub::SelfType => { - return Err(anyhow!( - "SelfType result is only supported for constructors" - )); - } - } + let result_type = get_result_type_source(def, function)?; + let output_values = get_output_values_source(def, function, mode)?; let remote_function_name = get_remote_function_name( def, @@ -341,14 +397,12 @@ fn generate_function_stub_source( }; let blocking = { - let function_name = if function.results.is_empty() { - Ident::new( - &to_rust_ident(&format!("blocking-{}", function.name)), - Span::call_site(), - ) + let blocking_function_name = if mode == FunctionMode::Constructor { + function.name.clone() } else { - function_name.clone() + format!("blocking-{}", function.name) }; + let function_name = Ident::new(&to_rust_ident(&blocking_function_name), Span::call_site()); quote! { fn #function_name(#(#params),*) -> #result_type { #init @@ -363,17 +417,33 @@ fn generate_function_stub_source( } }; - let non_blocking = if function.results.is_empty() { - quote! { - fn #function_name(#(#params),*) -> #result_type { - #init - let result = #rpc.invoke( - #remote_function_name, - &[ - #(#input_values),* - ], - ).expect(&format!("Failed to invoke remote {}", #remote_function_name)); - (#(#output_values),*) + let non_blocking = if mode != FunctionMode::Constructor { + if function.results.is_empty() { + quote! { + fn #function_name(#(#params),*) -> #result_type { + #init + let result = #rpc.invoke( + #remote_function_name, + &[ + #(#input_values),* + ], + ).expect(&format!("Failed to invoke remote {}", #remote_function_name)); + (#(#output_values),*) + } + } + } else { + let result_wrapper = result_wrapper_ident(function); + quote! { + fn #function_name(#(#params),*) -> wit_bindgen::rt::Resource<#result_wrapper> { + #init + let result = #rpc.async_invoke_and_await( + #remote_function_name, + &[ + #(#input_values),* + ], + ); + wit_bindgen::rt::Resource::new(#result_wrapper { future_invoke_result: result}) + } } } } else { @@ -386,6 +456,85 @@ fn generate_function_stub_source( }) } +fn get_output_values_source( + def: &StubDefinition, + function: &FunctionStub, + mode: FunctionMode, +) -> anyhow::Result> { + let mut output_values = Vec::new(); + match &function.results { + FunctionResultStub::Single(typ) => { + output_values.push(extract_from_wit_value( + typ, + &def.resolve, + quote! { result.tuple_element(0).expect("tuple not found") }, + )?); + } + FunctionResultStub::Multi(params) => { + for (n, param) in params.iter().enumerate() { + output_values.push(extract_from_wit_value( + ¶m.typ, + &def.resolve, + quote! { result.tuple_element(#n).expect("tuple not found") }, + )?); + } + } + FunctionResultStub::SelfType if mode == FunctionMode::Constructor => { + output_values.push(quote! { + { + let (uri, id) = result.tuple_element(0).expect("tuple not found").handle().expect("handle not found"); + Self { + rpc, + id, + uri + } + } + }); + } + FunctionResultStub::SelfType => { + return Err(anyhow!( + "SelfType result is only supported for constructors" + )); + } + } + Ok(output_values) +} + +fn get_result_type_source( + def: &StubDefinition, + function: &FunctionStub, +) -> anyhow::Result { + let result_type = match &function.results { + FunctionResultStub::Single(typ) => { + let typ = type_to_rust_ident(typ, &def.resolve)?; + quote! { + #typ + } + } + FunctionResultStub::Multi(params) => { + let mut results = Vec::new(); + for param in params { + let param_name = Ident::new(&to_rust_ident(¶m.name), Span::call_site()); + let param_typ = type_to_rust_ident(¶m.typ, &def.resolve)?; + results.push(quote! { + #param_name: #param_typ + }); + } + if results.is_empty() { + quote! { + () + } + } else { + quote! { + (#(#results),*) + } + } + } + FunctionResultStub::SelfType => quote! { Self }, + }; + Ok(result_type) +} + fn get_remote_function_name( def: &StubDefinition, function_name: &str, diff --git a/wasm-rpc-stubgen/src/wit.rs b/wasm-rpc-stubgen/src/wit.rs index a9a909e7..6de72565 100644 --- a/wasm-rpc-stubgen/src/wit.rs +++ b/wasm-rpc-stubgen/src/wit.rs @@ -13,7 +13,7 @@ // limitations under the License. use crate::stub::{ - FunctionParamStub, FunctionResultStub, InterfaceStubImport, InterfaceStubTypeDef, + FunctionParamStub, FunctionResultStub, FunctionStub, InterfaceStubImport, InterfaceStubTypeDef, StubDefinition, }; use anyhow::{anyhow, bail, Context}; @@ -63,6 +63,7 @@ pub fn get_stub_wit( .collect::>(); writeln!(out, " use golem:rpc/types@0.1.0.{{uri}};")?; + writeln!(out, " use wasi:io/poll@0.2.0.{{pollable}};")?; match type_gen_strategy { StubTypeGen::ImportRootTypes => { @@ -91,6 +92,21 @@ pub fn get_stub_wit( } } + // Generating async return types + for interface in &def.interfaces { + for function in &interface.functions { + if !function.results.is_empty() { + write_async_return_type(&mut out, function, def)?; + } + } + for function in &interface.static_functions { + if !function.results.is_empty() { + write_async_return_type(&mut out, function, def)?; + } + } + } + + // Generating function definitions for interface in &def.interfaces { writeln!(out, " resource {} {{", &interface.name)?; match &interface.constructor_params { @@ -107,59 +123,10 @@ pub fn get_stub_wit( } } for function in &interface.functions { - if !function.results.is_empty() { - write!(out, " {}: func(", function.name)?; - write_param_list(&mut out, def, &function.params)?; - write!(out, ")")?; - write!(out, " -> ")?; - match &function.results { - FunctionResultStub::Single(typ) => { - write!(out, "{}", typ.wit_type_string(&def.resolve)?)?; - } - FunctionResultStub::Multi(params) => { - write!(out, "(")?; - write_param_list(&mut out, def, params)?; - write!(out, ")")?; - } - FunctionResultStub::SelfType => { - return Err(anyhow!("Unexpected return type in wit generator")); - } - } - } else { - // Write the blocking function - write!(out, " blocking-{}: func(", function.name)?; - write_param_list(&mut out, def, &function.params)?; - write!(out, ")")?; - writeln!(out, ";")?; - - // Write the non blocking function - write!(out, " {}: func(", function.name)?; - write_param_list(&mut out, def, &function.params)?; - write!(out, ")")?; - } - writeln!(out, ";")?; + write_function_definition(&mut out, function, false, def)?; } for function in &interface.static_functions { - write!(out, " {}: static func(", function.name)?; - write_param_list(&mut out, def, &function.params)?; - write!(out, ")")?; - if !function.results.is_empty() { - write!(out, " -> ")?; - match &function.results { - FunctionResultStub::Single(typ) => { - write!(out, "{}", typ.wit_type_string(&def.resolve)?)?; - } - FunctionResultStub::Multi(params) => { - write!(out, "(")?; - write_param_list(&mut out, def, params)?; - write!(out, ")")?; - } - FunctionResultStub::SelfType => { - return Err(anyhow!("Unexpected return type in wit generator")); - } - } - } - writeln!(out, ";")?; + write_function_definition(&mut out, function, true, def)?; } writeln!(out, " }}")?; writeln!(out)?; @@ -179,6 +146,77 @@ pub fn get_stub_wit( Ok(out) } +fn write_function_definition( + out: &mut String, + function: &FunctionStub, + is_static: bool, + def: &StubDefinition, +) -> anyhow::Result<()> { + let func = if is_static { "static_func" } else { "func" }; + if !function.results.is_empty() { + // Write the blocking function + write!(out, " blocking-{}: {func}(", function.name)?; + write_param_list(out, def, &function.params)?; + write!(out, ")")?; + write!(out, " -> ")?; + write_function_result_type(out, function, def)?; + writeln!(out, ";")?; + // Write the non blocking function + write!(out, " {}: {func}(", function.name)?; + write_param_list(out, def, &function.params)?; + write!(out, ")")?; + write!(out, " -> future-{}-result", function.name)?; + } else { + // Write the blocking function + write!(out, " blocking-{}: {func}(", function.name)?; + write_param_list(out, def, &function.params)?; + write!(out, ")")?; + writeln!(out, ";")?; + + // Write the non blocking function + write!(out, " {}: {func}(", function.name)?; + write_param_list(out, def, &function.params)?; + write!(out, ")")?; + } + writeln!(out, ";")?; + Ok(()) +} + +fn write_async_return_type( + out: &mut String, + function: &FunctionStub, + def: &StubDefinition, +) -> anyhow::Result<()> { + writeln!(out, " resource future-{}-result {{", function.name)?; + writeln!(out, " subscribe: func() -> pollable;")?; + write!(out, " get: func() -> ")?; + write_function_result_type(out, function, def)?; + writeln!(out, ";")?; + writeln!(out, " }}")?; + Ok(()) +} + +fn write_function_result_type( + out: &mut String, + function: &FunctionStub, + def: &StubDefinition, +) -> anyhow::Result<()> { + match &function.results { + FunctionResultStub::Single(typ) => { + write!(out, "{}", typ.wit_type_string(&def.resolve)?)?; + } + FunctionResultStub::Multi(params) => { + write!(out, "(")?; + write_param_list(out, def, params)?; + write!(out, ")")?; + } + FunctionResultStub::SelfType => { + return Err(anyhow!("Unexpected return type in wit generator")); + } + } + Ok(()) +} + fn write_type_def( out: &mut String, typ: &TypeDef, @@ -526,6 +564,15 @@ pub fn copy_wit_files(def: &StubDefinition) -> anyhow::Result<()> { wasm_rpc_root.join(Path::new("wasm-rpc.wit")), golem_wasm_rpc::WASM_RPC_WIT, )?; + + let wasi_poll_root = dest_wit_root.join(Path::new("deps/io")); + fs::create_dir_all(&wasi_poll_root).unwrap(); + println!("Writing poll.wit to {}", wasi_poll_root.to_string_lossy()); + fs::write( + wasi_poll_root.join(Path::new("poll.wit")), + golem_wasm_rpc::WASI_POLL_WIT, + )?; + Ok(()) } diff --git a/wasm-rpc/Cargo.toml b/wasm-rpc/Cargo.toml index 09f15100..0ba457ba 100644 --- a/wasm-rpc/Cargo.toml +++ b/wasm-rpc/Cargo.toml @@ -52,3 +52,6 @@ package = "golem:rpc" [package.metadata.component.target] path = "wit" + +[package.metadata.component.target.dependencies] +"wasi:io" = { path = "wit/deps/io" } diff --git a/wasm-rpc/src/bindings.rs b/wasm-rpc/src/bindings.rs index c9057717..bfe84121 100644 --- a/wasm-rpc/src/bindings.rs +++ b/wasm-rpc/src/bindings.rs @@ -8,6 +8,7 @@ pub mod golem { #[doc(hidden)] #[cfg(target_arch = "wasm32")] static __FORCE_SECTION_REF: fn() = super::super::super::__link_section; + pub type Pollable = super::super::super::wasi::io::poll::Pollable; pub type NodeIndex = i32; #[derive(Clone)] pub struct Uri { @@ -202,6 +203,52 @@ pub mod golem { } } + + #[derive(Debug)] + #[repr(transparent)] + pub struct FutureInvokeResult{ + handle: wit_bindgen::rt::Resource, + } + + impl FutureInvokeResult{ + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: wit_bindgen::rt::Resource::from_handle(handle), + } + } + + #[doc(hidden)] + pub fn into_handle(self) -> u32 { + wit_bindgen::rt::Resource::into_handle(self.handle) + } + + #[doc(hidden)] + pub fn handle(&self) -> u32 { + wit_bindgen::rt::Resource::handle(&self.handle) + } + } + + + unsafe impl wit_bindgen::rt::WasmResource for FutureInvokeResult{ + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "golem:rpc/types@0.1.0")] + extern "C" { + #[link_name = "[resource-drop]future-invoke-result"] + fn drop(_: u32); + } + + drop(_handle); + } + } + } + impl WasmRpc { #[allow(unused_unsafe, clippy::all)] pub fn new(location: &Uri,) -> Self{ @@ -1173,19 +1220,861 @@ pub mod golem { } } } - - } - - } - } - - #[cfg(target_arch = "wasm32")] - #[link_section = "component-type:wit-value"] - #[doc(hidden)] - pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1677] = [3, 0, 9, 119, 105, 116, 45, 118, 97, 108, 117, 101, 0, 97, 115, 109, 13, 0, 1, 0, 7, 237, 5, 1, 65, 2, 1, 66, 29, 1, 122, 4, 0, 10, 110, 111, 100, 101, 45, 105, 110, 100, 101, 120, 3, 0, 0, 1, 114, 1, 5, 118, 97, 108, 117, 101, 115, 4, 0, 3, 117, 114, 105, 3, 0, 2, 1, 112, 1, 1, 107, 1, 1, 111, 2, 121, 5, 1, 112, 127, 1, 106, 1, 5, 1, 5, 1, 111, 2, 3, 119, 1, 113, 22, 12, 114, 101, 99, 111, 114, 100, 45, 118, 97, 108, 117, 101, 1, 4, 0, 13, 118, 97, 114, 105, 97, 110, 116, 45, 118, 97, 108, 117, 101, 1, 6, 0, 10, 101, 110, 117, 109, 45, 118, 97, 108, 117, 101, 1, 121, 0, 11, 102, 108, 97, 103, 115, 45, 118, 97, 108, 117, 101, 1, 7, 0, 11, 116, 117, 112, 108, 101, 45, 118, 97, 108, 117, 101, 1, 4, 0, 10, 108, 105, 115, 116, 45, 118, 97, 108, 117, 101, 1, 4, 0, 12, 111, 112, 116, 105, 111, 110, 45, 118, 97, 108, 117, 101, 1, 5, 0, 12, 114, 101, 115, 117, 108, 116, 45, 118, 97, 108, 117, 101, 1, 8, 0, 7, 112, 114, 105, 109, 45, 117, 56, 1, 125, 0, 8, 112, 114, 105, 109, 45, 117, 49, 54, 1, 123, 0, 8, 112, 114, 105, 109, 45, 117, 51, 50, 1, 121, 0, 8, 112, 114, 105, 109, 45, 117, 54, 52, 1, 119, 0, 7, 112, 114, 105, 109, 45, 115, 56, 1, 126, 0, 8, 112, 114, 105, 109, 45, 115, 49, 54, 1, 124, 0, 8, 112, 114, 105, 109, 45, 115, 51, 50, 1, 122, 0, 8, 112, 114, 105, 109, 45, 115, 54, 52, 1, 120, 0, 12, 112, 114, 105, 109, 45, 102, 108, 111, 97, 116, 51, 50, 1, 118, 0, 12, 112, 114, 105, 109, 45, 102, 108, 111, 97, 116, 54, 52, 1, 117, 0, 9, 112, 114, 105, 109, 45, 99, 104, 97, 114, 1, 116, 0, 9, 112, 114, 105, 109, 45, 98, 111, 111, 108, 1, 127, 0, 11, 112, 114, 105, 109, 45, 115, 116, 114, 105, 110, 103, 1, 115, 0, 6, 104, 97, 110, 100, 108, 101, 1, 9, 0, 4, 0, 8, 119, 105, 116, 45, 110, 111, 100, 101, 3, 0, 10, 1, 112, 11, 1, 114, 1, 5, 110, 111, 100, 101, 115, 12, 4, 0, 9, 119, 105, 116, 45, 118, 97, 108, 117, 101, 3, 0, 13, 1, 113, 4, 14, 112, 114, 111, 116, 111, 99, 111, 108, 45, 101, 114, 114, 111, 114, 1, 115, 0, 6, 100, 101, 110, 105, 101, 100, 1, 115, 0, 9, 110, 111, 116, 45, 102, 111, 117, 110, 100, 1, 115, 0, 21, 114, 101, 109, 111, 116, 101, 45, 105, 110, 116, 101, 114, 110, 97, 108, 45, 101, 114, 114, 111, 114, 1, 115, 0, 4, 0, 9, 114, 112, 99, 45, 101, 114, 114, 111, 114, 3, 0, 15, 4, 0, 8, 119, 97, 115, 109, 45, 114, 112, 99, 3, 1, 1, 105, 17, 1, 64, 1, 8, 108, 111, 99, 97, 116, 105, 111, 110, 3, 0, 18, 4, 0, 21, 91, 99, 111, 110, 115, 116, 114, 117, 99, 116, 111, 114, 93, 119, 97, 115, 109, 45, 114, 112, 99, 1, 19, 1, 104, 17, 1, 112, 14, 1, 106, 1, 14, 1, 16, 1, 64, 3, 4, 115, 101, 108, 102, 20, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 21, 0, 22, 4, 0, 33, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 105, 110, 118, 111, 107, 101, 45, 97, 110, 100, 45, 97, 119, 97, 105, 116, 1, 23, 1, 106, 0, 1, 16, 1, 64, 3, 4, 115, 101, 108, 102, 20, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 21, 0, 24, 4, 0, 23, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 105, 110, 118, 111, 107, 101, 1, 25, 4, 1, 21, 103, 111, 108, 101, 109, 58, 114, 112, 99, 47, 116, 121, 112, 101, 115, 64, 48, 46, 49, 46, 48, 5, 0, 11, 11, 1, 0, 5, 116, 121, 112, 101, 115, 3, 0, 0, 7, 142, 6, 1, 65, 2, 1, 65, 2, 1, 66, 29, 1, 122, 4, 0, 10, 110, 111, 100, 101, 45, 105, 110, 100, 101, 120, 3, 0, 0, 1, 114, 1, 5, 118, 97, 108, 117, 101, 115, 4, 0, 3, 117, 114, 105, 3, 0, 2, 1, 112, 1, 1, 107, 1, 1, 111, 2, 121, 5, 1, 112, 127, 1, 106, 1, 5, 1, 5, 1, 111, 2, 3, 119, 1, 113, 22, 12, 114, 101, 99, 111, 114, 100, 45, 118, 97, 108, 117, 101, 1, 4, 0, 13, 118, 97, 114, 105, 97, 110, 116, 45, 118, 97, 108, 117, 101, 1, 6, 0, 10, 101, 110, 117, 109, 45, 118, 97, 108, 117, 101, 1, 121, 0, 11, 102, 108, 97, 103, 115, 45, 118, 97, 108, 117, 101, 1, 7, 0, 11, 116, 117, 112, 108, 101, 45, 118, 97, 108, 117, 101, 1, 4, 0, 10, 108, 105, 115, 116, 45, 118, 97, 108, 117, 101, 1, 4, 0, 12, 111, 112, 116, 105, 111, 110, 45, 118, 97, 108, 117, 101, 1, 5, 0, 12, 114, 101, 115, 117, 108, 116, 45, 118, 97, 108, 117, 101, 1, 8, 0, 7, 112, 114, 105, 109, 45, 117, 56, 1, 125, 0, 8, 112, 114, 105, 109, 45, 117, 49, 54, 1, 123, 0, 8, 112, 114, 105, 109, 45, 117, 51, 50, 1, 121, 0, 8, 112, 114, 105, 109, 45, 117, 54, 52, 1, 119, 0, 7, 112, 114, 105, 109, 45, 115, 56, 1, 126, 0, 8, 112, 114, 105, 109, 45, 115, 49, 54, 1, 124, 0, 8, 112, 114, 105, 109, 45, 115, 51, 50, 1, 122, 0, 8, 112, 114, 105, 109, 45, 115, 54, 52, 1, 120, 0, 12, 112, 114, 105, 109, 45, 102, 108, 111, 97, 116, 51, 50, 1, 118, 0, 12, 112, 114, 105, 109, 45, 102, 108, 111, 97, 116, 54, 52, 1, 117, 0, 9, 112, 114, 105, 109, 45, 99, 104, 97, 114, 1, 116, 0, 9, 112, 114, 105, 109, 45, 98, 111, 111, 108, 1, 127, 0, 11, 112, 114, 105, 109, 45, 115, 116, 114, 105, 110, 103, 1, 115, 0, 6, 104, 97, 110, 100, 108, 101, 1, 9, 0, 4, 0, 8, 119, 105, 116, 45, 110, 111, 100, 101, 3, 0, 10, 1, 112, 11, 1, 114, 1, 5, 110, 111, 100, 101, 115, 12, 4, 0, 9, 119, 105, 116, 45, 118, 97, 108, 117, 101, 3, 0, 13, 1, 113, 4, 14, 112, 114, 111, 116, 111, 99, 111, 108, 45, 101, 114, 114, 111, 114, 1, 115, 0, 6, 100, 101, 110, 105, 101, 100, 1, 115, 0, 9, 110, 111, 116, 45, 102, 111, 117, 110, 100, 1, 115, 0, 21, 114, 101, 109, 111, 116, 101, 45, 105, 110, 116, 101, 114, 110, 97, 108, 45, 101, 114, 114, 111, 114, 1, 115, 0, 4, 0, 9, 114, 112, 99, 45, 101, 114, 114, 111, 114, 3, 0, 15, 4, 0, 8, 119, 97, 115, 109, 45, 114, 112, 99, 3, 1, 1, 105, 17, 1, 64, 1, 8, 108, 111, 99, 97, 116, 105, 111, 110, 3, 0, 18, 4, 0, 21, 91, 99, 111, 110, 115, 116, 114, 117, 99, 116, 111, 114, 93, 119, 97, 115, 109, 45, 114, 112, 99, 1, 19, 1, 104, 17, 1, 112, 14, 1, 106, 1, 14, 1, 16, 1, 64, 3, 4, 115, 101, 108, 102, 20, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 21, 0, 22, 4, 0, 33, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 105, 110, 118, 111, 107, 101, 45, 97, 110, 100, 45, 97, 119, 97, 105, 116, 1, 23, 1, 106, 0, 1, 16, 1, 64, 3, 4, 115, 101, 108, 102, 20, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 21, 0, 24, 4, 0, 23, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 105, 110, 118, 111, 107, 101, 1, 25, 3, 1, 21, 103, 111, 108, 101, 109, 58, 114, 112, 99, 47, 116, 121, 112, 101, 115, 64, 48, 46, 49, 46, 48, 5, 0, 4, 1, 25, 103, 111, 108, 101, 109, 58, 114, 112, 99, 47, 119, 105, 116, 45, 118, 97, 108, 117, 101, 64, 48, 46, 49, 46, 48, 4, 0, 11, 15, 1, 0, 9, 119, 105, 116, 45, 118, 97, 108, 117, 101, 3, 2, 0, 0, 16, 12, 112, 97, 99, 107, 97, 103, 101, 45, 100, 111, 99, 115, 0, 123, 125, 0, 70, 9, 112, 114, 111, 100, 117, 99, 101, 114, 115, 1, 12, 112, 114, 111, 99, 101, 115, 115, 101, 100, 45, 98, 121, 2, 13, 119, 105, 116, 45, 99, 111, 109, 112, 111, 110, 101, 110, 116, 6, 48, 46, 49, 56, 46, 50, 16, 119, 105, 116, 45, 98, 105, 110, 100, 103, 101, 110, 45, 114, 117, 115, 116, 6, 48, 46, 49, 54, 46, 48]; - - #[inline(never)] - #[doc(hidden)] - #[cfg(target_arch = "wasm32")] - pub fn __link_section() {} - \ No newline at end of file + impl WasmRpc { + #[allow(unused_unsafe, clippy::all)] + pub fn async_invoke_and_await(&self,function_name: &str,function_params: &[WitValue],) -> FutureInvokeResult{ + + #[allow(unused_imports)] + use wit_bindgen::rt::{alloc, vec::Vec, string::String}; + unsafe { + let mut cleanup_list = Vec::new(); + let vec0 = function_name; + let ptr0 = vec0.as_ptr() as i32; + let len0 = vec0.len() as i32; + let vec12 = function_params; + let len12 = vec12.len() as i32; + let layout12 = alloc::Layout::from_size_align_unchecked(vec12.len() * 8, 4); + let result12 = if layout12.size() != 0 + { + let ptr = alloc::alloc(layout12); + if ptr.is_null() + { + alloc::handle_alloc_error(layout12); + } + ptr + }else {{ + ::core::ptr::null_mut() + }}; + for (i, e) in vec12.into_iter().enumerate() { + let base = result12 as i32 + (i as i32) * 8; + { + let WitValue{ nodes:nodes1, } = e; + let vec11 = nodes1; + let len11 = vec11.len() as i32; + let layout11 = alloc::Layout::from_size_align_unchecked(vec11.len() * 24, 8); + let result11 = if layout11.size() != 0 + { + let ptr = alloc::alloc(layout11); + if ptr.is_null() + { + alloc::handle_alloc_error(layout11); + } + ptr + }else {{ + ::core::ptr::null_mut() + }}; + for (i, e) in vec11.into_iter().enumerate() { + let base = result11 as i32 + (i as i32) * 24; + { + match e { + WitNode::RecordValue(e) => { + *((base + 0) as *mut u8) = (0i32) as u8; + let vec2 = e; + let ptr2 = vec2.as_ptr() as i32; + let len2 = vec2.len() as i32; + *((base + 12) as *mut i32) = len2; + *((base + 8) as *mut i32) = ptr2; + }, + WitNode::VariantValue(e) => { + *((base + 0) as *mut u8) = (1i32) as u8; + let (t3_0, t3_1, ) = e; + *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(t3_0); + match t3_1 { + Some(e) => { + *((base + 12) as *mut u8) = (1i32) as u8; + *((base + 16) as *mut i32) = wit_bindgen::rt::as_i32(e); + }, + None => { + { + *((base + 12) as *mut u8) = (0i32) as u8; + } + }, + };}, + WitNode::EnumValue(e) => { + *((base + 0) as *mut u8) = (2i32) as u8; + *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); + }, + WitNode::FlagsValue(e) => { + *((base + 0) as *mut u8) = (3i32) as u8; + let vec4 = e; + let len4 = vec4.len() as i32; + let layout4 = alloc::Layout::from_size_align_unchecked(vec4.len() * 1, 1); + let result4 = if layout4.size() != 0 + { + let ptr = alloc::alloc(layout4); + if ptr.is_null() + { + alloc::handle_alloc_error(layout4); + } + ptr + }else {{ + ::core::ptr::null_mut() + }}; + for (i, e) in vec4.into_iter().enumerate() { + let base = result4 as i32 + (i as i32) * 1; + { + *((base + 0) as *mut u8) = (match e { true => 1, false => 0 }) as u8; + } + } + *((base + 12) as *mut i32) = len4; + *((base + 8) as *mut i32) = result4 as i32; + cleanup_list.extend_from_slice(&[(result4, layout4),]); + }, + WitNode::TupleValue(e) => { + *((base + 0) as *mut u8) = (4i32) as u8; + let vec5 = e; + let ptr5 = vec5.as_ptr() as i32; + let len5 = vec5.len() as i32; + *((base + 12) as *mut i32) = len5; + *((base + 8) as *mut i32) = ptr5; + }, + WitNode::ListValue(e) => { + *((base + 0) as *mut u8) = (5i32) as u8; + let vec6 = e; + let ptr6 = vec6.as_ptr() as i32; + let len6 = vec6.len() as i32; + *((base + 12) as *mut i32) = len6; + *((base + 8) as *mut i32) = ptr6; + }, + WitNode::OptionValue(e) => { + *((base + 0) as *mut u8) = (6i32) as u8; + match e { + Some(e) => { + *((base + 8) as *mut u8) = (1i32) as u8; + *((base + 12) as *mut i32) = wit_bindgen::rt::as_i32(e); + }, + None => { + { + *((base + 8) as *mut u8) = (0i32) as u8; + } + }, + };}, + WitNode::ResultValue(e) => { + *((base + 0) as *mut u8) = (7i32) as u8; + match e { + Ok(e) => { { + *((base + 8) as *mut u8) = (0i32) as u8; + match e { + Some(e) => { + *((base + 12) as *mut u8) = (1i32) as u8; + *((base + 16) as *mut i32) = wit_bindgen::rt::as_i32(e); + }, + None => { + { + *((base + 12) as *mut u8) = (0i32) as u8; + } + }, + };} }, + Err(e) => { { + *((base + 8) as *mut u8) = (1i32) as u8; + match e { + Some(e) => { + *((base + 12) as *mut u8) = (1i32) as u8; + *((base + 16) as *mut i32) = wit_bindgen::rt::as_i32(e); + }, + None => { + { + *((base + 12) as *mut u8) = (0i32) as u8; + } + }, + };} }, + };}, + WitNode::PrimU8(e) => { + *((base + 0) as *mut u8) = (8i32) as u8; + *((base + 8) as *mut u8) = (wit_bindgen::rt::as_i32(e)) as u8; + }, + WitNode::PrimU16(e) => { + *((base + 0) as *mut u8) = (9i32) as u8; + *((base + 8) as *mut u16) = (wit_bindgen::rt::as_i32(e)) as u16; + }, + WitNode::PrimU32(e) => { + *((base + 0) as *mut u8) = (10i32) as u8; + *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); + }, + WitNode::PrimU64(e) => { + *((base + 0) as *mut u8) = (11i32) as u8; + *((base + 8) as *mut i64) = wit_bindgen::rt::as_i64(e); + }, + WitNode::PrimS8(e) => { + *((base + 0) as *mut u8) = (12i32) as u8; + *((base + 8) as *mut u8) = (wit_bindgen::rt::as_i32(e)) as u8; + }, + WitNode::PrimS16(e) => { + *((base + 0) as *mut u8) = (13i32) as u8; + *((base + 8) as *mut u16) = (wit_bindgen::rt::as_i32(e)) as u16; + }, + WitNode::PrimS32(e) => { + *((base + 0) as *mut u8) = (14i32) as u8; + *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); + }, + WitNode::PrimS64(e) => { + *((base + 0) as *mut u8) = (15i32) as u8; + *((base + 8) as *mut i64) = wit_bindgen::rt::as_i64(e); + }, + WitNode::PrimFloat32(e) => { + *((base + 0) as *mut u8) = (16i32) as u8; + *((base + 8) as *mut f32) = wit_bindgen::rt::as_f32(e); + }, + WitNode::PrimFloat64(e) => { + *((base + 0) as *mut u8) = (17i32) as u8; + *((base + 8) as *mut f64) = wit_bindgen::rt::as_f64(e); + }, + WitNode::PrimChar(e) => { + *((base + 0) as *mut u8) = (18i32) as u8; + *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); + }, + WitNode::PrimBool(e) => { + *((base + 0) as *mut u8) = (19i32) as u8; + *((base + 8) as *mut u8) = (match e { true => 1, false => 0 }) as u8; + }, + WitNode::PrimString(e) => { + *((base + 0) as *mut u8) = (20i32) as u8; + let vec7 = e; + let ptr7 = vec7.as_ptr() as i32; + let len7 = vec7.len() as i32; + *((base + 12) as *mut i32) = len7; + *((base + 8) as *mut i32) = ptr7; + }, + WitNode::Handle(e) => { + *((base + 0) as *mut u8) = (21i32) as u8; + let (t8_0, t8_1, ) = e; + let Uri{ value:value9, } = t8_0; + let vec10 = value9; + let ptr10 = vec10.as_ptr() as i32; + let len10 = vec10.len() as i32; + *((base + 12) as *mut i32) = len10; + *((base + 8) as *mut i32) = ptr10; + *((base + 16) as *mut i64) = wit_bindgen::rt::as_i64(t8_1); + }, + } + } + } + *((base + 4) as *mut i32) = len11; + *((base + 0) as *mut i32) = result11 as i32; + cleanup_list.extend_from_slice(&[(result11, layout11),]); + } + } + + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "golem:rpc/types@0.1.0")] + extern "C" { + #[link_name = "[method]wasm-rpc.async-invoke-and-await"] + fn wit_import(_: i32, _: i32, _: i32, _: i32, _: i32, ) -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32, _: i32, _: i32, _: i32, ) -> i32{ unreachable!() } + let ret = wit_import((self).handle() as i32, ptr0, len0, result12 as i32, len12); + if layout12.size() != 0 { + alloc::dealloc(result12, layout12); + } + for (ptr, layout) in cleanup_list { + + if layout.size() != 0 { + + alloc::dealloc(ptr, layout); + + } + + } + FutureInvokeResult::from_handle(ret as u32) + } + } + } + impl FutureInvokeResult { + #[allow(unused_unsafe, clippy::all)] + pub fn subscribe(&self,) -> Pollable{ + + #[allow(unused_imports)] + use wit_bindgen::rt::{alloc, vec::Vec, string::String}; + unsafe { + + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "golem:rpc/types@0.1.0")] + extern "C" { + #[link_name = "[method]future-invoke-result.subscribe"] + fn wit_import(_: i32, ) -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, ) -> i32{ unreachable!() } + let ret = wit_import((self).handle() as i32); + super::super::super::wasi::io::poll::Pollable::from_handle(ret as u32) + } + } + } + impl FutureInvokeResult { + #[allow(unused_unsafe, clippy::all)] + pub fn get(&self,) -> Result{ + + #[allow(unused_imports)] + use wit_bindgen::rt::{alloc, vec::Vec, string::String}; + unsafe { + + #[repr(align(4))] + struct RetArea([u8; 16]); + let mut ret_area = ::core::mem::MaybeUninit::::uninit(); + let ptr0 = ret_area.as_mut_ptr() as i32; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "golem:rpc/types@0.1.0")] + extern "C" { + #[link_name = "[method]future-invoke-result.get"] + fn wit_import(_: i32, _: i32, ); + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32, ){ unreachable!() } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*((ptr0 + 0) as *const u8)); + match l1 { + 0 => { + let e = { + let l2 = *((ptr0 + 4) as *const i32); + let l3 = *((ptr0 + 8) as *const i32); + let base49 = l2; + let len49 = l3; + let mut result49 = Vec::with_capacity(len49 as usize); + for i in 0..len49 { + let base = base49 + i * 24; + let e49 = { + let l4 = i32::from(*((base + 0) as *const u8)); + let v48 = match l4 { + 0 => { + let e48 = { + let l5 = *((base + 8) as *const i32); + let l6 = *((base + 12) as *const i32); + let len7 = l6 as usize; + + Vec::from_raw_parts(l5 as *mut _, len7, len7) + }; + WitNode::RecordValue(e48) + } + 1 => { + let e48 = { + let l8 = *((base + 8) as *const i32); + let l9 = i32::from(*((base + 12) as *const u8)); + + (l8 as u32, match l9 { + 0 => None, + 1 => { + let e = { + let l10 = *((base + 16) as *const i32); + + l10 + }; + Some(e) + } + _ => wit_bindgen::rt::invalid_enum_discriminant(), + }) + }; + WitNode::VariantValue(e48) + } + 2 => { + let e48 = { + let l11 = *((base + 8) as *const i32); + + l11 as u32 + }; + WitNode::EnumValue(e48) + } + 3 => { + let e48 = { + let l12 = *((base + 8) as *const i32); + let l13 = *((base + 12) as *const i32); + let base15 = l12; + let len15 = l13; + let mut result15 = Vec::with_capacity(len15 as usize); + for i in 0..len15 { + let base = base15 + i * 1; + let e15 = { + let l14 = i32::from(*((base + 0) as *const u8)); + + wit_bindgen::rt::bool_lift(l14 as u8) + }; + result15.push(e15); + } + wit_bindgen::rt::dealloc(base15, (len15 as usize) * 1, 1); + + result15 + }; + WitNode::FlagsValue(e48) + } + 4 => { + let e48 = { + let l16 = *((base + 8) as *const i32); + let l17 = *((base + 12) as *const i32); + let len18 = l17 as usize; + + Vec::from_raw_parts(l16 as *mut _, len18, len18) + }; + WitNode::TupleValue(e48) + } + 5 => { + let e48 = { + let l19 = *((base + 8) as *const i32); + let l20 = *((base + 12) as *const i32); + let len21 = l20 as usize; + + Vec::from_raw_parts(l19 as *mut _, len21, len21) + }; + WitNode::ListValue(e48) + } + 6 => { + let e48 = { + let l22 = i32::from(*((base + 8) as *const u8)); + + match l22 { + 0 => None, + 1 => { + let e = { + let l23 = *((base + 12) as *const i32); + + l23 + }; + Some(e) + } + _ => wit_bindgen::rt::invalid_enum_discriminant(), + } + }; + WitNode::OptionValue(e48) + } + 7 => { + let e48 = { + let l24 = i32::from(*((base + 8) as *const u8)); + + match l24 { + 0 => { + let e = { + let l25 = i32::from(*((base + 12) as *const u8)); + + match l25 { + 0 => None, + 1 => { + let e = { + let l26 = *((base + 16) as *const i32); + + l26 + }; + Some(e) + } + _ => wit_bindgen::rt::invalid_enum_discriminant(), + } + }; + Ok(e) + } + 1 => { + let e = { + let l27 = i32::from(*((base + 12) as *const u8)); + + match l27 { + 0 => None, + 1 => { + let e = { + let l28 = *((base + 16) as *const i32); + + l28 + }; + Some(e) + } + _ => wit_bindgen::rt::invalid_enum_discriminant(), + } + }; + Err(e) + } + _ => wit_bindgen::rt::invalid_enum_discriminant(), + } + }; + WitNode::ResultValue(e48) + } + 8 => { + let e48 = { + let l29 = i32::from(*((base + 8) as *const u8)); + + l29 as u8 + }; + WitNode::PrimU8(e48) + } + 9 => { + let e48 = { + let l30 = i32::from(*((base + 8) as *const u16)); + + l30 as u16 + }; + WitNode::PrimU16(e48) + } + 10 => { + let e48 = { + let l31 = *((base + 8) as *const i32); + + l31 as u32 + }; + WitNode::PrimU32(e48) + } + 11 => { + let e48 = { + let l32 = *((base + 8) as *const i64); + + l32 as u64 + }; + WitNode::PrimU64(e48) + } + 12 => { + let e48 = { + let l33 = i32::from(*((base + 8) as *const i8)); + + l33 as i8 + }; + WitNode::PrimS8(e48) + } + 13 => { + let e48 = { + let l34 = i32::from(*((base + 8) as *const i16)); + + l34 as i16 + }; + WitNode::PrimS16(e48) + } + 14 => { + let e48 = { + let l35 = *((base + 8) as *const i32); + + l35 + }; + WitNode::PrimS32(e48) + } + 15 => { + let e48 = { + let l36 = *((base + 8) as *const i64); + + l36 + }; + WitNode::PrimS64(e48) + } + 16 => { + let e48 = { + let l37 = *((base + 8) as *const f32); + + l37 + }; + WitNode::PrimFloat32(e48) + } + 17 => { + let e48 = { + let l38 = *((base + 8) as *const f64); + + l38 + }; + WitNode::PrimFloat64(e48) + } + 18 => { + let e48 = { + let l39 = *((base + 8) as *const i32); + + wit_bindgen::rt::char_lift(l39 as u32) + }; + WitNode::PrimChar(e48) + } + 19 => { + let e48 = { + let l40 = i32::from(*((base + 8) as *const u8)); + + wit_bindgen::rt::bool_lift(l40 as u8) + }; + WitNode::PrimBool(e48) + } + 20 => { + let e48 = { + let l41 = *((base + 8) as *const i32); + let l42 = *((base + 12) as *const i32); + let len43 = l42 as usize; + let bytes43 = Vec::from_raw_parts(l41 as *mut _, len43, len43); + + wit_bindgen::rt::string_lift(bytes43) + }; + WitNode::PrimString(e48) + } + n => { + debug_assert_eq!(n, 21, "invalid enum discriminant"); + let e48 = { + let l44 = *((base + 8) as *const i32); + let l45 = *((base + 12) as *const i32); + let len46 = l45 as usize; + let bytes46 = Vec::from_raw_parts(l44 as *mut _, len46, len46); + let l47 = *((base + 16) as *const i64); + + (Uri{ + value: wit_bindgen::rt::string_lift(bytes46), + }, l47 as u64) + }; + WitNode::Handle(e48) + } + }; + + v48 + }; + result49.push(e49); + } + wit_bindgen::rt::dealloc(base49, (len49 as usize) * 24, 8); + + WitValue{ + nodes: result49, + } + }; + Ok(e) + } + 1 => { + let e = { + let l50 = i32::from(*((ptr0 + 4) as *const u8)); + let v63 = match l50 { + 0 => { + let e63 = { + let l51 = *((ptr0 + 8) as *const i32); + let l52 = *((ptr0 + 12) as *const i32); + let len53 = l52 as usize; + let bytes53 = Vec::from_raw_parts(l51 as *mut _, len53, len53); + + wit_bindgen::rt::string_lift(bytes53) + }; + RpcError::ProtocolError(e63) + } + 1 => { + let e63 = { + let l54 = *((ptr0 + 8) as *const i32); + let l55 = *((ptr0 + 12) as *const i32); + let len56 = l55 as usize; + let bytes56 = Vec::from_raw_parts(l54 as *mut _, len56, len56); + + wit_bindgen::rt::string_lift(bytes56) + }; + RpcError::Denied(e63) + } + 2 => { + let e63 = { + let l57 = *((ptr0 + 8) as *const i32); + let l58 = *((ptr0 + 12) as *const i32); + let len59 = l58 as usize; + let bytes59 = Vec::from_raw_parts(l57 as *mut _, len59, len59); + + wit_bindgen::rt::string_lift(bytes59) + }; + RpcError::NotFound(e63) + } + n => { + debug_assert_eq!(n, 3, "invalid enum discriminant"); + let e63 = { + let l60 = *((ptr0 + 8) as *const i32); + let l61 = *((ptr0 + 12) as *const i32); + let len62 = l61 as usize; + let bytes62 = Vec::from_raw_parts(l60 as *mut _, len62, len62); + + wit_bindgen::rt::string_lift(bytes62) + }; + RpcError::RemoteInternalError(e63) + } + }; + + v63 + }; + Err(e) + } + _ => wit_bindgen::rt::invalid_enum_discriminant(), + } + } + } + } + + } + + } + } + pub mod wasi { + pub mod io { + + #[allow(clippy::all)] + pub mod poll { + #[used] + #[doc(hidden)] + #[cfg(target_arch = "wasm32")] + static __FORCE_SECTION_REF: fn() = super::super::super::__link_section; + /// `pollable` epresents a single I/O event which may be ready, or not. + + #[derive(Debug)] + #[repr(transparent)] + pub struct Pollable{ + handle: wit_bindgen::rt::Resource, + } + + impl Pollable{ + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: wit_bindgen::rt::Resource::from_handle(handle), + } + } + + #[doc(hidden)] + pub fn into_handle(self) -> u32 { + wit_bindgen::rt::Resource::into_handle(self.handle) + } + + #[doc(hidden)] + pub fn handle(&self) -> u32 { + wit_bindgen::rt::Resource::handle(&self.handle) + } + } + + + unsafe impl wit_bindgen::rt::WasmResource for Pollable{ + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:io/poll@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]pollable"] + fn drop(_: u32); + } + + drop(_handle); + } + } + } + + impl Pollable { + #[allow(unused_unsafe, clippy::all)] + /// Return the readiness of a pollable. This function never blocks. + /// + /// Returns `true` when the pollable is ready, and `false` otherwise. + pub fn ready(&self,) -> bool{ + + #[allow(unused_imports)] + use wit_bindgen::rt::{alloc, vec::Vec, string::String}; + unsafe { + + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/poll@0.2.0")] + extern "C" { + #[link_name = "[method]pollable.ready"] + fn wit_import(_: i32, ) -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, ) -> i32{ unreachable!() } + let ret = wit_import((self).handle() as i32); + wit_bindgen::rt::bool_lift(ret as u8) + } + } + } + impl Pollable { + #[allow(unused_unsafe, clippy::all)] + /// `block` returns immediately if the pollable is ready, and otherwise + /// blocks until ready. + /// + /// This function is equivalent to calling `poll.poll` on a list + /// containing only this pollable. + pub fn block(&self,){ + + #[allow(unused_imports)] + use wit_bindgen::rt::{alloc, vec::Vec, string::String}; + unsafe { + + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/poll@0.2.0")] + extern "C" { + #[link_name = "[method]pollable.block"] + fn wit_import(_: i32, ); + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, ){ unreachable!() } + wit_import((self).handle() as i32); + } + } + } + #[allow(unused_unsafe, clippy::all)] + /// Poll for completion on a set of pollables. + /// + /// This function takes a list of pollables, which identify I/O sources of + /// interest, and waits until one or more of the events is ready for I/O. + /// + /// The result `list` contains one or more indices of handles in the + /// argument list that is ready for I/O. + /// + /// If the list contains more elements than can be indexed with a `u32` + /// value, this function traps. + /// + /// A timeout can be implemented by adding a pollable from the + /// wasi-clocks API to the list. + /// + /// This function does not return a `result`; polling in itself does not + /// do any I/O so it doesn't fail. If any of the I/O sources identified by + /// the pollables has an error, it is indicated by marking the source as + /// being reaedy for I/O. + pub fn poll(in_: &[&Pollable],) -> wit_bindgen::rt::vec::Vec::{ + + #[allow(unused_imports)] + use wit_bindgen::rt::{alloc, vec::Vec, string::String}; + unsafe { + + #[repr(align(4))] + struct RetArea([u8; 8]); + let mut ret_area = ::core::mem::MaybeUninit::::uninit(); + let vec0 = in_; + let len0 = vec0.len() as i32; + let layout0 = alloc::Layout::from_size_align_unchecked(vec0.len() * 4, 4); + let result0 = if layout0.size() != 0 + { + let ptr = alloc::alloc(layout0); + if ptr.is_null() + { + alloc::handle_alloc_error(layout0); + } + ptr + }else {{ + ::core::ptr::null_mut() + }}; + for (i, e) in vec0.into_iter().enumerate() { + let base = result0 as i32 + (i as i32) * 4; + { + *((base + 0) as *mut i32) = (e).handle() as i32; + } + } + let ptr1 = ret_area.as_mut_ptr() as i32; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/poll@0.2.0")] + extern "C" { + #[link_name = "poll"] + fn wit_import(_: i32, _: i32, _: i32, ); + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32, _: i32, ){ unreachable!() } + wit_import(result0 as i32, len0, ptr1); + let l2 = *((ptr1 + 0) as *const i32); + let l3 = *((ptr1 + 4) as *const i32); + let len4 = l3 as usize; + if layout0.size() != 0 { + alloc::dealloc(result0, layout0); + } + Vec::from_raw_parts(l2 as *mut _, len4, len4) + } + } + + } + + } + } + + #[cfg(target_arch = "wasm32")] + #[link_section = "component-type:wit-value"] + #[doc(hidden)] + pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 2368] = [3, 0, 9, 119, 105, 116, 45, 118, 97, 108, 117, 101, 0, 97, 115, 109, 13, 0, 1, 0, 7, 147, 8, 1, 65, 5, 1, 66, 1, 4, 0, 8, 112, 111, 108, 108, 97, 98, 108, 101, 3, 1, 3, 1, 18, 119, 97, 115, 105, 58, 105, 111, 47, 112, 111, 108, 108, 64, 48, 46, 50, 46, 48, 5, 0, 2, 3, 0, 0, 8, 112, 111, 108, 108, 97, 98, 108, 101, 1, 66, 41, 2, 3, 2, 1, 1, 4, 0, 8, 112, 111, 108, 108, 97, 98, 108, 101, 3, 0, 0, 1, 122, 4, 0, 10, 110, 111, 100, 101, 45, 105, 110, 100, 101, 120, 3, 0, 2, 1, 114, 1, 5, 118, 97, 108, 117, 101, 115, 4, 0, 3, 117, 114, 105, 3, 0, 4, 1, 112, 3, 1, 107, 3, 1, 111, 2, 121, 7, 1, 112, 127, 1, 106, 1, 7, 1, 7, 1, 111, 2, 5, 119, 1, 113, 22, 12, 114, 101, 99, 111, 114, 100, 45, 118, 97, 108, 117, 101, 1, 6, 0, 13, 118, 97, 114, 105, 97, 110, 116, 45, 118, 97, 108, 117, 101, 1, 8, 0, 10, 101, 110, 117, 109, 45, 118, 97, 108, 117, 101, 1, 121, 0, 11, 102, 108, 97, 103, 115, 45, 118, 97, 108, 117, 101, 1, 9, 0, 11, 116, 117, 112, 108, 101, 45, 118, 97, 108, 117, 101, 1, 6, 0, 10, 108, 105, 115, 116, 45, 118, 97, 108, 117, 101, 1, 6, 0, 12, 111, 112, 116, 105, 111, 110, 45, 118, 97, 108, 117, 101, 1, 7, 0, 12, 114, 101, 115, 117, 108, 116, 45, 118, 97, 108, 117, 101, 1, 10, 0, 7, 112, 114, 105, 109, 45, 117, 56, 1, 125, 0, 8, 112, 114, 105, 109, 45, 117, 49, 54, 1, 123, 0, 8, 112, 114, 105, 109, 45, 117, 51, 50, 1, 121, 0, 8, 112, 114, 105, 109, 45, 117, 54, 52, 1, 119, 0, 7, 112, 114, 105, 109, 45, 115, 56, 1, 126, 0, 8, 112, 114, 105, 109, 45, 115, 49, 54, 1, 124, 0, 8, 112, 114, 105, 109, 45, 115, 51, 50, 1, 122, 0, 8, 112, 114, 105, 109, 45, 115, 54, 52, 1, 120, 0, 12, 112, 114, 105, 109, 45, 102, 108, 111, 97, 116, 51, 50, 1, 118, 0, 12, 112, 114, 105, 109, 45, 102, 108, 111, 97, 116, 54, 52, 1, 117, 0, 9, 112, 114, 105, 109, 45, 99, 104, 97, 114, 1, 116, 0, 9, 112, 114, 105, 109, 45, 98, 111, 111, 108, 1, 127, 0, 11, 112, 114, 105, 109, 45, 115, 116, 114, 105, 110, 103, 1, 115, 0, 6, 104, 97, 110, 100, 108, 101, 1, 11, 0, 4, 0, 8, 119, 105, 116, 45, 110, 111, 100, 101, 3, 0, 12, 1, 112, 13, 1, 114, 1, 5, 110, 111, 100, 101, 115, 14, 4, 0, 9, 119, 105, 116, 45, 118, 97, 108, 117, 101, 3, 0, 15, 1, 113, 4, 14, 112, 114, 111, 116, 111, 99, 111, 108, 45, 101, 114, 114, 111, 114, 1, 115, 0, 6, 100, 101, 110, 105, 101, 100, 1, 115, 0, 9, 110, 111, 116, 45, 102, 111, 117, 110, 100, 1, 115, 0, 21, 114, 101, 109, 111, 116, 101, 45, 105, 110, 116, 101, 114, 110, 97, 108, 45, 101, 114, 114, 111, 114, 1, 115, 0, 4, 0, 9, 114, 112, 99, 45, 101, 114, 114, 111, 114, 3, 0, 17, 4, 0, 8, 119, 97, 115, 109, 45, 114, 112, 99, 3, 1, 4, 0, 20, 102, 117, 116, 117, 114, 101, 45, 105, 110, 118, 111, 107, 101, 45, 114, 101, 115, 117, 108, 116, 3, 1, 1, 105, 19, 1, 64, 1, 8, 108, 111, 99, 97, 116, 105, 111, 110, 5, 0, 21, 4, 0, 21, 91, 99, 111, 110, 115, 116, 114, 117, 99, 116, 111, 114, 93, 119, 97, 115, 109, 45, 114, 112, 99, 1, 22, 1, 104, 19, 1, 112, 16, 1, 106, 1, 16, 1, 18, 1, 64, 3, 4, 115, 101, 108, 102, 23, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 24, 0, 25, 4, 0, 33, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 105, 110, 118, 111, 107, 101, 45, 97, 110, 100, 45, 97, 119, 97, 105, 116, 1, 26, 1, 106, 0, 1, 18, 1, 64, 3, 4, 115, 101, 108, 102, 23, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 24, 0, 27, 4, 0, 23, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 105, 110, 118, 111, 107, 101, 1, 28, 1, 105, 20, 1, 64, 3, 4, 115, 101, 108, 102, 23, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 24, 0, 29, 4, 0, 39, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 97, 115, 121, 110, 99, 45, 105, 110, 118, 111, 107, 101, 45, 97, 110, 100, 45, 97, 119, 97, 105, 116, 1, 30, 1, 104, 20, 1, 105, 1, 1, 64, 1, 4, 115, 101, 108, 102, 31, 0, 32, 4, 0, 38, 91, 109, 101, 116, 104, 111, 100, 93, 102, 117, 116, 117, 114, 101, 45, 105, 110, 118, 111, 107, 101, 45, 114, 101, 115, 117, 108, 116, 46, 115, 117, 98, 115, 99, 114, 105, 98, 101, 1, 33, 1, 64, 1, 4, 115, 101, 108, 102, 31, 0, 25, 4, 0, 32, 91, 109, 101, 116, 104, 111, 100, 93, 102, 117, 116, 117, 114, 101, 45, 105, 110, 118, 111, 107, 101, 45, 114, 101, 115, 117, 108, 116, 46, 103, 101, 116, 1, 34, 4, 1, 21, 103, 111, 108, 101, 109, 58, 114, 112, 99, 47, 116, 121, 112, 101, 115, 64, 48, 46, 49, 46, 48, 5, 2, 11, 11, 1, 0, 5, 116, 121, 112, 101, 115, 3, 0, 0, 7, 155, 9, 1, 65, 2, 1, 65, 5, 1, 66, 10, 4, 0, 8, 112, 111, 108, 108, 97, 98, 108, 101, 3, 1, 1, 104, 0, 1, 64, 1, 4, 115, 101, 108, 102, 1, 0, 127, 4, 0, 22, 91, 109, 101, 116, 104, 111, 100, 93, 112, 111, 108, 108, 97, 98, 108, 101, 46, 114, 101, 97, 100, 121, 1, 2, 1, 64, 1, 4, 115, 101, 108, 102, 1, 1, 0, 4, 0, 22, 91, 109, 101, 116, 104, 111, 100, 93, 112, 111, 108, 108, 97, 98, 108, 101, 46, 98, 108, 111, 99, 107, 1, 3, 1, 112, 1, 1, 112, 121, 1, 64, 1, 2, 105, 110, 4, 0, 5, 4, 0, 4, 112, 111, 108, 108, 1, 6, 3, 1, 18, 119, 97, 115, 105, 58, 105, 111, 47, 112, 111, 108, 108, 64, 48, 46, 50, 46, 48, 5, 0, 2, 3, 0, 0, 8, 112, 111, 108, 108, 97, 98, 108, 101, 1, 66, 41, 2, 3, 2, 1, 1, 4, 0, 8, 112, 111, 108, 108, 97, 98, 108, 101, 3, 0, 0, 1, 122, 4, 0, 10, 110, 111, 100, 101, 45, 105, 110, 100, 101, 120, 3, 0, 2, 1, 114, 1, 5, 118, 97, 108, 117, 101, 115, 4, 0, 3, 117, 114, 105, 3, 0, 4, 1, 112, 3, 1, 107, 3, 1, 111, 2, 121, 7, 1, 112, 127, 1, 106, 1, 7, 1, 7, 1, 111, 2, 5, 119, 1, 113, 22, 12, 114, 101, 99, 111, 114, 100, 45, 118, 97, 108, 117, 101, 1, 6, 0, 13, 118, 97, 114, 105, 97, 110, 116, 45, 118, 97, 108, 117, 101, 1, 8, 0, 10, 101, 110, 117, 109, 45, 118, 97, 108, 117, 101, 1, 121, 0, 11, 102, 108, 97, 103, 115, 45, 118, 97, 108, 117, 101, 1, 9, 0, 11, 116, 117, 112, 108, 101, 45, 118, 97, 108, 117, 101, 1, 6, 0, 10, 108, 105, 115, 116, 45, 118, 97, 108, 117, 101, 1, 6, 0, 12, 111, 112, 116, 105, 111, 110, 45, 118, 97, 108, 117, 101, 1, 7, 0, 12, 114, 101, 115, 117, 108, 116, 45, 118, 97, 108, 117, 101, 1, 10, 0, 7, 112, 114, 105, 109, 45, 117, 56, 1, 125, 0, 8, 112, 114, 105, 109, 45, 117, 49, 54, 1, 123, 0, 8, 112, 114, 105, 109, 45, 117, 51, 50, 1, 121, 0, 8, 112, 114, 105, 109, 45, 117, 54, 52, 1, 119, 0, 7, 112, 114, 105, 109, 45, 115, 56, 1, 126, 0, 8, 112, 114, 105, 109, 45, 115, 49, 54, 1, 124, 0, 8, 112, 114, 105, 109, 45, 115, 51, 50, 1, 122, 0, 8, 112, 114, 105, 109, 45, 115, 54, 52, 1, 120, 0, 12, 112, 114, 105, 109, 45, 102, 108, 111, 97, 116, 51, 50, 1, 118, 0, 12, 112, 114, 105, 109, 45, 102, 108, 111, 97, 116, 54, 52, 1, 117, 0, 9, 112, 114, 105, 109, 45, 99, 104, 97, 114, 1, 116, 0, 9, 112, 114, 105, 109, 45, 98, 111, 111, 108, 1, 127, 0, 11, 112, 114, 105, 109, 45, 115, 116, 114, 105, 110, 103, 1, 115, 0, 6, 104, 97, 110, 100, 108, 101, 1, 11, 0, 4, 0, 8, 119, 105, 116, 45, 110, 111, 100, 101, 3, 0, 12, 1, 112, 13, 1, 114, 1, 5, 110, 111, 100, 101, 115, 14, 4, 0, 9, 119, 105, 116, 45, 118, 97, 108, 117, 101, 3, 0, 15, 1, 113, 4, 14, 112, 114, 111, 116, 111, 99, 111, 108, 45, 101, 114, 114, 111, 114, 1, 115, 0, 6, 100, 101, 110, 105, 101, 100, 1, 115, 0, 9, 110, 111, 116, 45, 102, 111, 117, 110, 100, 1, 115, 0, 21, 114, 101, 109, 111, 116, 101, 45, 105, 110, 116, 101, 114, 110, 97, 108, 45, 101, 114, 114, 111, 114, 1, 115, 0, 4, 0, 9, 114, 112, 99, 45, 101, 114, 114, 111, 114, 3, 0, 17, 4, 0, 8, 119, 97, 115, 109, 45, 114, 112, 99, 3, 1, 4, 0, 20, 102, 117, 116, 117, 114, 101, 45, 105, 110, 118, 111, 107, 101, 45, 114, 101, 115, 117, 108, 116, 3, 1, 1, 105, 19, 1, 64, 1, 8, 108, 111, 99, 97, 116, 105, 111, 110, 5, 0, 21, 4, 0, 21, 91, 99, 111, 110, 115, 116, 114, 117, 99, 116, 111, 114, 93, 119, 97, 115, 109, 45, 114, 112, 99, 1, 22, 1, 104, 19, 1, 112, 16, 1, 106, 1, 16, 1, 18, 1, 64, 3, 4, 115, 101, 108, 102, 23, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 24, 0, 25, 4, 0, 33, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 105, 110, 118, 111, 107, 101, 45, 97, 110, 100, 45, 97, 119, 97, 105, 116, 1, 26, 1, 106, 0, 1, 18, 1, 64, 3, 4, 115, 101, 108, 102, 23, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 24, 0, 27, 4, 0, 23, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 105, 110, 118, 111, 107, 101, 1, 28, 1, 105, 20, 1, 64, 3, 4, 115, 101, 108, 102, 23, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 24, 0, 29, 4, 0, 39, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 97, 115, 121, 110, 99, 45, 105, 110, 118, 111, 107, 101, 45, 97, 110, 100, 45, 97, 119, 97, 105, 116, 1, 30, 1, 104, 20, 1, 105, 1, 1, 64, 1, 4, 115, 101, 108, 102, 31, 0, 32, 4, 0, 38, 91, 109, 101, 116, 104, 111, 100, 93, 102, 117, 116, 117, 114, 101, 45, 105, 110, 118, 111, 107, 101, 45, 114, 101, 115, 117, 108, 116, 46, 115, 117, 98, 115, 99, 114, 105, 98, 101, 1, 33, 1, 64, 1, 4, 115, 101, 108, 102, 31, 0, 25, 4, 0, 32, 91, 109, 101, 116, 104, 111, 100, 93, 102, 117, 116, 117, 114, 101, 45, 105, 110, 118, 111, 107, 101, 45, 114, 101, 115, 117, 108, 116, 46, 103, 101, 116, 1, 34, 3, 1, 21, 103, 111, 108, 101, 109, 58, 114, 112, 99, 47, 116, 121, 112, 101, 115, 64, 48, 46, 49, 46, 48, 5, 2, 4, 1, 25, 103, 111, 108, 101, 109, 58, 114, 112, 99, 47, 119, 105, 116, 45, 118, 97, 108, 117, 101, 64, 48, 46, 49, 46, 48, 4, 0, 11, 15, 1, 0, 9, 119, 105, 116, 45, 118, 97, 108, 117, 101, 3, 2, 0, 0, 16, 12, 112, 97, 99, 107, 97, 103, 101, 45, 100, 111, 99, 115, 0, 123, 125, 0, 70, 9, 112, 114, 111, 100, 117, 99, 101, 114, 115, 1, 12, 112, 114, 111, 99, 101, 115, 115, 101, 100, 45, 98, 121, 2, 13, 119, 105, 116, 45, 99, 111, 109, 112, 111, 110, 101, 110, 116, 6, 48, 46, 49, 56, 46, 50, 16, 119, 105, 116, 45, 98, 105, 110, 100, 103, 101, 110, 45, 114, 117, 115, 116, 6, 48, 46, 49, 54, 46, 48]; + + #[inline(never)] + #[doc(hidden)] + #[cfg(target_arch = "wasm32")] + pub fn __link_section() {} + \ No newline at end of file diff --git a/wasm-rpc/src/lib.rs b/wasm-rpc/src/lib.rs index 4d6c4bbc..c30243b0 100644 --- a/wasm-rpc/src/lib.rs +++ b/wasm-rpc/src/lib.rs @@ -54,7 +54,10 @@ pub use extractor::{WitNodePointer, WitValueExtractor}; #[cfg(not(feature = "host"))] #[cfg(feature = "stub")] -pub use bindings::golem::rpc::types::{NodeIndex, RpcError, Uri, WasmRpc, WitNode, WitValue}; +pub use bindings::golem::rpc::types::{FutureInvokeResult, NodeIndex, RpcError, Uri, WasmRpc, WitNode, WitValue}; +#[cfg(not(feature = "host"))] +#[cfg(feature = "stub")] +pub use bindings::wasi::io::poll::Pollable; #[cfg(feature = "host")] use ::wasmtime::component::bindgen; @@ -321,6 +324,8 @@ impl<'a> arbitrary::Arbitrary<'a> for WitValue { #[cfg(feature = "host")] pub const WASM_RPC_WIT: &str = include_str!("../wit/wasm-rpc.wit"); +#[cfg(feature = "host")] +pub const WASI_POLL_WIT: &str = include_str!("../wit/deps/io/poll.wit"); pub const WASM_RPC_VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/wasm-rpc/wit/deps/io/poll.wit b/wasm-rpc/wit/deps/io/poll.wit new file mode 100644 index 00000000..82fa0f31 --- /dev/null +++ b/wasm-rpc/wit/deps/io/poll.wit @@ -0,0 +1,41 @@ +package wasi:io@0.2.0; + +/// A poll API intended to let users wait for I/O events on multiple handles +/// at once. +interface poll { + /// `pollable` epresents a single I/O event which may be ready, or not. + resource pollable { + + /// Return the readiness of a pollable. This function never blocks. + /// + /// Returns `true` when the pollable is ready, and `false` otherwise. + ready: func() -> bool; + + /// `block` returns immediately if the pollable is ready, and otherwise + /// blocks until ready. + /// + /// This function is equivalent to calling `poll.poll` on a list + /// containing only this pollable. + block: func(); + } + + /// Poll for completion on a set of pollables. + /// + /// This function takes a list of pollables, which identify I/O sources of + /// interest, and waits until one or more of the events is ready for I/O. + /// + /// The result `list` contains one or more indices of handles in the + /// argument list that is ready for I/O. + /// + /// If the list contains more elements than can be indexed with a `u32` + /// value, this function traps. + /// + /// A timeout can be implemented by adding a pollable from the + /// wasi-clocks API to the list. + /// + /// This function does not return a `result`; polling in itself does not + /// do any I/O so it doesn't fail. If any of the I/O sources identified by + /// the pollables has an error, it is indicated by marking the source as + /// being reaedy for I/O. + poll: func(in: list>) -> list; +} diff --git a/wasm-rpc/wit/wasm-rpc.wit b/wasm-rpc/wit/wasm-rpc.wit index 8e31847b..a21fb0e1 100644 --- a/wasm-rpc/wit/wasm-rpc.wit +++ b/wasm-rpc/wit/wasm-rpc.wit @@ -1,6 +1,8 @@ package golem:rpc@0.1.0; interface types { + use wasi:io/poll@0.2.0.{pollable}; + type node-index = s32; record wit-value { @@ -48,6 +50,13 @@ interface types { invoke-and-await: func(function-name: string, function-params: list) -> result; invoke: func(function-name: string, function-params: list) -> result<_, rpc-error>; + + async-invoke-and-await: func(function-name: string, function-params: list) -> future-invoke-result; + } + + resource future-invoke-result { + subscribe: func() -> pollable; + get: func() -> result; } } From 89c1f51374fb0e87b5bdbd4f44f7d0d03cc4a12f Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Fri, 14 Jun 2024 10:56:47 +0200 Subject: [PATCH 2/7] Format --- wasm-rpc-stubgen/src/lib.rs | 1 - wasm-rpc/src/lib.rs | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/wasm-rpc-stubgen/src/lib.rs b/wasm-rpc-stubgen/src/lib.rs index e02209be..9cd4b83c 100644 --- a/wasm-rpc-stubgen/src/lib.rs +++ b/wasm-rpc-stubgen/src/lib.rs @@ -79,7 +79,6 @@ pub struct GenerateArgs { /// the latest version of `wasm-rpc` will be used. #[clap(long)] pub wasm_rpc_path_override: Option, - } /// Build an RPC stub for a WASM component diff --git a/wasm-rpc/src/lib.rs b/wasm-rpc/src/lib.rs index c30243b0..974116d0 100644 --- a/wasm-rpc/src/lib.rs +++ b/wasm-rpc/src/lib.rs @@ -54,7 +54,9 @@ pub use extractor::{WitNodePointer, WitValueExtractor}; #[cfg(not(feature = "host"))] #[cfg(feature = "stub")] -pub use bindings::golem::rpc::types::{FutureInvokeResult, NodeIndex, RpcError, Uri, WasmRpc, WitNode, WitValue}; +pub use bindings::golem::rpc::types::{ + FutureInvokeResult, NodeIndex, RpcError, Uri, WasmRpc, WitNode, WitValue, +}; #[cfg(not(feature = "host"))] #[cfg(feature = "stub")] pub use bindings::wasi::io::poll::Pollable; From f3c16522f380e1a6637a0d4de457158d9b9cd8d3 Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Fri, 14 Jun 2024 15:23:40 +0200 Subject: [PATCH 3/7] Fixes --- Cargo.lock | 340 +++++++++++++++++++++++++++++++++++++- wasm-rpc/Cargo.toml | 6 +- wasm-rpc/src/lib.rs | 29 +++- wasm-rpc/wit/wasm-rpc.wit | 2 +- 4 files changed, 367 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3ab169ee..01d485e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,6 +50,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "ambient-authority" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9d4ee0d472d1cd2e28c97dfa124b3d8d992e10eb0a035f33f5d12e3a177ba3b" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -290,9 +296,9 @@ checksum = "fbb36e985947064623dbd357f727af08ffd077f93d696782f3c56365fa2e2799" [[package]] name = "async-trait" -version = "0.1.77" +version = "0.1.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", @@ -501,6 +507,83 @@ dependencies = [ "serde", ] +[[package]] +name = "cap-fs-ext" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88e341d15ac1029aadce600be764a1a1edafe40e03cde23285bc1d261b3a4866" +dependencies = [ + "cap-primitives", + "cap-std", + "io-lifetimes 2.0.3", + "windows-sys 0.52.0", +] + +[[package]] +name = "cap-net-ext" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "434168fe6533055f0f4204039abe3ff6d7db338ef46872a5fa39e9d5ad5ab7a9" +dependencies = [ + "cap-primitives", + "cap-std", + "rustix 0.38.31", + "smallvec", +] + +[[package]] +name = "cap-primitives" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe16767ed8eee6d3f1f00d6a7576b81c226ab917eb54b96e5f77a5216ef67abb" +dependencies = [ + "ambient-authority", + "fs-set-times", + "io-extras", + "io-lifetimes 2.0.3", + "ipnet", + "maybe-owned", + "rustix 0.38.31", + "windows-sys 0.52.0", + "winx", +] + +[[package]] +name = "cap-rand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20e5695565f0cd7106bc3c7170323597540e772bb73e0be2cd2c662a0f8fa4ca" +dependencies = [ + "ambient-authority", + "rand 0.8.5", +] + +[[package]] +name = "cap-std" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "593db20e4c51f62d3284bae7ee718849c3214f93a3b94ea1899ad85ba119d330" +dependencies = [ + "cap-primitives", + "io-extras", + "io-lifetimes 2.0.3", + "rustix 0.38.31", +] + +[[package]] +name = "cap-time-ext" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03261630f291f425430a36f38c847828265bc928f517cdd2004c56f4b02f002b" +dependencies = [ + "ambient-authority", + "cap-primitives", + "iana-time-zone", + "once_cell", + "rustix 0.38.31", + "winx", +] + [[package]] name = "cargo-component" version = "0.7.0" @@ -1030,13 +1113,33 @@ dependencies = [ "dirs-sys-next", ] +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys 0.3.7", +] + [[package]] name = "dirs" version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" dependencies = [ - "dirs-sys", + "dirs-sys 0.4.1", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", ] [[package]] @@ -1241,6 +1344,17 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +[[package]] +name = "fd-lock" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e5768da2206272c81ef0b5e951a41862938a6070da63bcea197899942d3b947" +dependencies = [ + "cfg-if", + "rustix 0.38.31", + "windows-sys 0.52.0", +] + [[package]] name = "ff" version = "0.13.0" @@ -1287,6 +1401,17 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs-set-times" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "033b337d725b97690d86893f9de22b67b80dcc4e9ad815f348254c38119db8fb" +dependencies = [ + "io-lifetimes 2.0.3", + "rustix 0.38.31", + "windows-sys 0.52.0", +] + [[package]] name = "fs_extra" version = "1.3.0" @@ -1490,6 +1615,7 @@ name = "golem-wasm-rpc" version = "0.0.0" dependencies = [ "arbitrary", + "async-trait", "bigdecimal", "bincode 2.0.0-rc.3", "golem-wasm-ast", @@ -1501,6 +1627,7 @@ dependencies = [ "serde_json", "wasm-wave", "wasmtime", + "wasmtime-wasi", "wit-bindgen", ] @@ -1804,6 +1931,16 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "io-extras" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9f046b9af244f13b3bd939f55d16830ac3a201e8a9ba9661bfcb03e2be72b9b" +dependencies = [ + "io-lifetimes 2.0.3", + "windows-sys 0.52.0", +] + [[package]] name = "io-lifetimes" version = "1.0.11" @@ -1815,6 +1952,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "io-lifetimes" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a611371471e98973dbcab4e0ec66c31a10bc356eeb4d54a0e05eac8158fe38c" + [[package]] name = "ipnet" version = "2.9.0" @@ -2028,6 +2171,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "204651f31b0a6a7b2128d2b92c372cd94607b210c3a6b6e542c57a8cfd4db996" +[[package]] +name = "maybe-owned" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4facc753ae494aeb6e3c22f839b158aebd4f9270f55cd3c79906c45476c47ab4" + [[package]] name = "memchr" version = "2.7.1" @@ -3074,7 +3223,7 @@ checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" dependencies = [ "bitflags 1.3.2", "errno", - "io-lifetimes", + "io-lifetimes 1.0.11", "libc", "linux-raw-sys 0.3.8", "windows-sys 0.48.0", @@ -3088,8 +3237,10 @@ checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" dependencies = [ "bitflags 2.4.2", "errno", + "itoa", "libc", "linux-raw-sys 0.4.13", + "once_cell", "windows-sys 0.52.0", ] @@ -3346,6 +3497,15 @@ dependencies = [ "digest", ] +[[package]] +name = "shellexpand" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" +dependencies = [ + "dirs 4.0.0", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -3520,6 +3680,22 @@ dependencies = [ "libc", ] +[[package]] +name = "system-interface" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0682e006dd35771e392a6623ac180999a9a854b1d4a6c12fb2e804941c2b1f58" +dependencies = [ + "bitflags 2.4.2", + "cap-fs-ext", + "cap-std", + "fd-lock", + "io-lifetimes 2.0.3", + "rustix 0.38.31", + "windows-sys 0.52.0", + "winx", +] + [[package]] name = "target-lexicon" version = "0.12.13" @@ -3756,6 +3932,7 @@ version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ + "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -3955,7 +4132,7 @@ dependencies = [ "async-trait", "bytes", "clap", - "dirs", + "dirs 5.0.1", "futures-util", "itertools 0.11.0", "libc", @@ -4061,6 +4238,49 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasi-cap-std-sync" +version = "17.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db014d2ced91f17d1f1a8f2b76d6ea8d731bc1dbc8c2bbaec689d6a242568e5d" +dependencies = [ + "anyhow", + "async-trait", + "cap-fs-ext", + "cap-rand", + "cap-std", + "cap-time-ext", + "fs-set-times", + "io-extras", + "io-lifetimes 2.0.3", + "once_cell", + "rustix 0.38.31", + "system-interface", + "tracing", + "wasi-common", + "windows-sys 0.52.0", +] + +[[package]] +name = "wasi-common" +version = "17.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "449d17849e3c83a931374442fe2deee4d6bd1ebf469719ef44192e9e82e19c89" +dependencies = [ + "anyhow", + "bitflags 2.4.2", + "cap-rand", + "cap-std", + "io-extras", + "log", + "rustix 0.38.31", + "thiserror", + "tracing", + "wasmtime", + "wiggle", + "windows-sys 0.52.0", +] + [[package]] name = "wasm-bindgen" version = "0.2.91" @@ -4542,6 +4762,41 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "wasmtime-wasi" +version = "17.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "902cc299b73655c36679b77efdfce4bb5971992f1a4a8a436dd3809a6848ff0e" +dependencies = [ + "anyhow", + "async-trait", + "bitflags 2.4.2", + "bytes", + "cap-fs-ext", + "cap-net-ext", + "cap-rand", + "cap-std", + "cap-time-ext", + "fs-set-times", + "futures", + "io-extras", + "io-lifetimes 2.0.3", + "libc", + "log", + "once_cell", + "rustix 0.38.31", + "system-interface", + "thiserror", + "tokio", + "tracing", + "url", + "wasi-cap-std-sync", + "wasi-common", + "wasmtime", + "wiggle", + "windows-sys 0.52.0", +] + [[package]] name = "wasmtime-winch" version = "17.0.0" @@ -4577,6 +4832,15 @@ version = "17.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b20a19e10d8cb50b45412fb21192982b7ce85c0122dc33bb71f1813e25dc6e52" +[[package]] +name = "wast" +version = "35.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ef140f1b49946586078353a453a1d28ba90adfc54dde75710bc1931de204d68" +dependencies = [ + "leb128", +] + [[package]] name = "wast" version = "201.0.0" @@ -4596,7 +4860,7 @@ version = "1.201.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "453d5b37a45b98dee4f4cb68015fc73634d7883bbef1c65e6e9c78d454cf3f32" dependencies = [ - "wast", + "wast 201.0.0", ] [[package]] @@ -4634,6 +4898,48 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "wiggle" +version = "17.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "737728db69a7657a5f6a7bac445c02d8564d603d62c46c95edf928554e67d072" +dependencies = [ + "anyhow", + "async-trait", + "bitflags 2.4.2", + "thiserror", + "tracing", + "wasmtime", + "wiggle-macro", +] + +[[package]] +name = "wiggle-generate" +version = "17.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2460c7163b79ffefd9a564eaeab0a5b0e84bb91afdfeeb84d36f304ddbe08982" +dependencies = [ + "anyhow", + "heck", + "proc-macro2", + "quote", + "shellexpand", + "syn 2.0.48", + "witx", +] + +[[package]] +name = "wiggle-macro" +version = "17.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa8d8412375ba8325d61fbae56dead51dabfaec85d620ce36427922fb9cece83" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", + "wiggle-generate", +] + [[package]] name = "winapi" version = "0.3.9" @@ -4850,6 +5156,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "winx" +version = "0.36.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9643b83820c0cd246ecabe5fa454dd04ba4fa67996369466d0747472d337346" +dependencies = [ + "bitflags 2.4.2", + "windows-sys 0.52.0", +] + [[package]] name = "wit-bindgen" version = "0.17.0" @@ -4980,6 +5296,18 @@ dependencies = [ "wasmparser 0.201.0", ] +[[package]] +name = "witx" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e366f27a5cabcddb2706a78296a40b8fcc451e1a6aba2fc1d94b4a01bdaaef4b" +dependencies = [ + "anyhow", + "log", + "thiserror", + "wast 35.0.2", +] + [[package]] name = "xdg-home" version = "1.1.0" diff --git a/wasm-rpc/Cargo.toml b/wasm-rpc/Cargo.toml index 0ba457ba..d11ebb4d 100644 --- a/wasm-rpc/Cargo.toml +++ b/wasm-rpc/Cargo.toml @@ -17,6 +17,7 @@ crate-type = ["cdylib", "rlib"] wit-bindgen = { version = "0.17.0", default-features = false, features = ["realloc"] } arbitrary = { version = "1.3.2", features = ["derive"], optional = true } +async-trait = { version = "0.1.77", optional = true } bigdecimal = { version = "0.4.2", optional = true } bincode = { version = "2.0.0-rc.3", optional = true } golem-wasm-ast = { version = "0.2.2", features = ["analysis", "wave"], optional = true } @@ -24,6 +25,7 @@ serde = { version = "1.0.113", optional = true } serde_json = { version = "1.0.113", optional = true } prost = { version = "0.12.3", optional = true } wasmtime = { version = "=17.0.0", features = ["component-model"], optional = true } +wasmtime-wasi = { version = "=17.0.0", features = ["preview2"], optional = true } wasm-wave = { version = "=0.4.0", optional = true } [dev-dependencies] @@ -35,7 +37,7 @@ prost-build = "0.12.3" [features] default = ["host"] -host = ["arbitrary", "bincode", "json", "protobuf", "serde", "text", "typeinfo", "wasmtime"] +host = ["dep:async-trait", "arbitrary", "bincode", "json", "protobuf", "serde", "text", "typeinfo", "wasmtime"] arbitrary = ["dep:arbitrary"] bincode = ["dep:bincode"] json = ["dep:serde", "dep:serde_json", "dep:bigdecimal", "typeinfo"] @@ -44,7 +46,7 @@ serde = ["dep:serde"] stub = [] text = ["wasmtime", "dep:wasm-wave"] typeinfo = ["dep:golem-wasm-ast"] -wasmtime = ["dep:wasmtime", "typeinfo"] +wasmtime = ["dep:wasmtime", "dep:wasmtime-wasi", "typeinfo"] [package.metadata.component] diff --git a/wasm-rpc/src/lib.rs b/wasm-rpc/src/lib.rs index 974116d0..6c1bece1 100644 --- a/wasm-rpc/src/lib.rs +++ b/wasm-rpc/src/lib.rs @@ -48,6 +48,7 @@ mod type_annotated_value; #[cfg(feature = "wasmtime")] pub mod wasmtime; +use std::any::Any; use crate::builder::WitValueBuilder; pub use builder::{NodeBuilder, WitValueBuilderExtensions}; pub use extractor::{WitNodePointer, WitValueExtractor}; @@ -64,6 +65,9 @@ pub use bindings::wasi::io::poll::Pollable; #[cfg(feature = "host")] use ::wasmtime::component::bindgen; +#[cfg(feature = "host")] +pub use wasmtime_wasi::preview2::Pollable; + #[cfg(feature = "host")] bindgen!({ path: "wit", @@ -73,7 +77,9 @@ bindgen!({ tracing: false, async: true, with: { - "golem:rpc/types/wasm-rpc": WasmRpcEntry + "golem:rpc/types/wasm-rpc": WasmRpcEntry, + "golem:rpc/types/future-invoke-result": FutureInvokeResultEntry, + "wasi:io/poll/pollable": Pollable, } }); @@ -85,6 +91,27 @@ pub struct WasmRpcEntry { pub payload: Box, } +#[cfg(feature = "host")] +#[async_trait::async_trait] +pub trait SubscribeAny: std::any::Any { + async fn ready(&mut self); + fn as_any(&self) -> &dyn Any; + fn as_any_mut(&mut self) -> &mut dyn Any; +} + +#[cfg(feature = "host")] +pub struct FutureInvokeResultEntry { + pub payload: Box, +} + +#[cfg(feature = "host")] +#[async_trait::async_trait] +impl wasmtime_wasi::preview2::Subscribe for FutureInvokeResultEntry { + async fn ready(&mut self) { + self.payload.ready().await + } +} + #[cfg(feature = "typeinfo")] pub use type_annotated_value::*; diff --git a/wasm-rpc/wit/wasm-rpc.wit b/wasm-rpc/wit/wasm-rpc.wit index a21fb0e1..69e1c8d4 100644 --- a/wasm-rpc/wit/wasm-rpc.wit +++ b/wasm-rpc/wit/wasm-rpc.wit @@ -56,7 +56,7 @@ interface types { resource future-invoke-result { subscribe: func() -> pollable; - get: func() -> result; + get: func() -> option>; } } From 28c2a5d3f0a8a57fd795f16444a947ea4d86e56d Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Mon, 17 Jun 2024 15:25:52 +0200 Subject: [PATCH 4/7] Fix naming collision --- wasm-rpc-stubgen/src/rust.rs | 42 ++++++++++++++++-------------------- wasm-rpc-stubgen/src/stub.rs | 8 +++++++ wasm-rpc-stubgen/src/wit.rs | 22 ++++++++++--------- wasm-rpc/src/lib.rs | 5 ++--- wasm-rpc/src/wasmtime.rs | 18 +++++++++++++--- 5 files changed, 55 insertions(+), 40 deletions(-) diff --git a/wasm-rpc-stubgen/src/rust.rs b/wasm-rpc-stubgen/src/rust.rs index dcca641b..82aa600e 100644 --- a/wasm-rpc-stubgen/src/rust.rs +++ b/wasm-rpc-stubgen/src/rust.rs @@ -74,7 +74,7 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> { for function in &interface.functions { if !function.results.is_empty() { - let result_wrapper = result_wrapper_ident(function); + let result_wrapper = result_wrapper_ident(function, interface); struct_defs.push(quote! { pub struct #result_wrapper { pub future_invoke_result: FutureInvokeResult @@ -84,7 +84,7 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> { } for function in &interface.static_functions { if !function.results.is_empty() { - let result_wrapper = result_wrapper_ident(function); + let result_wrapper = result_wrapper_ident(function, interface); struct_defs.push(quote! { pub struct #result_wrapper { pub future_invoke_result: FutureInvokeResult @@ -115,16 +115,12 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> { FunctionMode::Global }; fn_impls.push(generate_function_stub_source( - def, - function, - interface.interface_name(), - interface.resource_name(), - mode, + def, function, interface, mode, )?); if !function.results.is_empty() { - let result_wrapper = result_wrapper_ident(function); - let result_wrapper_interface = result_wrapper_interface_ident(function); + let result_wrapper = result_wrapper_ident(function, interface); + let result_wrapper_interface = result_wrapper_interface_ident(function, interface); let subscribe = quote! { fn subscribe(&self) -> bindings::wasi::io::poll::Pollable { @@ -154,14 +150,13 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> { fn_impls.push(generate_function_stub_source( def, function, - interface.interface_name(), - interface.resource_name(), + interface, FunctionMode::Static, )?); if !function.results.is_empty() { - let result_wrapper = result_wrapper_ident(function); - let result_wrapper_interface = result_wrapper_interface_ident(function); + let result_wrapper = result_wrapper_ident(function, interface); + let result_wrapper_interface = result_wrapper_interface_ident(function, interface); let subscribe = quote! { fn subscribe(&self) -> bindings::wasi::io::poll::Pollable { @@ -201,8 +196,7 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> { generate_function_stub_source( def, &constructor_stub, - interface.interface_name(), - interface.resource_name(), + interface, FunctionMode::Constructor, )? } else { @@ -279,16 +273,17 @@ enum FunctionMode { Constructor, } -fn result_wrapper_ident(function: &FunctionStub) -> Ident { +fn result_wrapper_ident(function: &FunctionStub, owner: &InterfaceStub) -> Ident { Ident::new( - &to_rust_ident(&format!("future-{}-result", function.name)).to_upper_camel_case(), + &to_rust_ident(&function.async_result_type(owner)).to_upper_camel_case(), Span::call_site(), ) } -fn result_wrapper_interface_ident(function: &FunctionStub) -> Ident { +fn result_wrapper_interface_ident(function: &FunctionStub, owner: &InterfaceStub) -> Ident { Ident::new( - &to_rust_ident(&format!("guest-future-{}-result", function.name)).to_upper_camel_case(), + &to_rust_ident(&format!("guest-{}", function.async_result_type(owner))) + .to_upper_camel_case(), Span::call_site(), ) } @@ -320,8 +315,7 @@ fn generate_result_wrapper_get_source( fn generate_function_stub_source( def: &StubDefinition, function: &FunctionStub, - interface_name: Option, - resource_name: Option, + owner: &InterfaceStub, mode: FunctionMode, ) -> anyhow::Result { let function_name = Ident::new(&to_rust_ident(&function.name), Span::call_site()); @@ -365,8 +359,8 @@ fn generate_function_stub_source( let remote_function_name = get_remote_function_name( def, &function.name, - interface_name.as_ref(), - resource_name.as_ref(), + owner.interface_name().as_ref(), + owner.resource_name().as_ref(), ); let rpc = match mode { @@ -432,7 +426,7 @@ fn generate_function_stub_source( } } } else { - let result_wrapper = result_wrapper_ident(function); + let result_wrapper = result_wrapper_ident(function, owner); quote! { fn #function_name(#(#params),*) -> wit_bindgen::rt::Resource<#result_wrapper> { #init diff --git a/wasm-rpc-stubgen/src/stub.rs b/wasm-rpc-stubgen/src/stub.rs index a19e36e8..36af5c34 100644 --- a/wasm-rpc-stubgen/src/stub.rs +++ b/wasm-rpc-stubgen/src/stub.rs @@ -227,6 +227,14 @@ impl FunctionStub { } }) } + + pub fn async_result_type(&self, owner: &InterfaceStub) -> String { + if owner.is_resource() { + format!("future-{}-{}-result", owner.name, self.name) + } else { + format!("future-{}-result", self.name) + } + } } #[derive(Debug, Clone)] diff --git a/wasm-rpc-stubgen/src/wit.rs b/wasm-rpc-stubgen/src/wit.rs index 6de72565..663cf450 100644 --- a/wasm-rpc-stubgen/src/wit.rs +++ b/wasm-rpc-stubgen/src/wit.rs @@ -13,8 +13,8 @@ // limitations under the License. use crate::stub::{ - FunctionParamStub, FunctionResultStub, FunctionStub, InterfaceStubImport, InterfaceStubTypeDef, - StubDefinition, + FunctionParamStub, FunctionResultStub, FunctionStub, InterfaceStub, InterfaceStubImport, + InterfaceStubTypeDef, StubDefinition, }; use anyhow::{anyhow, bail, Context}; use indexmap::IndexMap; @@ -96,12 +96,12 @@ pub fn get_stub_wit( for interface in &def.interfaces { for function in &interface.functions { if !function.results.is_empty() { - write_async_return_type(&mut out, function, def)?; + write_async_return_type(&mut out, function, interface, def)?; } } for function in &interface.static_functions { if !function.results.is_empty() { - write_async_return_type(&mut out, function, def)?; + write_async_return_type(&mut out, function, interface, def)?; } } } @@ -123,10 +123,10 @@ pub fn get_stub_wit( } } for function in &interface.functions { - write_function_definition(&mut out, function, false, def)?; + write_function_definition(&mut out, function, false, interface, def)?; } for function in &interface.static_functions { - write_function_definition(&mut out, function, true, def)?; + write_function_definition(&mut out, function, true, interface, def)?; } writeln!(out, " }}")?; writeln!(out)?; @@ -150,6 +150,7 @@ fn write_function_definition( out: &mut String, function: &FunctionStub, is_static: bool, + owner: &InterfaceStub, def: &StubDefinition, ) -> anyhow::Result<()> { let func = if is_static { "static_func" } else { "func" }; @@ -161,11 +162,11 @@ fn write_function_definition( write!(out, " -> ")?; write_function_result_type(out, function, def)?; writeln!(out, ";")?; - // Write the non blocking function + // Write the non-blocking function write!(out, " {}: {func}(", function.name)?; write_param_list(out, def, &function.params)?; write!(out, ")")?; - write!(out, " -> future-{}-result", function.name)?; + write!(out, " -> {}", function.async_result_type(owner))?; } else { // Write the blocking function write!(out, " blocking-{}: {func}(", function.name)?; @@ -173,7 +174,7 @@ fn write_function_definition( write!(out, ")")?; writeln!(out, ";")?; - // Write the non blocking function + // Write the non-blocking function write!(out, " {}: {func}(", function.name)?; write_param_list(out, def, &function.params)?; write!(out, ")")?; @@ -185,9 +186,10 @@ fn write_function_definition( fn write_async_return_type( out: &mut String, function: &FunctionStub, + owner: &InterfaceStub, def: &StubDefinition, ) -> anyhow::Result<()> { - writeln!(out, " resource future-{}-result {{", function.name)?; + writeln!(out, " resource {} {{", function.async_result_type(owner))?; writeln!(out, " subscribe: func() -> pollable;")?; write!(out, " get: func() -> ")?; write_function_result_type(out, function, def)?; diff --git a/wasm-rpc/src/lib.rs b/wasm-rpc/src/lib.rs index 6c1bece1..7569f15d 100644 --- a/wasm-rpc/src/lib.rs +++ b/wasm-rpc/src/lib.rs @@ -48,7 +48,6 @@ mod type_annotated_value; #[cfg(feature = "wasmtime")] pub mod wasmtime; -use std::any::Any; use crate::builder::WitValueBuilder; pub use builder::{NodeBuilder, WitValueBuilderExtensions}; pub use extractor::{WitNodePointer, WitValueExtractor}; @@ -95,8 +94,8 @@ pub struct WasmRpcEntry { #[async_trait::async_trait] pub trait SubscribeAny: std::any::Any { async fn ready(&mut self); - fn as_any(&self) -> &dyn Any; - fn as_any_mut(&mut self) -> &mut dyn Any; + fn as_any(&self) -> &dyn std::any::Any; + fn as_any_mut(&mut self) -> &mut dyn std::any::Any; } #[cfg(feature = "host")] diff --git a/wasm-rpc/src/wasmtime.rs b/wasm-rpc/src/wasmtime.rs index 0182b48b..bf30b8d2 100644 --- a/wasm-rpc/src/wasmtime.rs +++ b/wasm-rpc/src/wasmtime.rs @@ -389,7 +389,11 @@ pub fn encode_output( Ok(Value::Tuple(encoded_values)) } Val::Variant(variant) => { - let wasm_variant = unsafe { std::mem::transmute(variant.clone()) }; + let wasm_variant = unsafe { + std::mem::transmute::( + variant.clone(), + ) + }; let WasmVariant { ty: _, discriminant, @@ -404,7 +408,11 @@ pub fn encode_output( }) } Val::Enum(enum0) => { - let wasm_enum = unsafe { std::mem::transmute(enum0.clone()) }; + let wasm_enum = unsafe { + std::mem::transmute::( + enum0.clone(), + ) + }; let WasmEnum { ty: _, discriminant, @@ -433,7 +441,11 @@ pub fn encode_output( } }, Val::Flags(flags) => { - let wasm_flags = unsafe { std::mem::transmute(flags.clone()) }; + let wasm_flags = unsafe { + std::mem::transmute::( + flags.clone(), + ) + }; let WasmFlags { ty: _, count, From 7052afb63258b1578680b07a64f59f36b4dd50da Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Fri, 21 Jun 2024 10:09:30 +0200 Subject: [PATCH 5/7] Regenerated bindings.rs --- wasm-rpc/src/bindings.rs | 4537 +++++++++++++++++++++----------------- 1 file changed, 2571 insertions(+), 1966 deletions(-) diff --git a/wasm-rpc/src/bindings.rs b/wasm-rpc/src/bindings.rs index bfe84121..eccfb785 100644 --- a/wasm-rpc/src/bindings.rs +++ b/wasm-rpc/src/bindings.rs @@ -1,2080 +1,2685 @@ -// Generated by `wit-bindgen` 0.16.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.25.0. DO NOT EDIT! +// Options used: +#[allow(dead_code)] pub mod golem { - pub mod rpc { - - #[allow(clippy::all)] - pub mod types { - #[used] - #[doc(hidden)] - #[cfg(target_arch = "wasm32")] - static __FORCE_SECTION_REF: fn() = super::super::super::__link_section; - pub type Pollable = super::super::super::wasi::io::poll::Pollable; - pub type NodeIndex = i32; - #[derive(Clone)] - pub struct Uri { - pub value: wit_bindgen::rt::string::String, - } - impl ::core::fmt::Debug for Uri { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - f.debug_struct("Uri").field("value", &self.value).finish() - } - } - #[derive(Clone)] - pub enum WitNode{ - RecordValue(wit_bindgen::rt::vec::Vec::), - VariantValue((u32,Option,)), - EnumValue(u32), - FlagsValue(wit_bindgen::rt::vec::Vec::), - TupleValue(wit_bindgen::rt::vec::Vec::), - ListValue(wit_bindgen::rt::vec::Vec::), - OptionValue(Option), - ResultValue(Result,Option>), - PrimU8(u8), - PrimU16(u16), - PrimU32(u32), - PrimU64(u64), - PrimS8(i8), - PrimS16(i16), - PrimS32(i32), - PrimS64(i64), - PrimFloat32(f32), - PrimFloat64(f64), - PrimChar(char), - PrimBool(bool), - PrimString(wit_bindgen::rt::string::String), - Handle((Uri,u64,)), - } - impl ::core::fmt::Debug for WitNode { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - match self { - WitNode::RecordValue(e) => { - f.debug_tuple("WitNode::RecordValue").field(e).finish() - } - WitNode::VariantValue(e) => { - f.debug_tuple("WitNode::VariantValue").field(e).finish() - } - WitNode::EnumValue(e) => { - f.debug_tuple("WitNode::EnumValue").field(e).finish() - } - WitNode::FlagsValue(e) => { - f.debug_tuple("WitNode::FlagsValue").field(e).finish() - } - WitNode::TupleValue(e) => { - f.debug_tuple("WitNode::TupleValue").field(e).finish() - } - WitNode::ListValue(e) => { - f.debug_tuple("WitNode::ListValue").field(e).finish() - } - WitNode::OptionValue(e) => { - f.debug_tuple("WitNode::OptionValue").field(e).finish() - } - WitNode::ResultValue(e) => { - f.debug_tuple("WitNode::ResultValue").field(e).finish() - } - WitNode::PrimU8(e) => { - f.debug_tuple("WitNode::PrimU8").field(e).finish() - } - WitNode::PrimU16(e) => { - f.debug_tuple("WitNode::PrimU16").field(e).finish() - } - WitNode::PrimU32(e) => { - f.debug_tuple("WitNode::PrimU32").field(e).finish() - } - WitNode::PrimU64(e) => { - f.debug_tuple("WitNode::PrimU64").field(e).finish() - } - WitNode::PrimS8(e) => { - f.debug_tuple("WitNode::PrimS8").field(e).finish() - } - WitNode::PrimS16(e) => { - f.debug_tuple("WitNode::PrimS16").field(e).finish() + #[allow(dead_code)] + pub mod rpc { + #[allow(dead_code, clippy::all)] + pub mod types { + #[used] + #[doc(hidden)] + #[cfg(target_arch = "wasm32")] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + pub type Pollable = super::super::super::wasi::io::poll::Pollable; + pub type NodeIndex = i32; + #[derive(Clone)] + pub struct Uri { + pub value: _rt::String, } - WitNode::PrimS32(e) => { - f.debug_tuple("WitNode::PrimS32").field(e).finish() + impl ::core::fmt::Debug for Uri { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + f.debug_struct("Uri").field("value", &self.value).finish() + } } - WitNode::PrimS64(e) => { - f.debug_tuple("WitNode::PrimS64").field(e).finish() + #[derive(Clone)] + pub enum WitNode { + RecordValue(_rt::Vec), + VariantValue((u32, Option)), + EnumValue(u32), + FlagsValue(_rt::Vec), + TupleValue(_rt::Vec), + ListValue(_rt::Vec), + OptionValue(Option), + ResultValue(Result, Option>), + PrimU8(u8), + PrimU16(u16), + PrimU32(u32), + PrimU64(u64), + PrimS8(i8), + PrimS16(i16), + PrimS32(i32), + PrimS64(i64), + PrimFloat32(f32), + PrimFloat64(f64), + PrimChar(char), + PrimBool(bool), + PrimString(_rt::String), + Handle((Uri, u64)), } - WitNode::PrimFloat32(e) => { - f.debug_tuple("WitNode::PrimFloat32").field(e).finish() + impl ::core::fmt::Debug for WitNode { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + match self { + WitNode::RecordValue(e) => { + f.debug_tuple("WitNode::RecordValue").field(e).finish() + } + WitNode::VariantValue(e) => { + f.debug_tuple("WitNode::VariantValue").field(e).finish() + } + WitNode::EnumValue(e) => { + f.debug_tuple("WitNode::EnumValue").field(e).finish() + } + WitNode::FlagsValue(e) => { + f.debug_tuple("WitNode::FlagsValue").field(e).finish() + } + WitNode::TupleValue(e) => { + f.debug_tuple("WitNode::TupleValue").field(e).finish() + } + WitNode::ListValue(e) => { + f.debug_tuple("WitNode::ListValue").field(e).finish() + } + WitNode::OptionValue(e) => { + f.debug_tuple("WitNode::OptionValue").field(e).finish() + } + WitNode::ResultValue(e) => { + f.debug_tuple("WitNode::ResultValue").field(e).finish() + } + WitNode::PrimU8(e) => f.debug_tuple("WitNode::PrimU8").field(e).finish(), + WitNode::PrimU16(e) => f.debug_tuple("WitNode::PrimU16").field(e).finish(), + WitNode::PrimU32(e) => f.debug_tuple("WitNode::PrimU32").field(e).finish(), + WitNode::PrimU64(e) => f.debug_tuple("WitNode::PrimU64").field(e).finish(), + WitNode::PrimS8(e) => f.debug_tuple("WitNode::PrimS8").field(e).finish(), + WitNode::PrimS16(e) => f.debug_tuple("WitNode::PrimS16").field(e).finish(), + WitNode::PrimS32(e) => f.debug_tuple("WitNode::PrimS32").field(e).finish(), + WitNode::PrimS64(e) => f.debug_tuple("WitNode::PrimS64").field(e).finish(), + WitNode::PrimFloat32(e) => { + f.debug_tuple("WitNode::PrimFloat32").field(e).finish() + } + WitNode::PrimFloat64(e) => { + f.debug_tuple("WitNode::PrimFloat64").field(e).finish() + } + WitNode::PrimChar(e) => { + f.debug_tuple("WitNode::PrimChar").field(e).finish() + } + WitNode::PrimBool(e) => { + f.debug_tuple("WitNode::PrimBool").field(e).finish() + } + WitNode::PrimString(e) => { + f.debug_tuple("WitNode::PrimString").field(e).finish() + } + WitNode::Handle(e) => f.debug_tuple("WitNode::Handle").field(e).finish(), + } + } } - WitNode::PrimFloat64(e) => { - f.debug_tuple("WitNode::PrimFloat64").field(e).finish() + #[derive(Clone)] + pub struct WitValue { + pub nodes: _rt::Vec, } - WitNode::PrimChar(e) => { - f.debug_tuple("WitNode::PrimChar").field(e).finish() + impl ::core::fmt::Debug for WitValue { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + f.debug_struct("WitValue") + .field("nodes", &self.nodes) + .finish() + } } - WitNode::PrimBool(e) => { - f.debug_tuple("WitNode::PrimBool").field(e).finish() + #[derive(Clone)] + pub enum RpcError { + ProtocolError(_rt::String), + Denied(_rt::String), + NotFound(_rt::String), + RemoteInternalError(_rt::String), } - WitNode::PrimString(e) => { - f.debug_tuple("WitNode::PrimString").field(e).finish() + impl ::core::fmt::Debug for RpcError { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + match self { + RpcError::ProtocolError(e) => { + f.debug_tuple("RpcError::ProtocolError").field(e).finish() + } + RpcError::Denied(e) => f.debug_tuple("RpcError::Denied").field(e).finish(), + RpcError::NotFound(e) => { + f.debug_tuple("RpcError::NotFound").field(e).finish() + } + RpcError::RemoteInternalError(e) => f + .debug_tuple("RpcError::RemoteInternalError") + .field(e) + .finish(), + } + } } - WitNode::Handle(e) => { - f.debug_tuple("WitNode::Handle").field(e).finish() + impl ::core::fmt::Display for RpcError { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + write!(f, "{:?}", self) + } } - } - } - } - #[derive(Clone)] - pub struct WitValue { - pub nodes: wit_bindgen::rt::vec::Vec::, - } - impl ::core::fmt::Debug for WitValue { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - f.debug_struct("WitValue").field("nodes", &self.nodes).finish() - } - } - #[derive(Clone)] - pub enum RpcError{ - ProtocolError(wit_bindgen::rt::string::String), - Denied(wit_bindgen::rt::string::String), - NotFound(wit_bindgen::rt::string::String), - RemoteInternalError(wit_bindgen::rt::string::String), - } - impl ::core::fmt::Debug for RpcError { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - match self { - RpcError::ProtocolError(e) => { - f.debug_tuple("RpcError::ProtocolError").field(e).finish() + + impl std::error::Error for RpcError {} + + #[derive(Debug)] + #[repr(transparent)] + pub struct WasmRpc { + handle: _rt::Resource, } - RpcError::Denied(e) => { - f.debug_tuple("RpcError::Denied").field(e).finish() + + impl WasmRpc { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } } - RpcError::NotFound(e) => { - f.debug_tuple("RpcError::NotFound").field(e).finish() + + unsafe impl _rt::WasmResource for WasmRpc { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "golem:rpc/types@0.1.0")] + extern "C" { + #[link_name = "[resource-drop]wasm-rpc"] + fn drop(_: u32); + } + + drop(_handle); + } + } } - RpcError::RemoteInternalError(e) => { - f.debug_tuple("RpcError::RemoteInternalError").field(e).finish() + + #[derive(Debug)] + #[repr(transparent)] + pub struct FutureInvokeResult { + handle: _rt::Resource, } - } - } - } - impl ::core::fmt::Display for RpcError { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - write!(f, "{:?}", self) - } - } - - impl std::error::Error for RpcError {} - - #[derive(Debug)] - #[repr(transparent)] - pub struct WasmRpc{ - handle: wit_bindgen::rt::Resource, - } - - impl WasmRpc{ - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: wit_bindgen::rt::Resource::from_handle(handle), - } - } - - #[doc(hidden)] - pub fn into_handle(self) -> u32 { - wit_bindgen::rt::Resource::into_handle(self.handle) - } - - #[doc(hidden)] - pub fn handle(&self) -> u32 { - wit_bindgen::rt::Resource::handle(&self.handle) - } - } - - - unsafe impl wit_bindgen::rt::WasmResource for WasmRpc{ - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(not(target_arch = "wasm32"))] - unreachable!(); - - #[cfg(target_arch = "wasm32")] - { - #[link(wasm_import_module = "golem:rpc/types@0.1.0")] - extern "C" { - #[link_name = "[resource-drop]wasm-rpc"] - fn drop(_: u32); + + impl FutureInvokeResult { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } } - - drop(_handle); - } - } - } - - - #[derive(Debug)] - #[repr(transparent)] - pub struct FutureInvokeResult{ - handle: wit_bindgen::rt::Resource, - } - - impl FutureInvokeResult{ - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: wit_bindgen::rt::Resource::from_handle(handle), - } - } - - #[doc(hidden)] - pub fn into_handle(self) -> u32 { - wit_bindgen::rt::Resource::into_handle(self.handle) - } - - #[doc(hidden)] - pub fn handle(&self) -> u32 { - wit_bindgen::rt::Resource::handle(&self.handle) - } - } - - - unsafe impl wit_bindgen::rt::WasmResource for FutureInvokeResult{ - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(not(target_arch = "wasm32"))] - unreachable!(); - - #[cfg(target_arch = "wasm32")] - { - #[link(wasm_import_module = "golem:rpc/types@0.1.0")] - extern "C" { - #[link_name = "[resource-drop]future-invoke-result"] - fn drop(_: u32); + + unsafe impl _rt::WasmResource for FutureInvokeResult { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "golem:rpc/types@0.1.0")] + extern "C" { + #[link_name = "[resource-drop]future-invoke-result"] + fn drop(_: u32); + } + + drop(_handle); + } + } } - - drop(_handle); - } - } - } - - impl WasmRpc { - #[allow(unused_unsafe, clippy::all)] - pub fn new(location: &Uri,) -> Self{ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - let Uri{ value:value0, } = location; - let vec1 = value0; - let ptr1 = vec1.as_ptr() as i32; - let len1 = vec1.len() as i32; - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "golem:rpc/types@0.1.0")] - extern "C" { - #[link_name = "[constructor]wasm-rpc"] - fn wit_import(_: i32, _: i32, ) -> i32; + + impl WasmRpc { + #[allow(unused_unsafe, clippy::all)] + pub fn new(location: &Uri) -> Self { + unsafe { + let Uri { value: value0 } = location; + let vec1 = value0; + let ptr1 = vec1.as_ptr().cast::(); + let len1 = vec1.len(); + + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "golem:rpc/types@0.1.0")] + extern "C" { + #[link_name = "[constructor]wasm-rpc"] + fn wit_import(_: *mut u8, _: usize) -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: *mut u8, _: usize) -> i32 { + unreachable!() + } + let ret = wit_import(ptr1.cast_mut(), len1); + WasmRpc::from_handle(ret as u32) + } + } } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: i32, ) -> i32{ unreachable!() } - let ret = wit_import(ptr1, len1); - WasmRpc::from_handle(ret as u32) - } - } - } - impl WasmRpc { - #[allow(unused_unsafe, clippy::all)] - pub fn invoke_and_await(&self,function_name: &str,function_params: &[WitValue],) -> Result{ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - let mut cleanup_list = Vec::new(); - - #[repr(align(4))] - struct RetArea([u8; 16]); - let mut ret_area = ::core::mem::MaybeUninit::::uninit(); - let vec0 = function_name; - let ptr0 = vec0.as_ptr() as i32; - let len0 = vec0.len() as i32; - let vec12 = function_params; - let len12 = vec12.len() as i32; - let layout12 = alloc::Layout::from_size_align_unchecked(vec12.len() * 8, 4); - let result12 = if layout12.size() != 0 - { - let ptr = alloc::alloc(layout12); - if ptr.is_null() - { - alloc::handle_alloc_error(layout12); - } - ptr - }else {{ - ::core::ptr::null_mut() - }}; - for (i, e) in vec12.into_iter().enumerate() { - let base = result12 as i32 + (i as i32) * 8; - { - let WitValue{ nodes:nodes1, } = e; - let vec11 = nodes1; - let len11 = vec11.len() as i32; - let layout11 = alloc::Layout::from_size_align_unchecked(vec11.len() * 24, 8); - let result11 = if layout11.size() != 0 - { - let ptr = alloc::alloc(layout11); - if ptr.is_null() - { - alloc::handle_alloc_error(layout11); - } - ptr - }else {{ - ::core::ptr::null_mut() - }}; - for (i, e) in vec11.into_iter().enumerate() { - let base = result11 as i32 + (i as i32) * 24; - { - match e { - WitNode::RecordValue(e) => { - *((base + 0) as *mut u8) = (0i32) as u8; - let vec2 = e; - let ptr2 = vec2.as_ptr() as i32; - let len2 = vec2.len() as i32; - *((base + 12) as *mut i32) = len2; - *((base + 8) as *mut i32) = ptr2; - }, - WitNode::VariantValue(e) => { - *((base + 0) as *mut u8) = (1i32) as u8; - let (t3_0, t3_1, ) = e; - *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(t3_0); - match t3_1 { - Some(e) => { - *((base + 12) as *mut u8) = (1i32) as u8; - *((base + 16) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - None => { - { - *((base + 12) as *mut u8) = (0i32) as u8; - } - }, - };}, - WitNode::EnumValue(e) => { - *((base + 0) as *mut u8) = (2i32) as u8; - *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - WitNode::FlagsValue(e) => { - *((base + 0) as *mut u8) = (3i32) as u8; - let vec4 = e; - let len4 = vec4.len() as i32; - let layout4 = alloc::Layout::from_size_align_unchecked(vec4.len() * 1, 1); - let result4 = if layout4.size() != 0 - { - let ptr = alloc::alloc(layout4); - if ptr.is_null() - { - alloc::handle_alloc_error(layout4); + impl WasmRpc { + #[allow(unused_unsafe, clippy::all)] + pub fn invoke_and_await( + &self, + function_name: &str, + function_params: &[WitValue], + ) -> Result { + unsafe { + let mut cleanup_list = _rt::Vec::new(); + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); + let vec0 = function_name; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let vec12 = function_params; + let len12 = vec12.len(); + let layout12 = + _rt::alloc::Layout::from_size_align_unchecked(vec12.len() * 8, 4); + let result12 = if layout12.size() != 0 { + let ptr = _rt::alloc::alloc(layout12).cast::(); + if ptr.is_null() { + _rt::alloc::handle_alloc_error(layout12); } ptr - }else {{ - ::core::ptr::null_mut() - }}; - for (i, e) in vec4.into_iter().enumerate() { - let base = result4 as i32 + (i as i32) * 1; + } else { { - *((base + 0) as *mut u8) = (match e { true => 1, false => 0 }) as u8; + ::core::ptr::null_mut() } - } - *((base + 12) as *mut i32) = len4; - *((base + 8) as *mut i32) = result4 as i32; - cleanup_list.extend_from_slice(&[(result4, layout4),]); - }, - WitNode::TupleValue(e) => { - *((base + 0) as *mut u8) = (4i32) as u8; - let vec5 = e; - let ptr5 = vec5.as_ptr() as i32; - let len5 = vec5.len() as i32; - *((base + 12) as *mut i32) = len5; - *((base + 8) as *mut i32) = ptr5; - }, - WitNode::ListValue(e) => { - *((base + 0) as *mut u8) = (5i32) as u8; - let vec6 = e; - let ptr6 = vec6.as_ptr() as i32; - let len6 = vec6.len() as i32; - *((base + 12) as *mut i32) = len6; - *((base + 8) as *mut i32) = ptr6; - }, - WitNode::OptionValue(e) => { - *((base + 0) as *mut u8) = (6i32) as u8; - match e { - Some(e) => { - *((base + 8) as *mut u8) = (1i32) as u8; - *((base + 12) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - None => { - { - *((base + 8) as *mut u8) = (0i32) as u8; - } - }, - };}, - WitNode::ResultValue(e) => { - *((base + 0) as *mut u8) = (7i32) as u8; - match e { - Ok(e) => { { - *((base + 8) as *mut u8) = (0i32) as u8; - match e { - Some(e) => { - *((base + 12) as *mut u8) = (1i32) as u8; - *((base + 16) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - None => { + }; + for (i, e) in vec12.into_iter().enumerate() { + let base = result12.add(i * 8); + { + let WitValue { nodes: nodes1 } = e; + let vec11 = nodes1; + let len11 = vec11.len(); + let layout11 = _rt::alloc::Layout::from_size_align_unchecked( + vec11.len() * 24, + 8, + ); + let result11 = if layout11.size() != 0 { + let ptr = _rt::alloc::alloc(layout11).cast::(); + if ptr.is_null() { + _rt::alloc::handle_alloc_error(layout11); + } + ptr + } else { + { + ::core::ptr::null_mut() + } + }; + for (i, e) in vec11.into_iter().enumerate() { + let base = result11.add(i * 24); { - *((base + 12) as *mut u8) = (0i32) as u8; + match e { + WitNode::RecordValue(e) => { + *base.add(0).cast::() = (0i32) as u8; + let vec2 = e; + let ptr2 = vec2.as_ptr().cast::(); + let len2 = vec2.len(); + *base.add(12).cast::() = len2; + *base.add(8).cast::<*mut u8>() = ptr2.cast_mut(); + } + WitNode::VariantValue(e) => { + *base.add(0).cast::() = (1i32) as u8; + let (t3_0, t3_1) = e; + *base.add(8).cast::() = _rt::as_i32(t3_0); + match t3_1 { + Some(e) => { + *base.add(12).cast::() = (1i32) as u8; + *base.add(16).cast::() = + _rt::as_i32(e); + } + None => { + *base.add(12).cast::() = (0i32) as u8; + } + }; + } + WitNode::EnumValue(e) => { + *base.add(0).cast::() = (2i32) as u8; + *base.add(8).cast::() = _rt::as_i32(e); + } + WitNode::FlagsValue(e) => { + *base.add(0).cast::() = (3i32) as u8; + let vec4 = e; + let len4 = vec4.len(); + let layout4 = + _rt::alloc::Layout::from_size_align_unchecked( + vec4.len() * 1, + 1, + ); + let result4 = if layout4.size() != 0 { + let ptr = + _rt::alloc::alloc(layout4).cast::(); + if ptr.is_null() { + _rt::alloc::handle_alloc_error(layout4); + } + ptr + } else { + { + ::core::ptr::null_mut() + } + }; + for (i, e) in vec4.into_iter().enumerate() { + let base = result4.add(i * 1); + { + *base.add(0).cast::() = (match e { + true => 1, + false => 0, + }) + as u8; + } + } + *base.add(12).cast::() = len4; + *base.add(8).cast::<*mut u8>() = result4; + cleanup_list + .extend_from_slice(&[(result4, layout4)]); + } + WitNode::TupleValue(e) => { + *base.add(0).cast::() = (4i32) as u8; + let vec5 = e; + let ptr5 = vec5.as_ptr().cast::(); + let len5 = vec5.len(); + *base.add(12).cast::() = len5; + *base.add(8).cast::<*mut u8>() = ptr5.cast_mut(); + } + WitNode::ListValue(e) => { + *base.add(0).cast::() = (5i32) as u8; + let vec6 = e; + let ptr6 = vec6.as_ptr().cast::(); + let len6 = vec6.len(); + *base.add(12).cast::() = len6; + *base.add(8).cast::<*mut u8>() = ptr6.cast_mut(); + } + WitNode::OptionValue(e) => { + *base.add(0).cast::() = (6i32) as u8; + match e { + Some(e) => { + *base.add(8).cast::() = (1i32) as u8; + *base.add(12).cast::() = + _rt::as_i32(e); + } + None => { + *base.add(8).cast::() = (0i32) as u8; + } + }; + } + WitNode::ResultValue(e) => { + *base.add(0).cast::() = (7i32) as u8; + match e { + Ok(e) => { + *base.add(8).cast::() = (0i32) as u8; + match e { + Some(e) => { + *base.add(12).cast::() = + (1i32) as u8; + *base.add(16).cast::() = + _rt::as_i32(e); + } + None => { + *base.add(12).cast::() = + (0i32) as u8; + } + }; + } + Err(e) => { + *base.add(8).cast::() = (1i32) as u8; + match e { + Some(e) => { + *base.add(12).cast::() = + (1i32) as u8; + *base.add(16).cast::() = + _rt::as_i32(e); + } + None => { + *base.add(12).cast::() = + (0i32) as u8; + } + }; + } + }; + } + WitNode::PrimU8(e) => { + *base.add(0).cast::() = (8i32) as u8; + *base.add(8).cast::() = (_rt::as_i32(e)) as u8; + } + WitNode::PrimU16(e) => { + *base.add(0).cast::() = (9i32) as u8; + *base.add(8).cast::() = + (_rt::as_i32(e)) as u16; + } + WitNode::PrimU32(e) => { + *base.add(0).cast::() = (10i32) as u8; + *base.add(8).cast::() = _rt::as_i32(e); + } + WitNode::PrimU64(e) => { + *base.add(0).cast::() = (11i32) as u8; + *base.add(8).cast::() = _rt::as_i64(e); + } + WitNode::PrimS8(e) => { + *base.add(0).cast::() = (12i32) as u8; + *base.add(8).cast::() = (_rt::as_i32(e)) as u8; + } + WitNode::PrimS16(e) => { + *base.add(0).cast::() = (13i32) as u8; + *base.add(8).cast::() = + (_rt::as_i32(e)) as u16; + } + WitNode::PrimS32(e) => { + *base.add(0).cast::() = (14i32) as u8; + *base.add(8).cast::() = _rt::as_i32(e); + } + WitNode::PrimS64(e) => { + *base.add(0).cast::() = (15i32) as u8; + *base.add(8).cast::() = _rt::as_i64(e); + } + WitNode::PrimFloat32(e) => { + *base.add(0).cast::() = (16i32) as u8; + *base.add(8).cast::() = _rt::as_f32(e); + } + WitNode::PrimFloat64(e) => { + *base.add(0).cast::() = (17i32) as u8; + *base.add(8).cast::() = _rt::as_f64(e); + } + WitNode::PrimChar(e) => { + *base.add(0).cast::() = (18i32) as u8; + *base.add(8).cast::() = _rt::as_i32(e); + } + WitNode::PrimBool(e) => { + *base.add(0).cast::() = (19i32) as u8; + *base.add(8).cast::() = (match e { + true => 1, + false => 0, + }) + as u8; + } + WitNode::PrimString(e) => { + *base.add(0).cast::() = (20i32) as u8; + let vec7 = e; + let ptr7 = vec7.as_ptr().cast::(); + let len7 = vec7.len(); + *base.add(12).cast::() = len7; + *base.add(8).cast::<*mut u8>() = ptr7.cast_mut(); + } + WitNode::Handle(e) => { + *base.add(0).cast::() = (21i32) as u8; + let (t8_0, t8_1) = e; + let Uri { value: value9 } = t8_0; + let vec10 = value9; + let ptr10 = vec10.as_ptr().cast::(); + let len10 = vec10.len(); + *base.add(12).cast::() = len10; + *base.add(8).cast::<*mut u8>() = ptr10.cast_mut(); + *base.add(16).cast::() = _rt::as_i64(t8_1); + } + } } - }, - };} }, - Err(e) => { { - *((base + 8) as *mut u8) = (1i32) as u8; - match e { - Some(e) => { - *((base + 12) as *mut u8) = (1i32) as u8; - *((base + 16) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - None => { - { - *((base + 12) as *mut u8) = (0i32) as u8; - } - }, - };} }, - };}, - WitNode::PrimU8(e) => { - *((base + 0) as *mut u8) = (8i32) as u8; - *((base + 8) as *mut u8) = (wit_bindgen::rt::as_i32(e)) as u8; - }, - WitNode::PrimU16(e) => { - *((base + 0) as *mut u8) = (9i32) as u8; - *((base + 8) as *mut u16) = (wit_bindgen::rt::as_i32(e)) as u16; - }, - WitNode::PrimU32(e) => { - *((base + 0) as *mut u8) = (10i32) as u8; - *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - WitNode::PrimU64(e) => { - *((base + 0) as *mut u8) = (11i32) as u8; - *((base + 8) as *mut i64) = wit_bindgen::rt::as_i64(e); - }, - WitNode::PrimS8(e) => { - *((base + 0) as *mut u8) = (12i32) as u8; - *((base + 8) as *mut u8) = (wit_bindgen::rt::as_i32(e)) as u8; - }, - WitNode::PrimS16(e) => { - *((base + 0) as *mut u8) = (13i32) as u8; - *((base + 8) as *mut u16) = (wit_bindgen::rt::as_i32(e)) as u16; - }, - WitNode::PrimS32(e) => { - *((base + 0) as *mut u8) = (14i32) as u8; - *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - WitNode::PrimS64(e) => { - *((base + 0) as *mut u8) = (15i32) as u8; - *((base + 8) as *mut i64) = wit_bindgen::rt::as_i64(e); - }, - WitNode::PrimFloat32(e) => { - *((base + 0) as *mut u8) = (16i32) as u8; - *((base + 8) as *mut f32) = wit_bindgen::rt::as_f32(e); - }, - WitNode::PrimFloat64(e) => { - *((base + 0) as *mut u8) = (17i32) as u8; - *((base + 8) as *mut f64) = wit_bindgen::rt::as_f64(e); - }, - WitNode::PrimChar(e) => { - *((base + 0) as *mut u8) = (18i32) as u8; - *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - WitNode::PrimBool(e) => { - *((base + 0) as *mut u8) = (19i32) as u8; - *((base + 8) as *mut u8) = (match e { true => 1, false => 0 }) as u8; - }, - WitNode::PrimString(e) => { - *((base + 0) as *mut u8) = (20i32) as u8; - let vec7 = e; - let ptr7 = vec7.as_ptr() as i32; - let len7 = vec7.len() as i32; - *((base + 12) as *mut i32) = len7; - *((base + 8) as *mut i32) = ptr7; - }, - WitNode::Handle(e) => { - *((base + 0) as *mut u8) = (21i32) as u8; - let (t8_0, t8_1, ) = e; - let Uri{ value:value9, } = t8_0; - let vec10 = value9; - let ptr10 = vec10.as_ptr() as i32; - let len10 = vec10.len() as i32; - *((base + 12) as *mut i32) = len10; - *((base + 8) as *mut i32) = ptr10; - *((base + 16) as *mut i64) = wit_bindgen::rt::as_i64(t8_1); - }, - } + } + *base.add(4).cast::() = len11; + *base.add(0).cast::<*mut u8>() = result11; + cleanup_list.extend_from_slice(&[(result11, layout11)]); } - } - *((base + 4) as *mut i32) = len11; - *((base + 0) as *mut i32) = result11 as i32; - cleanup_list.extend_from_slice(&[(result11, layout11),]); } - } - let ptr13 = ret_area.as_mut_ptr() as i32; - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "golem:rpc/types@0.1.0")] - extern "C" { - #[link_name = "[method]wasm-rpc.invoke-and-await"] - fn wit_import(_: i32, _: i32, _: i32, _: i32, _: i32, _: i32, ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: i32, _: i32, _: i32, _: i32, _: i32, ){ unreachable!() } - wit_import((self).handle() as i32, ptr0, len0, result12 as i32, len12, ptr13); - let l14 = i32::from(*((ptr13 + 0) as *const u8)); - if layout12.size() != 0 { - alloc::dealloc(result12, layout12); - } - for (ptr, layout) in cleanup_list { - - if layout.size() != 0 { - - alloc::dealloc(ptr, layout); - + let ptr13 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "golem:rpc/types@0.1.0")] + extern "C" { + #[link_name = "[method]wasm-rpc.invoke-and-await"] + fn wit_import( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + _: usize, + _: *mut u8, + ); } - - } - match l14 { - 0 => { - let e = { - let l15 = *((ptr13 + 4) as *const i32); - let l16 = *((ptr13 + 8) as *const i32); - let base62 = l15; - let len62 = l16; - let mut result62 = Vec::with_capacity(len62 as usize); - for i in 0..len62 { - let base = base62 + i * 24; - let e62 = { - let l17 = i32::from(*((base + 0) as *const u8)); - let v61 = match l17 { - 0 => { - let e61 = { - let l18 = *((base + 8) as *const i32); - let l19 = *((base + 12) as *const i32); - let len20 = l19 as usize; - - Vec::from_raw_parts(l18 as *mut _, len20, len20) - }; - WitNode::RecordValue(e61) - } - 1 => { - let e61 = { - let l21 = *((base + 8) as *const i32); - let l22 = i32::from(*((base + 12) as *const u8)); - - (l21 as u32, match l22 { + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + _: usize, + _: *mut u8, + ) { + unreachable!() + } + wit_import( + (self).handle() as i32, + ptr0.cast_mut(), + len0, + result12, + len12, + ptr13, + ); + let l14 = i32::from(*ptr13.add(0).cast::()); + if layout12.size() != 0 { + _rt::alloc::dealloc(result12.cast(), layout12); + } + for (ptr, layout) in cleanup_list { + if layout.size() != 0 { + _rt::alloc::dealloc(ptr.cast(), layout); + } + } + match l14 { + 0 => { + let e = { + let l15 = *ptr13.add(4).cast::<*mut u8>(); + let l16 = *ptr13.add(8).cast::(); + let base62 = l15; + let len62 = l16; + let mut result62 = _rt::Vec::with_capacity(len62); + for i in 0..len62 { + let base = base62.add(i * 24); + let e62 = { + let l17 = i32::from(*base.add(0).cast::()); + let v61 = match l17 { + 0 => { + let e61 = { + let l18 = *base.add(8).cast::<*mut u8>(); + let l19 = *base.add(12).cast::(); + let len20 = l19; + + _rt::Vec::from_raw_parts( + l18.cast(), + len20, + len20, + ) + }; + WitNode::RecordValue(e61) + } + 1 => { + let e61 = + { + let l21 = *base.add(8).cast::(); + let l22 = i32::from( + *base.add(12).cast::(), + ); + + (l21 as u32, match l22 { 0 => None, 1 => { let e = { - let l23 = *((base + 16) as *const i32); - + let l23 = *base.add(16).cast::(); + l23 }; Some(e) } - _ => wit_bindgen::rt::invalid_enum_discriminant(), + _ => _rt::invalid_enum_discriminant(), }) - }; - WitNode::VariantValue(e61) - } - 2 => { - let e61 = { - let l24 = *((base + 8) as *const i32); - - l24 as u32 - }; - WitNode::EnumValue(e61) - } - 3 => { - let e61 = { - let l25 = *((base + 8) as *const i32); - let l26 = *((base + 12) as *const i32); - let base28 = l25; - let len28 = l26; - let mut result28 = Vec::with_capacity(len28 as usize); - for i in 0..len28 { - let base = base28 + i * 1; - let e28 = { - let l27 = i32::from(*((base + 0) as *const u8)); - - wit_bindgen::rt::bool_lift(l27 as u8) - }; - result28.push(e28); - } - wit_bindgen::rt::dealloc(base28, (len28 as usize) * 1, 1); - - result28 - }; - WitNode::FlagsValue(e61) - } - 4 => { - let e61 = { - let l29 = *((base + 8) as *const i32); - let l30 = *((base + 12) as *const i32); - let len31 = l30 as usize; - - Vec::from_raw_parts(l29 as *mut _, len31, len31) - }; - WitNode::TupleValue(e61) - } - 5 => { - let e61 = { - let l32 = *((base + 8) as *const i32); - let l33 = *((base + 12) as *const i32); - let len34 = l33 as usize; - - Vec::from_raw_parts(l32 as *mut _, len34, len34) - }; - WitNode::ListValue(e61) - } - 6 => { - let e61 = { - let l35 = i32::from(*((base + 8) as *const u8)); - - match l35 { - 0 => None, - 1 => { - let e = { - let l36 = *((base + 12) as *const i32); - - l36 - }; - Some(e) - } - _ => wit_bindgen::rt::invalid_enum_discriminant(), - } - }; - WitNode::OptionValue(e61) - } - 7 => { - let e61 = { - let l37 = i32::from(*((base + 8) as *const u8)); - - match l37 { - 0 => { - let e = { - let l38 = i32::from(*((base + 12) as *const u8)); - - match l38 { + }; + WitNode::VariantValue(e61) + } + 2 => { + let e61 = { + let l24 = *base.add(8).cast::(); + + l24 as u32 + }; + WitNode::EnumValue(e61) + } + 3 => { + let e61 = { + let l25 = *base.add(8).cast::<*mut u8>(); + let l26 = *base.add(12).cast::(); + let base28 = l25; + let len28 = l26; + let mut result28 = + _rt::Vec::with_capacity(len28); + for i in 0..len28 { + let base = base28.add(i * 1); + let e28 = { + let l27 = i32::from( + *base.add(0).cast::(), + ); + + _rt::bool_lift(l27 as u8) + }; + result28.push(e28); + } + _rt::cabi_dealloc(base28, len28 * 1, 1); + + result28 + }; + WitNode::FlagsValue(e61) + } + 4 => { + let e61 = { + let l29 = *base.add(8).cast::<*mut u8>(); + let l30 = *base.add(12).cast::(); + let len31 = l30; + + _rt::Vec::from_raw_parts( + l29.cast(), + len31, + len31, + ) + }; + WitNode::TupleValue(e61) + } + 5 => { + let e61 = { + let l32 = *base.add(8).cast::<*mut u8>(); + let l33 = *base.add(12).cast::(); + let len34 = l33; + + _rt::Vec::from_raw_parts( + l32.cast(), + len34, + len34, + ) + }; + WitNode::ListValue(e61) + } + 6 => { + let e61 = { + let l35 = + i32::from(*base.add(8).cast::()); + + match l35 { + 0 => None, + 1 => { + let e = { + let l36 = + *base.add(12).cast::(); + + l36 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + WitNode::OptionValue(e61) + } + 7 => { + let e61 = { + let l37 = + i32::from(*base.add(8).cast::()); + + match l37 { + 0 => { + let e = { + let l38 = i32::from( + *base.add(12).cast::(), + ); + + match l38 { 0 => None, 1 => { let e = { - let l39 = *((base + 16) as *const i32); - + let l39 = *base.add(16).cast::(); + l39 }; Some(e) } - _ => wit_bindgen::rt::invalid_enum_discriminant(), + _ => _rt::invalid_enum_discriminant(), } - }; - Ok(e) - } - 1 => { - let e = { - let l40 = i32::from(*((base + 12) as *const u8)); - - match l40 { + }; + Ok(e) + } + 1 => { + let e = { + let l40 = i32::from( + *base.add(12).cast::(), + ); + + match l40 { 0 => None, 1 => { let e = { - let l41 = *((base + 16) as *const i32); - + let l41 = *base.add(16).cast::(); + l41 }; Some(e) } - _ => wit_bindgen::rt::invalid_enum_discriminant(), + _ => _rt::invalid_enum_discriminant(), } - }; - Err(e) + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + WitNode::ResultValue(e61) + } + 8 => { + let e61 = { + let l42 = + i32::from(*base.add(8).cast::()); + + l42 as u8 + }; + WitNode::PrimU8(e61) + } + 9 => { + let e61 = { + let l43 = + i32::from(*base.add(8).cast::()); + + l43 as u16 + }; + WitNode::PrimU16(e61) + } + 10 => { + let e61 = { + let l44 = *base.add(8).cast::(); + + l44 as u32 + }; + WitNode::PrimU32(e61) + } + 11 => { + let e61 = { + let l45 = *base.add(8).cast::(); + + l45 as u64 + }; + WitNode::PrimU64(e61) + } + 12 => { + let e61 = { + let l46 = + i32::from(*base.add(8).cast::()); + + l46 as i8 + }; + WitNode::PrimS8(e61) + } + 13 => { + let e61 = { + let l47 = + i32::from(*base.add(8).cast::()); + + l47 as i16 + }; + WitNode::PrimS16(e61) + } + 14 => { + let e61 = { + let l48 = *base.add(8).cast::(); + + l48 + }; + WitNode::PrimS32(e61) + } + 15 => { + let e61 = { + let l49 = *base.add(8).cast::(); + + l49 + }; + WitNode::PrimS64(e61) + } + 16 => { + let e61 = { + let l50 = *base.add(8).cast::(); + + l50 + }; + WitNode::PrimFloat32(e61) + } + 17 => { + let e61 = { + let l51 = *base.add(8).cast::(); + + l51 + }; + WitNode::PrimFloat64(e61) + } + 18 => { + let e61 = { + let l52 = *base.add(8).cast::(); + + _rt::char_lift(l52 as u32) + }; + WitNode::PrimChar(e61) + } + 19 => { + let e61 = { + let l53 = + i32::from(*base.add(8).cast::()); + + _rt::bool_lift(l53 as u8) + }; + WitNode::PrimBool(e61) + } + 20 => { + let e61 = { + let l54 = *base.add(8).cast::<*mut u8>(); + let l55 = *base.add(12).cast::(); + let len56 = l55; + let bytes56 = _rt::Vec::from_raw_parts( + l54.cast(), + len56, + len56, + ); + + _rt::string_lift(bytes56) + }; + WitNode::PrimString(e61) + } + n => { + debug_assert_eq!( + n, 21, + "invalid enum discriminant" + ); + let e61 = { + let l57 = *base.add(8).cast::<*mut u8>(); + let l58 = *base.add(12).cast::(); + let len59 = l58; + let bytes59 = _rt::Vec::from_raw_parts( + l57.cast(), + len59, + len59, + ); + let l60 = *base.add(16).cast::(); + + ( + Uri { + value: _rt::string_lift(bytes59), + }, + l60 as u64, + ) + }; + WitNode::Handle(e61) + } + }; + + v61 + }; + result62.push(e62); + } + _rt::cabi_dealloc(base62, len62 * 24, 8); + + WitValue { nodes: result62 } + }; + Ok(e) + } + 1 => { + let e = { + let l63 = i32::from(*ptr13.add(4).cast::()); + let v76 = match l63 { + 0 => { + let e76 = { + let l64 = *ptr13.add(8).cast::<*mut u8>(); + let l65 = *ptr13.add(12).cast::(); + let len66 = l65; + let bytes66 = _rt::Vec::from_raw_parts( + l64.cast(), + len66, + len66, + ); + + _rt::string_lift(bytes66) + }; + RpcError::ProtocolError(e76) + } + 1 => { + let e76 = { + let l67 = *ptr13.add(8).cast::<*mut u8>(); + let l68 = *ptr13.add(12).cast::(); + let len69 = l68; + let bytes69 = _rt::Vec::from_raw_parts( + l67.cast(), + len69, + len69, + ); + + _rt::string_lift(bytes69) + }; + RpcError::Denied(e76) + } + 2 => { + let e76 = { + let l70 = *ptr13.add(8).cast::<*mut u8>(); + let l71 = *ptr13.add(12).cast::(); + let len72 = l71; + let bytes72 = _rt::Vec::from_raw_parts( + l70.cast(), + len72, + len72, + ); + + _rt::string_lift(bytes72) + }; + RpcError::NotFound(e76) + } + n => { + debug_assert_eq!(n, 3, "invalid enum discriminant"); + let e76 = { + let l73 = *ptr13.add(8).cast::<*mut u8>(); + let l74 = *ptr13.add(12).cast::(); + let len75 = l74; + let bytes75 = _rt::Vec::from_raw_parts( + l73.cast(), + len75, + len75, + ); + + _rt::string_lift(bytes75) + }; + RpcError::RemoteInternalError(e76) } - _ => wit_bindgen::rt::invalid_enum_discriminant(), - } - }; - WitNode::ResultValue(e61) - } - 8 => { - let e61 = { - let l42 = i32::from(*((base + 8) as *const u8)); - - l42 as u8 - }; - WitNode::PrimU8(e61) - } - 9 => { - let e61 = { - let l43 = i32::from(*((base + 8) as *const u16)); - - l43 as u16 - }; - WitNode::PrimU16(e61) - } - 10 => { - let e61 = { - let l44 = *((base + 8) as *const i32); - - l44 as u32 - }; - WitNode::PrimU32(e61) - } - 11 => { - let e61 = { - let l45 = *((base + 8) as *const i64); - - l45 as u64 - }; - WitNode::PrimU64(e61) - } - 12 => { - let e61 = { - let l46 = i32::from(*((base + 8) as *const i8)); - - l46 as i8 - }; - WitNode::PrimS8(e61) - } - 13 => { - let e61 = { - let l47 = i32::from(*((base + 8) as *const i16)); - - l47 as i16 - }; - WitNode::PrimS16(e61) - } - 14 => { - let e61 = { - let l48 = *((base + 8) as *const i32); - - l48 - }; - WitNode::PrimS32(e61) - } - 15 => { - let e61 = { - let l49 = *((base + 8) as *const i64); - - l49 - }; - WitNode::PrimS64(e61) - } - 16 => { - let e61 = { - let l50 = *((base + 8) as *const f32); - - l50 - }; - WitNode::PrimFloat32(e61) - } - 17 => { - let e61 = { - let l51 = *((base + 8) as *const f64); - - l51 - }; - WitNode::PrimFloat64(e61) - } - 18 => { - let e61 = { - let l52 = *((base + 8) as *const i32); - - wit_bindgen::rt::char_lift(l52 as u32) - }; - WitNode::PrimChar(e61) - } - 19 => { - let e61 = { - let l53 = i32::from(*((base + 8) as *const u8)); - - wit_bindgen::rt::bool_lift(l53 as u8) - }; - WitNode::PrimBool(e61) - } - 20 => { - let e61 = { - let l54 = *((base + 8) as *const i32); - let l55 = *((base + 12) as *const i32); - let len56 = l55 as usize; - let bytes56 = Vec::from_raw_parts(l54 as *mut _, len56, len56); - - wit_bindgen::rt::string_lift(bytes56) - }; - WitNode::PrimString(e61) - } - n => { - debug_assert_eq!(n, 21, "invalid enum discriminant"); - let e61 = { - let l57 = *((base + 8) as *const i32); - let l58 = *((base + 12) as *const i32); - let len59 = l58 as usize; - let bytes59 = Vec::from_raw_parts(l57 as *mut _, len59, len59); - let l60 = *((base + 16) as *const i64); - - (Uri{ - value: wit_bindgen::rt::string_lift(bytes59), - }, l60 as u64) }; - WitNode::Handle(e61) - } + + v76 }; - - v61 - }; - result62.push(e62); - } - wit_bindgen::rt::dealloc(base62, (len62 as usize) * 24, 8); - - WitValue{ - nodes: result62, + Err(e) } - }; - Ok(e) - } - 1 => { - let e = { - let l63 = i32::from(*((ptr13 + 4) as *const u8)); - let v76 = match l63 { - 0 => { - let e76 = { - let l64 = *((ptr13 + 8) as *const i32); - let l65 = *((ptr13 + 12) as *const i32); - let len66 = l65 as usize; - let bytes66 = Vec::from_raw_parts(l64 as *mut _, len66, len66); - - wit_bindgen::rt::string_lift(bytes66) - }; - RpcError::ProtocolError(e76) - } - 1 => { - let e76 = { - let l67 = *((ptr13 + 8) as *const i32); - let l68 = *((ptr13 + 12) as *const i32); - let len69 = l68 as usize; - let bytes69 = Vec::from_raw_parts(l67 as *mut _, len69, len69); - - wit_bindgen::rt::string_lift(bytes69) - }; - RpcError::Denied(e76) - } - 2 => { - let e76 = { - let l70 = *((ptr13 + 8) as *const i32); - let l71 = *((ptr13 + 12) as *const i32); - let len72 = l71 as usize; - let bytes72 = Vec::from_raw_parts(l70 as *mut _, len72, len72); - - wit_bindgen::rt::string_lift(bytes72) - }; - RpcError::NotFound(e76) - } - n => { - debug_assert_eq!(n, 3, "invalid enum discriminant"); - let e76 = { - let l73 = *((ptr13 + 8) as *const i32); - let l74 = *((ptr13 + 12) as *const i32); - let len75 = l74 as usize; - let bytes75 = Vec::from_raw_parts(l73 as *mut _, len75, len75); - - wit_bindgen::rt::string_lift(bytes75) - }; - RpcError::RemoteInternalError(e76) - } - }; - - v76 - }; - Err(e) + _ => _rt::invalid_enum_discriminant(), } - _ => wit_bindgen::rt::invalid_enum_discriminant(), - } } - } } - impl WasmRpc { - #[allow(unused_unsafe, clippy::all)] - pub fn invoke(&self,function_name: &str,function_params: &[WitValue],) -> Result<(),RpcError>{ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; + } + impl WasmRpc { + #[allow(unused_unsafe, clippy::all)] + pub fn invoke( + &self, + function_name: &str, + function_params: &[WitValue], + ) -> Result<(), RpcError> { unsafe { - let mut cleanup_list = Vec::new(); - - #[repr(align(4))] - struct RetArea([u8; 16]); - let mut ret_area = ::core::mem::MaybeUninit::::uninit(); - let vec0 = function_name; - let ptr0 = vec0.as_ptr() as i32; - let len0 = vec0.len() as i32; - let vec12 = function_params; - let len12 = vec12.len() as i32; - let layout12 = alloc::Layout::from_size_align_unchecked(vec12.len() * 8, 4); - let result12 = if layout12.size() != 0 - { - let ptr = alloc::alloc(layout12); - if ptr.is_null() - { - alloc::handle_alloc_error(layout12); - } - ptr - }else {{ - ::core::ptr::null_mut() - }}; - for (i, e) in vec12.into_iter().enumerate() { - let base = result12 as i32 + (i as i32) * 8; - { - let WitValue{ nodes:nodes1, } = e; - let vec11 = nodes1; - let len11 = vec11.len() as i32; - let layout11 = alloc::Layout::from_size_align_unchecked(vec11.len() * 24, 8); - let result11 = if layout11.size() != 0 - { - let ptr = alloc::alloc(layout11); - if ptr.is_null() - { - alloc::handle_alloc_error(layout11); + let mut cleanup_list = _rt::Vec::new(); + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); + let vec0 = function_name; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let vec12 = function_params; + let len12 = vec12.len(); + let layout12 = + _rt::alloc::Layout::from_size_align_unchecked(vec12.len() * 8, 4); + let result12 = if layout12.size() != 0 { + let ptr = _rt::alloc::alloc(layout12).cast::(); + if ptr.is_null() { + _rt::alloc::handle_alloc_error(layout12); } ptr - }else {{ - ::core::ptr::null_mut() - }}; - for (i, e) in vec11.into_iter().enumerate() { - let base = result11 as i32 + (i as i32) * 24; + } else { + { + ::core::ptr::null_mut() + } + }; + for (i, e) in vec12.into_iter().enumerate() { + let base = result12.add(i * 8); { - match e { - WitNode::RecordValue(e) => { - *((base + 0) as *mut u8) = (0i32) as u8; - let vec2 = e; - let ptr2 = vec2.as_ptr() as i32; - let len2 = vec2.len() as i32; - *((base + 12) as *mut i32) = len2; - *((base + 8) as *mut i32) = ptr2; - }, - WitNode::VariantValue(e) => { - *((base + 0) as *mut u8) = (1i32) as u8; - let (t3_0, t3_1, ) = e; - *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(t3_0); - match t3_1 { - Some(e) => { - *((base + 12) as *mut u8) = (1i32) as u8; - *((base + 16) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - None => { - { - *((base + 12) as *mut u8) = (0i32) as u8; - } - }, - };}, - WitNode::EnumValue(e) => { - *((base + 0) as *mut u8) = (2i32) as u8; - *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - WitNode::FlagsValue(e) => { - *((base + 0) as *mut u8) = (3i32) as u8; - let vec4 = e; - let len4 = vec4.len() as i32; - let layout4 = alloc::Layout::from_size_align_unchecked(vec4.len() * 1, 1); - let result4 = if layout4.size() != 0 + let WitValue { nodes: nodes1 } = e; + let vec11 = nodes1; + let len11 = vec11.len(); + let layout11 = _rt::alloc::Layout::from_size_align_unchecked( + vec11.len() * 24, + 8, + ); + let result11 = if layout11.size() != 0 { + let ptr = _rt::alloc::alloc(layout11).cast::(); + if ptr.is_null() { + _rt::alloc::handle_alloc_error(layout11); + } + ptr + } else { { - let ptr = alloc::alloc(layout4); - if ptr.is_null() - { - alloc::handle_alloc_error(layout4); - } - ptr - }else {{ - ::core::ptr::null_mut() - }}; - for (i, e) in vec4.into_iter().enumerate() { - let base = result4 as i32 + (i as i32) * 1; - { - *((base + 0) as *mut u8) = (match e { true => 1, false => 0 }) as u8; - } + ::core::ptr::null_mut() } - *((base + 12) as *mut i32) = len4; - *((base + 8) as *mut i32) = result4 as i32; - cleanup_list.extend_from_slice(&[(result4, layout4),]); - }, - WitNode::TupleValue(e) => { - *((base + 0) as *mut u8) = (4i32) as u8; - let vec5 = e; - let ptr5 = vec5.as_ptr() as i32; - let len5 = vec5.len() as i32; - *((base + 12) as *mut i32) = len5; - *((base + 8) as *mut i32) = ptr5; - }, - WitNode::ListValue(e) => { - *((base + 0) as *mut u8) = (5i32) as u8; - let vec6 = e; - let ptr6 = vec6.as_ptr() as i32; - let len6 = vec6.len() as i32; - *((base + 12) as *mut i32) = len6; - *((base + 8) as *mut i32) = ptr6; - }, - WitNode::OptionValue(e) => { - *((base + 0) as *mut u8) = (6i32) as u8; - match e { - Some(e) => { - *((base + 8) as *mut u8) = (1i32) as u8; - *((base + 12) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - None => { - { - *((base + 8) as *mut u8) = (0i32) as u8; - } - }, - };}, - WitNode::ResultValue(e) => { - *((base + 0) as *mut u8) = (7i32) as u8; - match e { - Ok(e) => { { - *((base + 8) as *mut u8) = (0i32) as u8; - match e { - Some(e) => { - *((base + 12) as *mut u8) = (1i32) as u8; - *((base + 16) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - None => { - { - *((base + 12) as *mut u8) = (0i32) as u8; - } - }, - };} }, - Err(e) => { { - *((base + 8) as *mut u8) = (1i32) as u8; - match e { - Some(e) => { - *((base + 12) as *mut u8) = (1i32) as u8; - *((base + 16) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - None => { - { - *((base + 12) as *mut u8) = (0i32) as u8; + }; + for (i, e) in vec11.into_iter().enumerate() { + let base = result11.add(i * 24); + { + match e { + WitNode::RecordValue(e) => { + *base.add(0).cast::() = (0i32) as u8; + let vec2 = e; + let ptr2 = vec2.as_ptr().cast::(); + let len2 = vec2.len(); + *base.add(12).cast::() = len2; + *base.add(8).cast::<*mut u8>() = ptr2.cast_mut(); + } + WitNode::VariantValue(e) => { + *base.add(0).cast::() = (1i32) as u8; + let (t3_0, t3_1) = e; + *base.add(8).cast::() = _rt::as_i32(t3_0); + match t3_1 { + Some(e) => { + *base.add(12).cast::() = (1i32) as u8; + *base.add(16).cast::() = + _rt::as_i32(e); + } + None => { + *base.add(12).cast::() = (0i32) as u8; + } + }; + } + WitNode::EnumValue(e) => { + *base.add(0).cast::() = (2i32) as u8; + *base.add(8).cast::() = _rt::as_i32(e); + } + WitNode::FlagsValue(e) => { + *base.add(0).cast::() = (3i32) as u8; + let vec4 = e; + let len4 = vec4.len(); + let layout4 = + _rt::alloc::Layout::from_size_align_unchecked( + vec4.len() * 1, + 1, + ); + let result4 = if layout4.size() != 0 { + let ptr = + _rt::alloc::alloc(layout4).cast::(); + if ptr.is_null() { + _rt::alloc::handle_alloc_error(layout4); + } + ptr + } else { + { + ::core::ptr::null_mut() + } + }; + for (i, e) in vec4.into_iter().enumerate() { + let base = result4.add(i * 1); + { + *base.add(0).cast::() = (match e { + true => 1, + false => 0, + }) + as u8; + } } - }, - };} }, - };}, - WitNode::PrimU8(e) => { - *((base + 0) as *mut u8) = (8i32) as u8; - *((base + 8) as *mut u8) = (wit_bindgen::rt::as_i32(e)) as u8; - }, - WitNode::PrimU16(e) => { - *((base + 0) as *mut u8) = (9i32) as u8; - *((base + 8) as *mut u16) = (wit_bindgen::rt::as_i32(e)) as u16; - }, - WitNode::PrimU32(e) => { - *((base + 0) as *mut u8) = (10i32) as u8; - *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - WitNode::PrimU64(e) => { - *((base + 0) as *mut u8) = (11i32) as u8; - *((base + 8) as *mut i64) = wit_bindgen::rt::as_i64(e); - }, - WitNode::PrimS8(e) => { - *((base + 0) as *mut u8) = (12i32) as u8; - *((base + 8) as *mut u8) = (wit_bindgen::rt::as_i32(e)) as u8; - }, - WitNode::PrimS16(e) => { - *((base + 0) as *mut u8) = (13i32) as u8; - *((base + 8) as *mut u16) = (wit_bindgen::rt::as_i32(e)) as u16; - }, - WitNode::PrimS32(e) => { - *((base + 0) as *mut u8) = (14i32) as u8; - *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - WitNode::PrimS64(e) => { - *((base + 0) as *mut u8) = (15i32) as u8; - *((base + 8) as *mut i64) = wit_bindgen::rt::as_i64(e); - }, - WitNode::PrimFloat32(e) => { - *((base + 0) as *mut u8) = (16i32) as u8; - *((base + 8) as *mut f32) = wit_bindgen::rt::as_f32(e); - }, - WitNode::PrimFloat64(e) => { - *((base + 0) as *mut u8) = (17i32) as u8; - *((base + 8) as *mut f64) = wit_bindgen::rt::as_f64(e); - }, - WitNode::PrimChar(e) => { - *((base + 0) as *mut u8) = (18i32) as u8; - *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - WitNode::PrimBool(e) => { - *((base + 0) as *mut u8) = (19i32) as u8; - *((base + 8) as *mut u8) = (match e { true => 1, false => 0 }) as u8; - }, - WitNode::PrimString(e) => { - *((base + 0) as *mut u8) = (20i32) as u8; - let vec7 = e; - let ptr7 = vec7.as_ptr() as i32; - let len7 = vec7.len() as i32; - *((base + 12) as *mut i32) = len7; - *((base + 8) as *mut i32) = ptr7; - }, - WitNode::Handle(e) => { - *((base + 0) as *mut u8) = (21i32) as u8; - let (t8_0, t8_1, ) = e; - let Uri{ value:value9, } = t8_0; - let vec10 = value9; - let ptr10 = vec10.as_ptr() as i32; - let len10 = vec10.len() as i32; - *((base + 12) as *mut i32) = len10; - *((base + 8) as *mut i32) = ptr10; - *((base + 16) as *mut i64) = wit_bindgen::rt::as_i64(t8_1); - }, + *base.add(12).cast::() = len4; + *base.add(8).cast::<*mut u8>() = result4; + cleanup_list + .extend_from_slice(&[(result4, layout4)]); + } + WitNode::TupleValue(e) => { + *base.add(0).cast::() = (4i32) as u8; + let vec5 = e; + let ptr5 = vec5.as_ptr().cast::(); + let len5 = vec5.len(); + *base.add(12).cast::() = len5; + *base.add(8).cast::<*mut u8>() = ptr5.cast_mut(); + } + WitNode::ListValue(e) => { + *base.add(0).cast::() = (5i32) as u8; + let vec6 = e; + let ptr6 = vec6.as_ptr().cast::(); + let len6 = vec6.len(); + *base.add(12).cast::() = len6; + *base.add(8).cast::<*mut u8>() = ptr6.cast_mut(); + } + WitNode::OptionValue(e) => { + *base.add(0).cast::() = (6i32) as u8; + match e { + Some(e) => { + *base.add(8).cast::() = (1i32) as u8; + *base.add(12).cast::() = + _rt::as_i32(e); + } + None => { + *base.add(8).cast::() = (0i32) as u8; + } + }; + } + WitNode::ResultValue(e) => { + *base.add(0).cast::() = (7i32) as u8; + match e { + Ok(e) => { + *base.add(8).cast::() = (0i32) as u8; + match e { + Some(e) => { + *base.add(12).cast::() = + (1i32) as u8; + *base.add(16).cast::() = + _rt::as_i32(e); + } + None => { + *base.add(12).cast::() = + (0i32) as u8; + } + }; + } + Err(e) => { + *base.add(8).cast::() = (1i32) as u8; + match e { + Some(e) => { + *base.add(12).cast::() = + (1i32) as u8; + *base.add(16).cast::() = + _rt::as_i32(e); + } + None => { + *base.add(12).cast::() = + (0i32) as u8; + } + }; + } + }; + } + WitNode::PrimU8(e) => { + *base.add(0).cast::() = (8i32) as u8; + *base.add(8).cast::() = (_rt::as_i32(e)) as u8; + } + WitNode::PrimU16(e) => { + *base.add(0).cast::() = (9i32) as u8; + *base.add(8).cast::() = + (_rt::as_i32(e)) as u16; + } + WitNode::PrimU32(e) => { + *base.add(0).cast::() = (10i32) as u8; + *base.add(8).cast::() = _rt::as_i32(e); + } + WitNode::PrimU64(e) => { + *base.add(0).cast::() = (11i32) as u8; + *base.add(8).cast::() = _rt::as_i64(e); + } + WitNode::PrimS8(e) => { + *base.add(0).cast::() = (12i32) as u8; + *base.add(8).cast::() = (_rt::as_i32(e)) as u8; + } + WitNode::PrimS16(e) => { + *base.add(0).cast::() = (13i32) as u8; + *base.add(8).cast::() = + (_rt::as_i32(e)) as u16; + } + WitNode::PrimS32(e) => { + *base.add(0).cast::() = (14i32) as u8; + *base.add(8).cast::() = _rt::as_i32(e); + } + WitNode::PrimS64(e) => { + *base.add(0).cast::() = (15i32) as u8; + *base.add(8).cast::() = _rt::as_i64(e); + } + WitNode::PrimFloat32(e) => { + *base.add(0).cast::() = (16i32) as u8; + *base.add(8).cast::() = _rt::as_f32(e); + } + WitNode::PrimFloat64(e) => { + *base.add(0).cast::() = (17i32) as u8; + *base.add(8).cast::() = _rt::as_f64(e); + } + WitNode::PrimChar(e) => { + *base.add(0).cast::() = (18i32) as u8; + *base.add(8).cast::() = _rt::as_i32(e); + } + WitNode::PrimBool(e) => { + *base.add(0).cast::() = (19i32) as u8; + *base.add(8).cast::() = (match e { + true => 1, + false => 0, + }) + as u8; + } + WitNode::PrimString(e) => { + *base.add(0).cast::() = (20i32) as u8; + let vec7 = e; + let ptr7 = vec7.as_ptr().cast::(); + let len7 = vec7.len(); + *base.add(12).cast::() = len7; + *base.add(8).cast::<*mut u8>() = ptr7.cast_mut(); + } + WitNode::Handle(e) => { + *base.add(0).cast::() = (21i32) as u8; + let (t8_0, t8_1) = e; + let Uri { value: value9 } = t8_0; + let vec10 = value9; + let ptr10 = vec10.as_ptr().cast::(); + let len10 = vec10.len(); + *base.add(12).cast::() = len10; + *base.add(8).cast::<*mut u8>() = ptr10.cast_mut(); + *base.add(16).cast::() = _rt::as_i64(t8_1); + } } - } } - *((base + 4) as *mut i32) = len11; - *((base + 0) as *mut i32) = result11 as i32; - cleanup_list.extend_from_slice(&[(result11, layout11),]); - } - } - let ptr13 = ret_area.as_mut_ptr() as i32; - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "golem:rpc/types@0.1.0")] - extern "C" { - #[link_name = "[method]wasm-rpc.invoke"] - fn wit_import(_: i32, _: i32, _: i32, _: i32, _: i32, _: i32, ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: i32, _: i32, _: i32, _: i32, _: i32, ){ unreachable!() } - wit_import((self).handle() as i32, ptr0, len0, result12 as i32, len12, ptr13); - let l14 = i32::from(*((ptr13 + 0) as *const u8)); - if layout12.size() != 0 { - alloc::dealloc(result12, layout12); } - for (ptr, layout) in cleanup_list { - - if layout.size() != 0 { - - alloc::dealloc(ptr, layout); - - } - - } - match l14 { - 0 => { - let e = (); - Ok(e) - } - 1 => { - let e = { - let l15 = i32::from(*((ptr13 + 4) as *const u8)); - let v28 = match l15 { + *base.add(4).cast::() = len11; + *base.add(0).cast::<*mut u8>() = result11; + cleanup_list.extend_from_slice(&[(result11, layout11)]); + } + } + let ptr13 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "golem:rpc/types@0.1.0")] + extern "C" { + #[link_name = "[method]wasm-rpc.invoke"] + fn wit_import( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + _: usize, + _: *mut u8, + ); + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + _: usize, + _: *mut u8, + ) { + unreachable!() + } + wit_import( + (self).handle() as i32, + ptr0.cast_mut(), + len0, + result12, + len12, + ptr13, + ); + let l14 = i32::from(*ptr13.add(0).cast::()); + if layout12.size() != 0 { + _rt::alloc::dealloc(result12.cast(), layout12); + } + for (ptr, layout) in cleanup_list { + if layout.size() != 0 { + _rt::alloc::dealloc(ptr.cast(), layout); + } + } + match l14 { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = { + let l15 = i32::from(*ptr13.add(4).cast::()); + let v28 = match l15 { 0 => { - let e28 = { - let l16 = *((ptr13 + 8) as *const i32); - let l17 = *((ptr13 + 12) as *const i32); - let len18 = l17 as usize; - let bytes18 = Vec::from_raw_parts(l16 as *mut _, len18, len18); - - wit_bindgen::rt::string_lift(bytes18) - }; - RpcError::ProtocolError(e28) + let e28 = { + let l16 = *ptr13.add(8).cast::<*mut u8>(); + let l17 = *ptr13.add(12).cast::(); + let len18 = l17; + let bytes18 = _rt::Vec::from_raw_parts( + l16.cast(), + len18, + len18, + ); + + _rt::string_lift(bytes18) + }; + RpcError::ProtocolError(e28) } 1 => { - let e28 = { - let l19 = *((ptr13 + 8) as *const i32); - let l20 = *((ptr13 + 12) as *const i32); - let len21 = l20 as usize; - let bytes21 = Vec::from_raw_parts(l19 as *mut _, len21, len21); - - wit_bindgen::rt::string_lift(bytes21) - }; - RpcError::Denied(e28) + let e28 = { + let l19 = *ptr13.add(8).cast::<*mut u8>(); + let l20 = *ptr13.add(12).cast::(); + let len21 = l20; + let bytes21 = _rt::Vec::from_raw_parts( + l19.cast(), + len21, + len21, + ); + + _rt::string_lift(bytes21) + }; + RpcError::Denied(e28) } 2 => { - let e28 = { - let l22 = *((ptr13 + 8) as *const i32); - let l23 = *((ptr13 + 12) as *const i32); - let len24 = l23 as usize; - let bytes24 = Vec::from_raw_parts(l22 as *mut _, len24, len24); - - wit_bindgen::rt::string_lift(bytes24) - }; - RpcError::NotFound(e28) + let e28 = { + let l22 = *ptr13.add(8).cast::<*mut u8>(); + let l23 = *ptr13.add(12).cast::(); + let len24 = l23; + let bytes24 = _rt::Vec::from_raw_parts( + l22.cast(), + len24, + len24, + ); + + _rt::string_lift(bytes24) + }; + RpcError::NotFound(e28) } n => { - debug_assert_eq!(n, 3, "invalid enum discriminant"); - let e28 = { - let l25 = *((ptr13 + 8) as *const i32); - let l26 = *((ptr13 + 12) as *const i32); - let len27 = l26 as usize; - let bytes27 = Vec::from_raw_parts(l25 as *mut _, len27, len27); - - wit_bindgen::rt::string_lift(bytes27) - }; - RpcError::RemoteInternalError(e28) + debug_assert_eq!(n, 3, "invalid enum discriminant"); + let e28 = { + let l25 = *ptr13.add(8).cast::<*mut u8>(); + let l26 = *ptr13.add(12).cast::(); + let len27 = l26; + let bytes27 = _rt::Vec::from_raw_parts( + l25.cast(), + len27, + len27, + ); + + _rt::string_lift(bytes27) + }; + RpcError::RemoteInternalError(e28) } - }; - - v28 }; - Err(e) - } - _ => wit_bindgen::rt::invalid_enum_discriminant(), - } - } + + v28 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl WasmRpc { + #[allow(unused_unsafe, clippy::all)] + pub fn async_invoke_and_await( + &self, + function_name: &str, + function_params: &[WitValue], + ) -> FutureInvokeResult { + unsafe { + let mut cleanup_list = _rt::Vec::new(); + let vec0 = function_name; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let vec12 = function_params; + let len12 = vec12.len(); + let layout12 = + _rt::alloc::Layout::from_size_align_unchecked(vec12.len() * 8, 4); + let result12 = if layout12.size() != 0 { + let ptr = _rt::alloc::alloc(layout12).cast::(); + if ptr.is_null() { + _rt::alloc::handle_alloc_error(layout12); + } + ptr + } else { + { + ::core::ptr::null_mut() } - } - impl WasmRpc { - #[allow(unused_unsafe, clippy::all)] - pub fn async_invoke_and_await(&self,function_name: &str,function_params: &[WitValue],) -> FutureInvokeResult{ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - let mut cleanup_list = Vec::new(); - let vec0 = function_name; - let ptr0 = vec0.as_ptr() as i32; - let len0 = vec0.len() as i32; - let vec12 = function_params; - let len12 = vec12.len() as i32; - let layout12 = alloc::Layout::from_size_align_unchecked(vec12.len() * 8, 4); - let result12 = if layout12.size() != 0 - { - let ptr = alloc::alloc(layout12); - if ptr.is_null() - { - alloc::handle_alloc_error(layout12); - } - ptr - }else {{ - ::core::ptr::null_mut() - }}; - for (i, e) in vec12.into_iter().enumerate() { - let base = result12 as i32 + (i as i32) * 8; - { - let WitValue{ nodes:nodes1, } = e; - let vec11 = nodes1; - let len11 = vec11.len() as i32; - let layout11 = alloc::Layout::from_size_align_unchecked(vec11.len() * 24, 8); - let result11 = if layout11.size() != 0 + }; + for (i, e) in vec12.into_iter().enumerate() { + let base = result12.add(i * 8); + { + let WitValue { nodes: nodes1 } = e; + let vec11 = nodes1; + let len11 = vec11.len(); + let layout11 = _rt::alloc::Layout::from_size_align_unchecked( + vec11.len() * 24, + 8, + ); + let result11 = if layout11.size() != 0 { + let ptr = _rt::alloc::alloc(layout11).cast::(); + if ptr.is_null() { + _rt::alloc::handle_alloc_error(layout11); + } + ptr + } else { + { + ::core::ptr::null_mut() + } + }; + for (i, e) in vec11.into_iter().enumerate() { + let base = result11.add(i * 24); { - let ptr = alloc::alloc(layout11); - if ptr.is_null() - { - alloc::handle_alloc_error(layout11); - } - ptr - }else {{ - ::core::ptr::null_mut() - }}; - for (i, e) in vec11.into_iter().enumerate() { - let base = result11 as i32 + (i as i32) * 24; - { match e { - WitNode::RecordValue(e) => { - *((base + 0) as *mut u8) = (0i32) as u8; - let vec2 = e; - let ptr2 = vec2.as_ptr() as i32; - let len2 = vec2.len() as i32; - *((base + 12) as *mut i32) = len2; - *((base + 8) as *mut i32) = ptr2; - }, - WitNode::VariantValue(e) => { - *((base + 0) as *mut u8) = (1i32) as u8; - let (t3_0, t3_1, ) = e; - *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(t3_0); - match t3_1 { - Some(e) => { - *((base + 12) as *mut u8) = (1i32) as u8; - *((base + 16) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - None => { - { - *((base + 12) as *mut u8) = (0i32) as u8; - } - }, - };}, + WitNode::RecordValue(e) => { + *base.add(0).cast::() = (0i32) as u8; + let vec2 = e; + let ptr2 = vec2.as_ptr().cast::(); + let len2 = vec2.len(); + *base.add(12).cast::() = len2; + *base.add(8).cast::<*mut u8>() = ptr2.cast_mut(); + } + WitNode::VariantValue(e) => { + *base.add(0).cast::() = (1i32) as u8; + let (t3_0, t3_1) = e; + *base.add(8).cast::() = _rt::as_i32(t3_0); + match t3_1 { + Some(e) => { + *base.add(12).cast::() = (1i32) as u8; + *base.add(16).cast::() = + _rt::as_i32(e); + } + None => { + *base.add(12).cast::() = (0i32) as u8; + } + }; + } WitNode::EnumValue(e) => { - *((base + 0) as *mut u8) = (2i32) as u8; - *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, + *base.add(0).cast::() = (2i32) as u8; + *base.add(8).cast::() = _rt::as_i32(e); + } WitNode::FlagsValue(e) => { - *((base + 0) as *mut u8) = (3i32) as u8; - let vec4 = e; - let len4 = vec4.len() as i32; - let layout4 = alloc::Layout::from_size_align_unchecked(vec4.len() * 1, 1); - let result4 = if layout4.size() != 0 - { - let ptr = alloc::alloc(layout4); - if ptr.is_null() - { - alloc::handle_alloc_error(layout4); - } - ptr - }else {{ - ::core::ptr::null_mut() - }}; - for (i, e) in vec4.into_iter().enumerate() { - let base = result4 as i32 + (i as i32) * 1; - { - *((base + 0) as *mut u8) = (match e { true => 1, false => 0 }) as u8; + *base.add(0).cast::() = (3i32) as u8; + let vec4 = e; + let len4 = vec4.len(); + let layout4 = + _rt::alloc::Layout::from_size_align_unchecked( + vec4.len() * 1, + 1, + ); + let result4 = if layout4.size() != 0 { + let ptr = + _rt::alloc::alloc(layout4).cast::(); + if ptr.is_null() { + _rt::alloc::handle_alloc_error(layout4); + } + ptr + } else { + { + ::core::ptr::null_mut() + } + }; + for (i, e) in vec4.into_iter().enumerate() { + let base = result4.add(i * 1); + { + *base.add(0).cast::() = (match e { + true => 1, + false => 0, + }) + as u8; + } } - } - *((base + 12) as *mut i32) = len4; - *((base + 8) as *mut i32) = result4 as i32; - cleanup_list.extend_from_slice(&[(result4, layout4),]); - }, + *base.add(12).cast::() = len4; + *base.add(8).cast::<*mut u8>() = result4; + cleanup_list + .extend_from_slice(&[(result4, layout4)]); + } WitNode::TupleValue(e) => { - *((base + 0) as *mut u8) = (4i32) as u8; - let vec5 = e; - let ptr5 = vec5.as_ptr() as i32; - let len5 = vec5.len() as i32; - *((base + 12) as *mut i32) = len5; - *((base + 8) as *mut i32) = ptr5; - }, + *base.add(0).cast::() = (4i32) as u8; + let vec5 = e; + let ptr5 = vec5.as_ptr().cast::(); + let len5 = vec5.len(); + *base.add(12).cast::() = len5; + *base.add(8).cast::<*mut u8>() = ptr5.cast_mut(); + } WitNode::ListValue(e) => { - *((base + 0) as *mut u8) = (5i32) as u8; - let vec6 = e; - let ptr6 = vec6.as_ptr() as i32; - let len6 = vec6.len() as i32; - *((base + 12) as *mut i32) = len6; - *((base + 8) as *mut i32) = ptr6; - }, + *base.add(0).cast::() = (5i32) as u8; + let vec6 = e; + let ptr6 = vec6.as_ptr().cast::(); + let len6 = vec6.len(); + *base.add(12).cast::() = len6; + *base.add(8).cast::<*mut u8>() = ptr6.cast_mut(); + } WitNode::OptionValue(e) => { - *((base + 0) as *mut u8) = (6i32) as u8; - match e { - Some(e) => { - *((base + 8) as *mut u8) = (1i32) as u8; - *((base + 12) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - None => { - { - *((base + 8) as *mut u8) = (0i32) as u8; - } - }, - };}, - WitNode::ResultValue(e) => { - *((base + 0) as *mut u8) = (7i32) as u8; + *base.add(0).cast::() = (6i32) as u8; match e { - Ok(e) => { { - *((base + 8) as *mut u8) = (0i32) as u8; - match e { - Some(e) => { - *((base + 12) as *mut u8) = (1i32) as u8; - *((base + 16) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - None => { - { - *((base + 12) as *mut u8) = (0i32) as u8; - } - }, - };} }, - Err(e) => { { - *((base + 8) as *mut u8) = (1i32) as u8; - match e { - Some(e) => { - *((base + 12) as *mut u8) = (1i32) as u8; - *((base + 16) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - None => { - { - *((base + 12) as *mut u8) = (0i32) as u8; - } - }, - };} }, - };}, - WitNode::PrimU8(e) => { - *((base + 0) as *mut u8) = (8i32) as u8; - *((base + 8) as *mut u8) = (wit_bindgen::rt::as_i32(e)) as u8; - }, - WitNode::PrimU16(e) => { - *((base + 0) as *mut u8) = (9i32) as u8; - *((base + 8) as *mut u16) = (wit_bindgen::rt::as_i32(e)) as u16; - }, - WitNode::PrimU32(e) => { - *((base + 0) as *mut u8) = (10i32) as u8; - *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - WitNode::PrimU64(e) => { - *((base + 0) as *mut u8) = (11i32) as u8; - *((base + 8) as *mut i64) = wit_bindgen::rt::as_i64(e); - }, - WitNode::PrimS8(e) => { - *((base + 0) as *mut u8) = (12i32) as u8; - *((base + 8) as *mut u8) = (wit_bindgen::rt::as_i32(e)) as u8; - }, - WitNode::PrimS16(e) => { - *((base + 0) as *mut u8) = (13i32) as u8; - *((base + 8) as *mut u16) = (wit_bindgen::rt::as_i32(e)) as u16; - }, - WitNode::PrimS32(e) => { - *((base + 0) as *mut u8) = (14i32) as u8; - *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - WitNode::PrimS64(e) => { - *((base + 0) as *mut u8) = (15i32) as u8; - *((base + 8) as *mut i64) = wit_bindgen::rt::as_i64(e); - }, - WitNode::PrimFloat32(e) => { - *((base + 0) as *mut u8) = (16i32) as u8; - *((base + 8) as *mut f32) = wit_bindgen::rt::as_f32(e); - }, - WitNode::PrimFloat64(e) => { - *((base + 0) as *mut u8) = (17i32) as u8; - *((base + 8) as *mut f64) = wit_bindgen::rt::as_f64(e); - }, - WitNode::PrimChar(e) => { - *((base + 0) as *mut u8) = (18i32) as u8; - *((base + 8) as *mut i32) = wit_bindgen::rt::as_i32(e); - }, - WitNode::PrimBool(e) => { - *((base + 0) as *mut u8) = (19i32) as u8; - *((base + 8) as *mut u8) = (match e { true => 1, false => 0 }) as u8; - }, - WitNode::PrimString(e) => { - *((base + 0) as *mut u8) = (20i32) as u8; - let vec7 = e; - let ptr7 = vec7.as_ptr() as i32; - let len7 = vec7.len() as i32; - *((base + 12) as *mut i32) = len7; - *((base + 8) as *mut i32) = ptr7; - }, - WitNode::Handle(e) => { - *((base + 0) as *mut u8) = (21i32) as u8; - let (t8_0, t8_1, ) = e; - let Uri{ value:value9, } = t8_0; - let vec10 = value9; - let ptr10 = vec10.as_ptr() as i32; - let len10 = vec10.len() as i32; - *((base + 12) as *mut i32) = len10; - *((base + 8) as *mut i32) = ptr10; - *((base + 16) as *mut i64) = wit_bindgen::rt::as_i64(t8_1); - }, - } - } - } - *((base + 4) as *mut i32) = len11; - *((base + 0) as *mut i32) = result11 as i32; - cleanup_list.extend_from_slice(&[(result11, layout11),]); - } - } - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "golem:rpc/types@0.1.0")] - extern "C" { - #[link_name = "[method]wasm-rpc.async-invoke-and-await"] - fn wit_import(_: i32, _: i32, _: i32, _: i32, _: i32, ) -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: i32, _: i32, _: i32, _: i32, ) -> i32{ unreachable!() } - let ret = wit_import((self).handle() as i32, ptr0, len0, result12 as i32, len12); - if layout12.size() != 0 { - alloc::dealloc(result12, layout12); - } - for (ptr, layout) in cleanup_list { - - if layout.size() != 0 { - - alloc::dealloc(ptr, layout); - - } - - } - FutureInvokeResult::from_handle(ret as u32) - } - } - } - impl FutureInvokeResult { - #[allow(unused_unsafe, clippy::all)] - pub fn subscribe(&self,) -> Pollable{ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "golem:rpc/types@0.1.0")] - extern "C" { - #[link_name = "[method]future-invoke-result.subscribe"] - fn wit_import(_: i32, ) -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, ) -> i32{ unreachable!() } - let ret = wit_import((self).handle() as i32); - super::super::super::wasi::io::poll::Pollable::from_handle(ret as u32) - } - } - } - impl FutureInvokeResult { - #[allow(unused_unsafe, clippy::all)] - pub fn get(&self,) -> Result{ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - - #[repr(align(4))] - struct RetArea([u8; 16]); - let mut ret_area = ::core::mem::MaybeUninit::::uninit(); - let ptr0 = ret_area.as_mut_ptr() as i32; - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "golem:rpc/types@0.1.0")] - extern "C" { - #[link_name = "[method]future-invoke-result.get"] - fn wit_import(_: i32, _: i32, ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: i32, ){ unreachable!() } - wit_import((self).handle() as i32, ptr0); - let l1 = i32::from(*((ptr0 + 0) as *const u8)); - match l1 { - 0 => { - let e = { - let l2 = *((ptr0 + 4) as *const i32); - let l3 = *((ptr0 + 8) as *const i32); - let base49 = l2; - let len49 = l3; - let mut result49 = Vec::with_capacity(len49 as usize); - for i in 0..len49 { - let base = base49 + i * 24; - let e49 = { - let l4 = i32::from(*((base + 0) as *const u8)); - let v48 = match l4 { - 0 => { - let e48 = { - let l5 = *((base + 8) as *const i32); - let l6 = *((base + 12) as *const i32); - let len7 = l6 as usize; - - Vec::from_raw_parts(l5 as *mut _, len7, len7) - }; - WitNode::RecordValue(e48) - } - 1 => { - let e48 = { - let l8 = *((base + 8) as *const i32); - let l9 = i32::from(*((base + 12) as *const u8)); - - (l8 as u32, match l9 { - 0 => None, - 1 => { - let e = { - let l10 = *((base + 16) as *const i32); - - l10 - }; - Some(e) + Some(e) => { + *base.add(8).cast::() = (1i32) as u8; + *base.add(12).cast::() = + _rt::as_i32(e); + } + None => { + *base.add(8).cast::() = (0i32) as u8; + } + }; + } + WitNode::ResultValue(e) => { + *base.add(0).cast::() = (7i32) as u8; + match e { + Ok(e) => { + *base.add(8).cast::() = (0i32) as u8; + match e { + Some(e) => { + *base.add(12).cast::() = + (1i32) as u8; + *base.add(16).cast::() = + _rt::as_i32(e); + } + None => { + *base.add(12).cast::() = + (0i32) as u8; } - _ => wit_bindgen::rt::invalid_enum_discriminant(), - }) - }; - WitNode::VariantValue(e48) - } - 2 => { - let e48 = { - let l11 = *((base + 8) as *const i32); - - l11 as u32 - }; - WitNode::EnumValue(e48) - } - 3 => { - let e48 = { - let l12 = *((base + 8) as *const i32); - let l13 = *((base + 12) as *const i32); - let base15 = l12; - let len15 = l13; - let mut result15 = Vec::with_capacity(len15 as usize); - for i in 0..len15 { - let base = base15 + i * 1; - let e15 = { - let l14 = i32::from(*((base + 0) as *const u8)); - - wit_bindgen::rt::bool_lift(l14 as u8) - }; - result15.push(e15); - } - wit_bindgen::rt::dealloc(base15, (len15 as usize) * 1, 1); - - result15 - }; - WitNode::FlagsValue(e48) - } - 4 => { - let e48 = { - let l16 = *((base + 8) as *const i32); - let l17 = *((base + 12) as *const i32); - let len18 = l17 as usize; - - Vec::from_raw_parts(l16 as *mut _, len18, len18) - }; - WitNode::TupleValue(e48) - } - 5 => { - let e48 = { - let l19 = *((base + 8) as *const i32); - let l20 = *((base + 12) as *const i32); - let len21 = l20 as usize; - - Vec::from_raw_parts(l19 as *mut _, len21, len21) }; - WitNode::ListValue(e48) - } - 6 => { - let e48 = { - let l22 = i32::from(*((base + 8) as *const u8)); - - match l22 { - 0 => None, - 1 => { - let e = { - let l23 = *((base + 12) as *const i32); - - l23 - }; - Some(e) + } + Err(e) => { + *base.add(8).cast::() = (1i32) as u8; + match e { + Some(e) => { + *base.add(12).cast::() = + (1i32) as u8; + *base.add(16).cast::() = + _rt::as_i32(e); + } + None => { + *base.add(12).cast::() = + (0i32) as u8; } - _ => wit_bindgen::rt::invalid_enum_discriminant(), - } }; - WitNode::OptionValue(e48) - } - 7 => { - let e48 = { - let l24 = i32::from(*((base + 8) as *const u8)); - - match l24 { + } + }; + } + WitNode::PrimU8(e) => { + *base.add(0).cast::() = (8i32) as u8; + *base.add(8).cast::() = (_rt::as_i32(e)) as u8; + } + WitNode::PrimU16(e) => { + *base.add(0).cast::() = (9i32) as u8; + *base.add(8).cast::() = + (_rt::as_i32(e)) as u16; + } + WitNode::PrimU32(e) => { + *base.add(0).cast::() = (10i32) as u8; + *base.add(8).cast::() = _rt::as_i32(e); + } + WitNode::PrimU64(e) => { + *base.add(0).cast::() = (11i32) as u8; + *base.add(8).cast::() = _rt::as_i64(e); + } + WitNode::PrimS8(e) => { + *base.add(0).cast::() = (12i32) as u8; + *base.add(8).cast::() = (_rt::as_i32(e)) as u8; + } + WitNode::PrimS16(e) => { + *base.add(0).cast::() = (13i32) as u8; + *base.add(8).cast::() = + (_rt::as_i32(e)) as u16; + } + WitNode::PrimS32(e) => { + *base.add(0).cast::() = (14i32) as u8; + *base.add(8).cast::() = _rt::as_i32(e); + } + WitNode::PrimS64(e) => { + *base.add(0).cast::() = (15i32) as u8; + *base.add(8).cast::() = _rt::as_i64(e); + } + WitNode::PrimFloat32(e) => { + *base.add(0).cast::() = (16i32) as u8; + *base.add(8).cast::() = _rt::as_f32(e); + } + WitNode::PrimFloat64(e) => { + *base.add(0).cast::() = (17i32) as u8; + *base.add(8).cast::() = _rt::as_f64(e); + } + WitNode::PrimChar(e) => { + *base.add(0).cast::() = (18i32) as u8; + *base.add(8).cast::() = _rt::as_i32(e); + } + WitNode::PrimBool(e) => { + *base.add(0).cast::() = (19i32) as u8; + *base.add(8).cast::() = (match e { + true => 1, + false => 0, + }) + as u8; + } + WitNode::PrimString(e) => { + *base.add(0).cast::() = (20i32) as u8; + let vec7 = e; + let ptr7 = vec7.as_ptr().cast::(); + let len7 = vec7.len(); + *base.add(12).cast::() = len7; + *base.add(8).cast::<*mut u8>() = ptr7.cast_mut(); + } + WitNode::Handle(e) => { + *base.add(0).cast::() = (21i32) as u8; + let (t8_0, t8_1) = e; + let Uri { value: value9 } = t8_0; + let vec10 = value9; + let ptr10 = vec10.as_ptr().cast::(); + let len10 = vec10.len(); + *base.add(12).cast::() = len10; + *base.add(8).cast::<*mut u8>() = ptr10.cast_mut(); + *base.add(16).cast::() = _rt::as_i64(t8_1); + } + } + } + } + *base.add(4).cast::() = len11; + *base.add(0).cast::<*mut u8>() = result11; + cleanup_list.extend_from_slice(&[(result11, layout11)]); + } + } + + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "golem:rpc/types@0.1.0")] + extern "C" { + #[link_name = "[method]wasm-rpc.async-invoke-and-await"] + fn wit_import( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + _: usize, + ) -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8, _: usize) -> i32 { + unreachable!() + } + let ret = wit_import( + (self).handle() as i32, + ptr0.cast_mut(), + len0, + result12, + len12, + ); + if layout12.size() != 0 { + _rt::alloc::dealloc(result12.cast(), layout12); + } + for (ptr, layout) in cleanup_list { + if layout.size() != 0 { + _rt::alloc::dealloc(ptr.cast(), layout); + } + } + FutureInvokeResult::from_handle(ret as u32) + } + } + } + impl FutureInvokeResult { + #[allow(unused_unsafe, clippy::all)] + pub fn subscribe(&self) -> Pollable { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "golem:rpc/types@0.1.0")] + extern "C" { + #[link_name = "[method]future-invoke-result.subscribe"] + fn wit_import(_: i32) -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32); + super::super::super::wasi::io::poll::Pollable::from_handle(ret as u32) + } + } + } + impl FutureInvokeResult { + #[allow(unused_unsafe, clippy::all)] + pub fn get(&self) -> Option> { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 20]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 20]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "golem:rpc/types@0.1.0")] + extern "C" { + #[link_name = "[method]future-invoke-result.get"] + fn wit_import(_: i32, _: *mut u8); + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => None, + 1 => { + let e = { + let l2 = i32::from(*ptr0.add(4).cast::()); + + match l2 { + 0 => { + let e = { + let l3 = *ptr0.add(8).cast::<*mut u8>(); + let l4 = *ptr0.add(12).cast::(); + let base50 = l3; + let len50 = l4; + let mut result50 = _rt::Vec::with_capacity(len50); + for i in 0..len50 { + let base = base50.add(i * 24); + let e50 = { + let l5 = + i32::from(*base.add(0).cast::()); + let v49 = match l5 { 0 => { - let e = { - let l25 = i32::from(*((base + 12) as *const u8)); - - match l25 { + let e49 = { + let l6 = *base + .add(8) + .cast::<*mut u8>(); + let l7 = *base + .add(12) + .cast::(); + let len8 = l7; + + _rt::Vec::from_raw_parts( + l6.cast(), + len8, + len8, + ) + }; + WitNode::RecordValue(e49) + } + 1 => { + let e49 = { + let l9 = + *base.add(8).cast::(); + let l10 = i32::from( + *base.add(12).cast::(), + ); + + (l9 as u32, match l10 { 0 => None, 1 => { let e = { - let l26 = *((base + 16) as *const i32); - - l26 + let l11 = *base.add(16).cast::(); + + l11 }; Some(e) } - _ => wit_bindgen::rt::invalid_enum_discriminant(), - } - }; - Ok(e) + _ => _rt::invalid_enum_discriminant(), + }) + }; + WitNode::VariantValue(e49) } - 1 => { - let e = { - let l27 = i32::from(*((base + 12) as *const u8)); - - match l27 { + 2 => { + let e49 = { + let l12 = + *base.add(8).cast::(); + + l12 as u32 + }; + WitNode::EnumValue(e49) + } + 3 => { + let e49 = { + let l13 = *base + .add(8) + .cast::<*mut u8>(); + let l14 = *base + .add(12) + .cast::(); + let base16 = l13; + let len16 = l14; + let mut result16 = + _rt::Vec::with_capacity( + len16, + ); + for i in 0..len16 { + let base = + base16.add(i * 1); + let e16 = { + let l15 = i32::from( + *base + .add(0) + .cast::(), + ); + + _rt::bool_lift( + l15 as u8, + ) + }; + result16.push(e16); + } + _rt::cabi_dealloc( + base16, + len16 * 1, + 1, + ); + + result16 + }; + WitNode::FlagsValue(e49) + } + 4 => { + let e49 = { + let l17 = *base + .add(8) + .cast::<*mut u8>(); + let l18 = *base + .add(12) + .cast::(); + let len19 = l18; + + _rt::Vec::from_raw_parts( + l17.cast(), + len19, + len19, + ) + }; + WitNode::TupleValue(e49) + } + 5 => { + let e49 = { + let l20 = *base + .add(8) + .cast::<*mut u8>(); + let l21 = *base + .add(12) + .cast::(); + let len22 = l21; + + _rt::Vec::from_raw_parts( + l20.cast(), + len22, + len22, + ) + }; + WitNode::ListValue(e49) + } + 6 => { + let e49 = { + let l23 = i32::from( + *base.add(8).cast::(), + ); + + match l23 { 0 => None, 1 => { let e = { - let l28 = *((base + 16) as *const i32); - - l28 + let l24 = *base.add(12).cast::(); + + l24 }; Some(e) } - _ => wit_bindgen::rt::invalid_enum_discriminant(), + _ => _rt::invalid_enum_discriminant(), } - }; - Err(e) + }; + WitNode::OptionValue(e49) + } + 7 => { + let e49 = { + let l25 = i32::from( + *base.add(8).cast::(), + ); + + match l25 { + 0 => { + let e = { + let l26 = i32::from(*base.add(12).cast::()); + + match l26 { + 0 => None, + 1 => { + let e = { + let l27 = *base.add(16).cast::(); + + l27 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + Ok(e) + } + 1 => { + let e = { + let l28 = i32::from(*base.add(12).cast::()); + + match l28 { + 0 => None, + 1 => { + let e = { + let l29 = *base.add(16).cast::(); + + l29 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + WitNode::ResultValue(e49) + } + 8 => { + let e49 = { + let l30 = i32::from( + *base.add(8).cast::(), + ); + + l30 as u8 + }; + WitNode::PrimU8(e49) + } + 9 => { + let e49 = { + let l31 = i32::from( + *base.add(8).cast::(), + ); + + l31 as u16 + }; + WitNode::PrimU16(e49) + } + 10 => { + let e49 = { + let l32 = + *base.add(8).cast::(); + + l32 as u32 + }; + WitNode::PrimU32(e49) + } + 11 => { + let e49 = { + let l33 = + *base.add(8).cast::(); + + l33 as u64 + }; + WitNode::PrimU64(e49) + } + 12 => { + let e49 = { + let l34 = i32::from( + *base.add(8).cast::(), + ); + + l34 as i8 + }; + WitNode::PrimS8(e49) + } + 13 => { + let e49 = { + let l35 = i32::from( + *base.add(8).cast::(), + ); + + l35 as i16 + }; + WitNode::PrimS16(e49) + } + 14 => { + let e49 = { + let l36 = + *base.add(8).cast::(); + + l36 + }; + WitNode::PrimS32(e49) + } + 15 => { + let e49 = { + let l37 = + *base.add(8).cast::(); + + l37 + }; + WitNode::PrimS64(e49) + } + 16 => { + let e49 = { + let l38 = + *base.add(8).cast::(); + + l38 + }; + WitNode::PrimFloat32(e49) + } + 17 => { + let e49 = { + let l39 = + *base.add(8).cast::(); + + l39 + }; + WitNode::PrimFloat64(e49) + } + 18 => { + let e49 = { + let l40 = + *base.add(8).cast::(); + + _rt::char_lift(l40 as u32) + }; + WitNode::PrimChar(e49) + } + 19 => { + let e49 = { + let l41 = i32::from( + *base.add(8).cast::(), + ); + + _rt::bool_lift(l41 as u8) + }; + WitNode::PrimBool(e49) + } + 20 => { + let e49 = { + let l42 = *base + .add(8) + .cast::<*mut u8>(); + let l43 = *base + .add(12) + .cast::(); + let len44 = l43; + let bytes44 = + _rt::Vec::from_raw_parts( + l42.cast(), + len44, + len44, + ); + + _rt::string_lift(bytes44) + }; + WitNode::PrimString(e49) + } + n => { + debug_assert_eq!( + n, 21, + "invalid enum discriminant" + ); + let e49 = { + let l45 = *base + .add(8) + .cast::<*mut u8>(); + let l46 = *base + .add(12) + .cast::(); + let len47 = l46; + let bytes47 = + _rt::Vec::from_raw_parts( + l45.cast(), + len47, + len47, + ); + let l48 = + *base.add(16).cast::(); + + ( + Uri { + value: _rt::string_lift( + bytes47, + ), + }, + l48 as u64, + ) + }; + WitNode::Handle(e49) } - _ => wit_bindgen::rt::invalid_enum_discriminant(), - } - }; - WitNode::ResultValue(e48) - } - 8 => { - let e48 = { - let l29 = i32::from(*((base + 8) as *const u8)); - - l29 as u8 - }; - WitNode::PrimU8(e48) - } - 9 => { - let e48 = { - let l30 = i32::from(*((base + 8) as *const u16)); - - l30 as u16 - }; - WitNode::PrimU16(e48) - } - 10 => { - let e48 = { - let l31 = *((base + 8) as *const i32); - - l31 as u32 - }; - WitNode::PrimU32(e48) - } - 11 => { - let e48 = { - let l32 = *((base + 8) as *const i64); - - l32 as u64 - }; - WitNode::PrimU64(e48) - } - 12 => { - let e48 = { - let l33 = i32::from(*((base + 8) as *const i8)); - - l33 as i8 - }; - WitNode::PrimS8(e48) - } - 13 => { - let e48 = { - let l34 = i32::from(*((base + 8) as *const i16)); - - l34 as i16 - }; - WitNode::PrimS16(e48) - } - 14 => { - let e48 = { - let l35 = *((base + 8) as *const i32); - - l35 - }; - WitNode::PrimS32(e48) - } - 15 => { - let e48 = { - let l36 = *((base + 8) as *const i64); - - l36 - }; - WitNode::PrimS64(e48) - } - 16 => { - let e48 = { - let l37 = *((base + 8) as *const f32); - - l37 - }; - WitNode::PrimFloat32(e48) - } - 17 => { - let e48 = { - let l38 = *((base + 8) as *const f64); - - l38 }; - WitNode::PrimFloat64(e48) - } - 18 => { - let e48 = { - let l39 = *((base + 8) as *const i32); - - wit_bindgen::rt::char_lift(l39 as u32) + + v49 + }; + result50.push(e50); + } + _rt::cabi_dealloc(base50, len50 * 24, 8); + + WitValue { nodes: result50 } + }; + Ok(e) + } + 1 => { + let e = { + let l51 = i32::from(*ptr0.add(8).cast::()); + let v64 = match l51 { + 0 => { + let e64 = { + let l52 = + *ptr0.add(12).cast::<*mut u8>(); + let l53 = *ptr0.add(16).cast::(); + let len54 = l53; + let bytes54 = _rt::Vec::from_raw_parts( + l52.cast(), + len54, + len54, + ); + + _rt::string_lift(bytes54) }; - WitNode::PrimChar(e48) - } - 19 => { - let e48 = { - let l40 = i32::from(*((base + 8) as *const u8)); - - wit_bindgen::rt::bool_lift(l40 as u8) + RpcError::ProtocolError(e64) + } + 1 => { + let e64 = { + let l55 = + *ptr0.add(12).cast::<*mut u8>(); + let l56 = *ptr0.add(16).cast::(); + let len57 = l56; + let bytes57 = _rt::Vec::from_raw_parts( + l55.cast(), + len57, + len57, + ); + + _rt::string_lift(bytes57) }; - WitNode::PrimBool(e48) - } - 20 => { - let e48 = { - let l41 = *((base + 8) as *const i32); - let l42 = *((base + 12) as *const i32); - let len43 = l42 as usize; - let bytes43 = Vec::from_raw_parts(l41 as *mut _, len43, len43); - - wit_bindgen::rt::string_lift(bytes43) + RpcError::Denied(e64) + } + 2 => { + let e64 = { + let l58 = + *ptr0.add(12).cast::<*mut u8>(); + let l59 = *ptr0.add(16).cast::(); + let len60 = l59; + let bytes60 = _rt::Vec::from_raw_parts( + l58.cast(), + len60, + len60, + ); + + _rt::string_lift(bytes60) }; - WitNode::PrimString(e48) - } - n => { - debug_assert_eq!(n, 21, "invalid enum discriminant"); - let e48 = { - let l44 = *((base + 8) as *const i32); - let l45 = *((base + 12) as *const i32); - let len46 = l45 as usize; - let bytes46 = Vec::from_raw_parts(l44 as *mut _, len46, len46); - let l47 = *((base + 16) as *const i64); - - (Uri{ - value: wit_bindgen::rt::string_lift(bytes46), - }, l47 as u64) + RpcError::NotFound(e64) + } + n => { + debug_assert_eq!( + n, 3, + "invalid enum discriminant" + ); + let e64 = { + let l61 = + *ptr0.add(12).cast::<*mut u8>(); + let l62 = *ptr0.add(16).cast::(); + let len63 = l62; + let bytes63 = _rt::Vec::from_raw_parts( + l61.cast(), + len63, + len63, + ); + + _rt::string_lift(bytes63) }; - WitNode::Handle(e48) - } - }; - - v48 - }; - result49.push(e49); - } - wit_bindgen::rt::dealloc(base49, (len49 as usize) * 24, 8); - - WitValue{ - nodes: result49, - } - }; - Ok(e) - } - 1 => { - let e = { - let l50 = i32::from(*((ptr0 + 4) as *const u8)); - let v63 = match l50 { - 0 => { - let e63 = { - let l51 = *((ptr0 + 8) as *const i32); - let l52 = *((ptr0 + 12) as *const i32); - let len53 = l52 as usize; - let bytes53 = Vec::from_raw_parts(l51 as *mut _, len53, len53); - - wit_bindgen::rt::string_lift(bytes53) - }; - RpcError::ProtocolError(e63) - } - 1 => { - let e63 = { - let l54 = *((ptr0 + 8) as *const i32); - let l55 = *((ptr0 + 12) as *const i32); - let len56 = l55 as usize; - let bytes56 = Vec::from_raw_parts(l54 as *mut _, len56, len56); - - wit_bindgen::rt::string_lift(bytes56) - }; - RpcError::Denied(e63) - } - 2 => { - let e63 = { - let l57 = *((ptr0 + 8) as *const i32); - let l58 = *((ptr0 + 12) as *const i32); - let len59 = l58 as usize; - let bytes59 = Vec::from_raw_parts(l57 as *mut _, len59, len59); - - wit_bindgen::rt::string_lift(bytes59) - }; - RpcError::NotFound(e63) - } - n => { - debug_assert_eq!(n, 3, "invalid enum discriminant"); - let e63 = { - let l60 = *((ptr0 + 8) as *const i32); - let l61 = *((ptr0 + 12) as *const i32); - let len62 = l61 as usize; - let bytes62 = Vec::from_raw_parts(l60 as *mut _, len62, len62); - - wit_bindgen::rt::string_lift(bytes62) - }; - RpcError::RemoteInternalError(e63) - } + RpcError::RemoteInternalError(e64) + } }; - - v63 - }; - Err(e) - } - _ => wit_bindgen::rt::invalid_enum_discriminant(), - } - } - } - } - - } - - } - } - pub mod wasi { - pub mod io { - - #[allow(clippy::all)] - pub mod poll { - #[used] - #[doc(hidden)] - #[cfg(target_arch = "wasm32")] - static __FORCE_SECTION_REF: fn() = super::super::super::__link_section; - /// `pollable` epresents a single I/O event which may be ready, or not. - - #[derive(Debug)] - #[repr(transparent)] - pub struct Pollable{ - handle: wit_bindgen::rt::Resource, - } - - impl Pollable{ - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: wit_bindgen::rt::Resource::from_handle(handle), - } - } - - #[doc(hidden)] - pub fn into_handle(self) -> u32 { - wit_bindgen::rt::Resource::into_handle(self.handle) - } - - #[doc(hidden)] - pub fn handle(&self) -> u32 { - wit_bindgen::rt::Resource::handle(&self.handle) - } - } - - - unsafe impl wit_bindgen::rt::WasmResource for Pollable{ - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(not(target_arch = "wasm32"))] - unreachable!(); - - #[cfg(target_arch = "wasm32")] - { - #[link(wasm_import_module = "wasi:io/poll@0.2.0")] - extern "C" { - #[link_name = "[resource-drop]pollable"] - fn drop(_: u32); - } - - drop(_handle); - } - } - } - - impl Pollable { - #[allow(unused_unsafe, clippy::all)] - /// Return the readiness of a pollable. This function never blocks. - /// - /// Returns `true` when the pollable is ready, and `false` otherwise. - pub fn ready(&self,) -> bool{ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:io/poll@0.2.0")] - extern "C" { - #[link_name = "[method]pollable.ready"] - fn wit_import(_: i32, ) -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, ) -> i32{ unreachable!() } - let ret = wit_import((self).handle() as i32); - wit_bindgen::rt::bool_lift(ret as u8) + + v64 + }; + Err(e) } - } + _ => _rt::invalid_enum_discriminant(), } - impl Pollable { - #[allow(unused_unsafe, clippy::all)] - /// `block` returns immediately if the pollable is ready, and otherwise - /// blocks until ready. - /// - /// This function is equivalent to calling `poll.poll` on a list - /// containing only this pollable. - pub fn block(&self,){ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:io/poll@0.2.0")] - extern "C" { - #[link_name = "[method]pollable.block"] - fn wit_import(_: i32, ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, ){ unreachable!() } - wit_import((self).handle() as i32); - } - } - } - #[allow(unused_unsafe, clippy::all)] - /// Poll for completion on a set of pollables. - /// - /// This function takes a list of pollables, which identify I/O sources of - /// interest, and waits until one or more of the events is ready for I/O. - /// - /// The result `list` contains one or more indices of handles in the - /// argument list that is ready for I/O. - /// - /// If the list contains more elements than can be indexed with a `u32` - /// value, this function traps. - /// - /// A timeout can be implemented by adding a pollable from the - /// wasi-clocks API to the list. - /// - /// This function does not return a `result`; polling in itself does not - /// do any I/O so it doesn't fail. If any of the I/O sources identified by - /// the pollables has an error, it is indicated by marking the source as - /// being reaedy for I/O. - pub fn poll(in_: &[&Pollable],) -> wit_bindgen::rt::vec::Vec::{ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - - #[repr(align(4))] - struct RetArea([u8; 8]); - let mut ret_area = ::core::mem::MaybeUninit::::uninit(); - let vec0 = in_; - let len0 = vec0.len() as i32; - let layout0 = alloc::Layout::from_size_align_unchecked(vec0.len() * 4, 4); - let result0 = if layout0.size() != 0 - { - let ptr = alloc::alloc(layout0); - if ptr.is_null() - { - alloc::handle_alloc_error(layout0); - } - ptr - }else {{ - ::core::ptr::null_mut() - }}; - for (i, e) in vec0.into_iter().enumerate() { - let base = result0 as i32 + (i as i32) * 4; - { - *((base + 0) as *mut i32) = (e).handle() as i32; - } - } - let ptr1 = ret_area.as_mut_ptr() as i32; - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:io/poll@0.2.0")] - extern "C" { - #[link_name = "poll"] - fn wit_import(_: i32, _: i32, _: i32, ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: i32, _: i32, ){ unreachable!() } - wit_import(result0 as i32, len0, ptr1); - let l2 = *((ptr1 + 0) as *const i32); - let l3 = *((ptr1 + 4) as *const i32); - let len4 = l3 as usize; - if layout0.size() != 0 { - alloc::dealloc(result0, layout0); - } - Vec::from_raw_parts(l2 as *mut _, len4, len4) - } - } - - } - - } - } - - #[cfg(target_arch = "wasm32")] - #[link_section = "component-type:wit-value"] - #[doc(hidden)] - pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 2368] = [3, 0, 9, 119, 105, 116, 45, 118, 97, 108, 117, 101, 0, 97, 115, 109, 13, 0, 1, 0, 7, 147, 8, 1, 65, 5, 1, 66, 1, 4, 0, 8, 112, 111, 108, 108, 97, 98, 108, 101, 3, 1, 3, 1, 18, 119, 97, 115, 105, 58, 105, 111, 47, 112, 111, 108, 108, 64, 48, 46, 50, 46, 48, 5, 0, 2, 3, 0, 0, 8, 112, 111, 108, 108, 97, 98, 108, 101, 1, 66, 41, 2, 3, 2, 1, 1, 4, 0, 8, 112, 111, 108, 108, 97, 98, 108, 101, 3, 0, 0, 1, 122, 4, 0, 10, 110, 111, 100, 101, 45, 105, 110, 100, 101, 120, 3, 0, 2, 1, 114, 1, 5, 118, 97, 108, 117, 101, 115, 4, 0, 3, 117, 114, 105, 3, 0, 4, 1, 112, 3, 1, 107, 3, 1, 111, 2, 121, 7, 1, 112, 127, 1, 106, 1, 7, 1, 7, 1, 111, 2, 5, 119, 1, 113, 22, 12, 114, 101, 99, 111, 114, 100, 45, 118, 97, 108, 117, 101, 1, 6, 0, 13, 118, 97, 114, 105, 97, 110, 116, 45, 118, 97, 108, 117, 101, 1, 8, 0, 10, 101, 110, 117, 109, 45, 118, 97, 108, 117, 101, 1, 121, 0, 11, 102, 108, 97, 103, 115, 45, 118, 97, 108, 117, 101, 1, 9, 0, 11, 116, 117, 112, 108, 101, 45, 118, 97, 108, 117, 101, 1, 6, 0, 10, 108, 105, 115, 116, 45, 118, 97, 108, 117, 101, 1, 6, 0, 12, 111, 112, 116, 105, 111, 110, 45, 118, 97, 108, 117, 101, 1, 7, 0, 12, 114, 101, 115, 117, 108, 116, 45, 118, 97, 108, 117, 101, 1, 10, 0, 7, 112, 114, 105, 109, 45, 117, 56, 1, 125, 0, 8, 112, 114, 105, 109, 45, 117, 49, 54, 1, 123, 0, 8, 112, 114, 105, 109, 45, 117, 51, 50, 1, 121, 0, 8, 112, 114, 105, 109, 45, 117, 54, 52, 1, 119, 0, 7, 112, 114, 105, 109, 45, 115, 56, 1, 126, 0, 8, 112, 114, 105, 109, 45, 115, 49, 54, 1, 124, 0, 8, 112, 114, 105, 109, 45, 115, 51, 50, 1, 122, 0, 8, 112, 114, 105, 109, 45, 115, 54, 52, 1, 120, 0, 12, 112, 114, 105, 109, 45, 102, 108, 111, 97, 116, 51, 50, 1, 118, 0, 12, 112, 114, 105, 109, 45, 102, 108, 111, 97, 116, 54, 52, 1, 117, 0, 9, 112, 114, 105, 109, 45, 99, 104, 97, 114, 1, 116, 0, 9, 112, 114, 105, 109, 45, 98, 111, 111, 108, 1, 127, 0, 11, 112, 114, 105, 109, 45, 115, 116, 114, 105, 110, 103, 1, 115, 0, 6, 104, 97, 110, 100, 108, 101, 1, 11, 0, 4, 0, 8, 119, 105, 116, 45, 110, 111, 100, 101, 3, 0, 12, 1, 112, 13, 1, 114, 1, 5, 110, 111, 100, 101, 115, 14, 4, 0, 9, 119, 105, 116, 45, 118, 97, 108, 117, 101, 3, 0, 15, 1, 113, 4, 14, 112, 114, 111, 116, 111, 99, 111, 108, 45, 101, 114, 114, 111, 114, 1, 115, 0, 6, 100, 101, 110, 105, 101, 100, 1, 115, 0, 9, 110, 111, 116, 45, 102, 111, 117, 110, 100, 1, 115, 0, 21, 114, 101, 109, 111, 116, 101, 45, 105, 110, 116, 101, 114, 110, 97, 108, 45, 101, 114, 114, 111, 114, 1, 115, 0, 4, 0, 9, 114, 112, 99, 45, 101, 114, 114, 111, 114, 3, 0, 17, 4, 0, 8, 119, 97, 115, 109, 45, 114, 112, 99, 3, 1, 4, 0, 20, 102, 117, 116, 117, 114, 101, 45, 105, 110, 118, 111, 107, 101, 45, 114, 101, 115, 117, 108, 116, 3, 1, 1, 105, 19, 1, 64, 1, 8, 108, 111, 99, 97, 116, 105, 111, 110, 5, 0, 21, 4, 0, 21, 91, 99, 111, 110, 115, 116, 114, 117, 99, 116, 111, 114, 93, 119, 97, 115, 109, 45, 114, 112, 99, 1, 22, 1, 104, 19, 1, 112, 16, 1, 106, 1, 16, 1, 18, 1, 64, 3, 4, 115, 101, 108, 102, 23, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 24, 0, 25, 4, 0, 33, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 105, 110, 118, 111, 107, 101, 45, 97, 110, 100, 45, 97, 119, 97, 105, 116, 1, 26, 1, 106, 0, 1, 18, 1, 64, 3, 4, 115, 101, 108, 102, 23, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 24, 0, 27, 4, 0, 23, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 105, 110, 118, 111, 107, 101, 1, 28, 1, 105, 20, 1, 64, 3, 4, 115, 101, 108, 102, 23, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 24, 0, 29, 4, 0, 39, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 97, 115, 121, 110, 99, 45, 105, 110, 118, 111, 107, 101, 45, 97, 110, 100, 45, 97, 119, 97, 105, 116, 1, 30, 1, 104, 20, 1, 105, 1, 1, 64, 1, 4, 115, 101, 108, 102, 31, 0, 32, 4, 0, 38, 91, 109, 101, 116, 104, 111, 100, 93, 102, 117, 116, 117, 114, 101, 45, 105, 110, 118, 111, 107, 101, 45, 114, 101, 115, 117, 108, 116, 46, 115, 117, 98, 115, 99, 114, 105, 98, 101, 1, 33, 1, 64, 1, 4, 115, 101, 108, 102, 31, 0, 25, 4, 0, 32, 91, 109, 101, 116, 104, 111, 100, 93, 102, 117, 116, 117, 114, 101, 45, 105, 110, 118, 111, 107, 101, 45, 114, 101, 115, 117, 108, 116, 46, 103, 101, 116, 1, 34, 4, 1, 21, 103, 111, 108, 101, 109, 58, 114, 112, 99, 47, 116, 121, 112, 101, 115, 64, 48, 46, 49, 46, 48, 5, 2, 11, 11, 1, 0, 5, 116, 121, 112, 101, 115, 3, 0, 0, 7, 155, 9, 1, 65, 2, 1, 65, 5, 1, 66, 10, 4, 0, 8, 112, 111, 108, 108, 97, 98, 108, 101, 3, 1, 1, 104, 0, 1, 64, 1, 4, 115, 101, 108, 102, 1, 0, 127, 4, 0, 22, 91, 109, 101, 116, 104, 111, 100, 93, 112, 111, 108, 108, 97, 98, 108, 101, 46, 114, 101, 97, 100, 121, 1, 2, 1, 64, 1, 4, 115, 101, 108, 102, 1, 1, 0, 4, 0, 22, 91, 109, 101, 116, 104, 111, 100, 93, 112, 111, 108, 108, 97, 98, 108, 101, 46, 98, 108, 111, 99, 107, 1, 3, 1, 112, 1, 1, 112, 121, 1, 64, 1, 2, 105, 110, 4, 0, 5, 4, 0, 4, 112, 111, 108, 108, 1, 6, 3, 1, 18, 119, 97, 115, 105, 58, 105, 111, 47, 112, 111, 108, 108, 64, 48, 46, 50, 46, 48, 5, 0, 2, 3, 0, 0, 8, 112, 111, 108, 108, 97, 98, 108, 101, 1, 66, 41, 2, 3, 2, 1, 1, 4, 0, 8, 112, 111, 108, 108, 97, 98, 108, 101, 3, 0, 0, 1, 122, 4, 0, 10, 110, 111, 100, 101, 45, 105, 110, 100, 101, 120, 3, 0, 2, 1, 114, 1, 5, 118, 97, 108, 117, 101, 115, 4, 0, 3, 117, 114, 105, 3, 0, 4, 1, 112, 3, 1, 107, 3, 1, 111, 2, 121, 7, 1, 112, 127, 1, 106, 1, 7, 1, 7, 1, 111, 2, 5, 119, 1, 113, 22, 12, 114, 101, 99, 111, 114, 100, 45, 118, 97, 108, 117, 101, 1, 6, 0, 13, 118, 97, 114, 105, 97, 110, 116, 45, 118, 97, 108, 117, 101, 1, 8, 0, 10, 101, 110, 117, 109, 45, 118, 97, 108, 117, 101, 1, 121, 0, 11, 102, 108, 97, 103, 115, 45, 118, 97, 108, 117, 101, 1, 9, 0, 11, 116, 117, 112, 108, 101, 45, 118, 97, 108, 117, 101, 1, 6, 0, 10, 108, 105, 115, 116, 45, 118, 97, 108, 117, 101, 1, 6, 0, 12, 111, 112, 116, 105, 111, 110, 45, 118, 97, 108, 117, 101, 1, 7, 0, 12, 114, 101, 115, 117, 108, 116, 45, 118, 97, 108, 117, 101, 1, 10, 0, 7, 112, 114, 105, 109, 45, 117, 56, 1, 125, 0, 8, 112, 114, 105, 109, 45, 117, 49, 54, 1, 123, 0, 8, 112, 114, 105, 109, 45, 117, 51, 50, 1, 121, 0, 8, 112, 114, 105, 109, 45, 117, 54, 52, 1, 119, 0, 7, 112, 114, 105, 109, 45, 115, 56, 1, 126, 0, 8, 112, 114, 105, 109, 45, 115, 49, 54, 1, 124, 0, 8, 112, 114, 105, 109, 45, 115, 51, 50, 1, 122, 0, 8, 112, 114, 105, 109, 45, 115, 54, 52, 1, 120, 0, 12, 112, 114, 105, 109, 45, 102, 108, 111, 97, 116, 51, 50, 1, 118, 0, 12, 112, 114, 105, 109, 45, 102, 108, 111, 97, 116, 54, 52, 1, 117, 0, 9, 112, 114, 105, 109, 45, 99, 104, 97, 114, 1, 116, 0, 9, 112, 114, 105, 109, 45, 98, 111, 111, 108, 1, 127, 0, 11, 112, 114, 105, 109, 45, 115, 116, 114, 105, 110, 103, 1, 115, 0, 6, 104, 97, 110, 100, 108, 101, 1, 11, 0, 4, 0, 8, 119, 105, 116, 45, 110, 111, 100, 101, 3, 0, 12, 1, 112, 13, 1, 114, 1, 5, 110, 111, 100, 101, 115, 14, 4, 0, 9, 119, 105, 116, 45, 118, 97, 108, 117, 101, 3, 0, 15, 1, 113, 4, 14, 112, 114, 111, 116, 111, 99, 111, 108, 45, 101, 114, 114, 111, 114, 1, 115, 0, 6, 100, 101, 110, 105, 101, 100, 1, 115, 0, 9, 110, 111, 116, 45, 102, 111, 117, 110, 100, 1, 115, 0, 21, 114, 101, 109, 111, 116, 101, 45, 105, 110, 116, 101, 114, 110, 97, 108, 45, 101, 114, 114, 111, 114, 1, 115, 0, 4, 0, 9, 114, 112, 99, 45, 101, 114, 114, 111, 114, 3, 0, 17, 4, 0, 8, 119, 97, 115, 109, 45, 114, 112, 99, 3, 1, 4, 0, 20, 102, 117, 116, 117, 114, 101, 45, 105, 110, 118, 111, 107, 101, 45, 114, 101, 115, 117, 108, 116, 3, 1, 1, 105, 19, 1, 64, 1, 8, 108, 111, 99, 97, 116, 105, 111, 110, 5, 0, 21, 4, 0, 21, 91, 99, 111, 110, 115, 116, 114, 117, 99, 116, 111, 114, 93, 119, 97, 115, 109, 45, 114, 112, 99, 1, 22, 1, 104, 19, 1, 112, 16, 1, 106, 1, 16, 1, 18, 1, 64, 3, 4, 115, 101, 108, 102, 23, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 24, 0, 25, 4, 0, 33, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 105, 110, 118, 111, 107, 101, 45, 97, 110, 100, 45, 97, 119, 97, 105, 116, 1, 26, 1, 106, 0, 1, 18, 1, 64, 3, 4, 115, 101, 108, 102, 23, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 24, 0, 27, 4, 0, 23, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 105, 110, 118, 111, 107, 101, 1, 28, 1, 105, 20, 1, 64, 3, 4, 115, 101, 108, 102, 23, 13, 102, 117, 110, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 115, 15, 102, 117, 110, 99, 116, 105, 111, 110, 45, 112, 97, 114, 97, 109, 115, 24, 0, 29, 4, 0, 39, 91, 109, 101, 116, 104, 111, 100, 93, 119, 97, 115, 109, 45, 114, 112, 99, 46, 97, 115, 121, 110, 99, 45, 105, 110, 118, 111, 107, 101, 45, 97, 110, 100, 45, 97, 119, 97, 105, 116, 1, 30, 1, 104, 20, 1, 105, 1, 1, 64, 1, 4, 115, 101, 108, 102, 31, 0, 32, 4, 0, 38, 91, 109, 101, 116, 104, 111, 100, 93, 102, 117, 116, 117, 114, 101, 45, 105, 110, 118, 111, 107, 101, 45, 114, 101, 115, 117, 108, 116, 46, 115, 117, 98, 115, 99, 114, 105, 98, 101, 1, 33, 1, 64, 1, 4, 115, 101, 108, 102, 31, 0, 25, 4, 0, 32, 91, 109, 101, 116, 104, 111, 100, 93, 102, 117, 116, 117, 114, 101, 45, 105, 110, 118, 111, 107, 101, 45, 114, 101, 115, 117, 108, 116, 46, 103, 101, 116, 1, 34, 3, 1, 21, 103, 111, 108, 101, 109, 58, 114, 112, 99, 47, 116, 121, 112, 101, 115, 64, 48, 46, 49, 46, 48, 5, 2, 4, 1, 25, 103, 111, 108, 101, 109, 58, 114, 112, 99, 47, 119, 105, 116, 45, 118, 97, 108, 117, 101, 64, 48, 46, 49, 46, 48, 4, 0, 11, 15, 1, 0, 9, 119, 105, 116, 45, 118, 97, 108, 117, 101, 3, 2, 0, 0, 16, 12, 112, 97, 99, 107, 97, 103, 101, 45, 100, 111, 99, 115, 0, 123, 125, 0, 70, 9, 112, 114, 111, 100, 117, 99, 101, 114, 115, 1, 12, 112, 114, 111, 99, 101, 115, 115, 101, 100, 45, 98, 121, 2, 13, 119, 105, 116, 45, 99, 111, 109, 112, 111, 110, 101, 110, 116, 6, 48, 46, 49, 56, 46, 50, 16, 119, 105, 116, 45, 98, 105, 110, 100, 103, 101, 110, 45, 114, 117, 115, 116, 6, 48, 46, 49, 54, 46, 48]; - - #[inline(never)] - #[doc(hidden)] - #[cfg(target_arch = "wasm32")] - pub fn __link_section() {} - \ No newline at end of file + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + } + } +} +#[allow(dead_code)] +pub mod wasi { + #[allow(dead_code)] + pub mod io { + #[allow(dead_code, clippy::all)] + pub mod poll { + #[used] + #[doc(hidden)] + #[cfg(target_arch = "wasm32")] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + /// `pollable` epresents a single I/O event which may be ready, or not. + + #[derive(Debug)] + #[repr(transparent)] + pub struct Pollable { + handle: _rt::Resource, + } + + impl Pollable { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + + unsafe impl _rt::WasmResource for Pollable { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:io/poll@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]pollable"] + fn drop(_: u32); + } + + drop(_handle); + } + } + } + + impl Pollable { + #[allow(unused_unsafe, clippy::all)] + /// Return the readiness of a pollable. This function never blocks. + /// + /// Returns `true` when the pollable is ready, and `false` otherwise. + pub fn ready(&self) -> bool { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/poll@0.2.0")] + extern "C" { + #[link_name = "[method]pollable.ready"] + fn wit_import(_: i32) -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32); + _rt::bool_lift(ret as u8) + } + } + } + impl Pollable { + #[allow(unused_unsafe, clippy::all)] + /// `block` returns immediately if the pollable is ready, and otherwise + /// blocks until ready. + /// + /// This function is equivalent to calling `poll.poll` on a list + /// containing only this pollable. + pub fn block(&self) { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/poll@0.2.0")] + extern "C" { + #[link_name = "[method]pollable.block"] + fn wit_import(_: i32); + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) { + unreachable!() + } + wit_import((self).handle() as i32); + } + } + } + #[allow(unused_unsafe, clippy::all)] + /// Poll for completion on a set of pollables. + /// + /// This function takes a list of pollables, which identify I/O sources of + /// interest, and waits until one or more of the events is ready for I/O. + /// + /// The result `list` contains one or more indices of handles in the + /// argument list that is ready for I/O. + /// + /// If the list contains more elements than can be indexed with a `u32` + /// value, this function traps. + /// + /// A timeout can be implemented by adding a pollable from the + /// wasi-clocks API to the list. + /// + /// This function does not return a `result`; polling in itself does not + /// do any I/O so it doesn't fail. If any of the I/O sources identified by + /// the pollables has an error, it is indicated by marking the source as + /// being reaedy for I/O. + pub fn poll(in_: &[&Pollable]) -> _rt::Vec { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let vec0 = in_; + let len0 = vec0.len(); + let layout0 = _rt::alloc::Layout::from_size_align_unchecked(vec0.len() * 4, 4); + let result0 = if layout0.size() != 0 { + let ptr = _rt::alloc::alloc(layout0).cast::(); + if ptr.is_null() { + _rt::alloc::handle_alloc_error(layout0); + } + ptr + } else { + { + ::core::ptr::null_mut() + } + }; + for (i, e) in vec0.into_iter().enumerate() { + let base = result0.add(i * 4); + { + *base.add(0).cast::() = (e).handle() as i32; + } + } + let ptr1 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/poll@0.2.0")] + extern "C" { + #[link_name = "poll"] + fn wit_import(_: *mut u8, _: usize, _: *mut u8); + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: *mut u8, _: usize, _: *mut u8) { + unreachable!() + } + wit_import(result0, len0, ptr1); + let l2 = *ptr1.add(0).cast::<*mut u8>(); + let l3 = *ptr1.add(4).cast::(); + let len4 = l3; + if layout0.size() != 0 { + _rt::alloc::dealloc(result0.cast(), layout0); + } + _rt::Vec::from_raw_parts(l2.cast(), len4, len4) + } + } + } + } +} +mod _rt { + + use core::fmt; + use core::marker; + use core::sync::atomic::{AtomicU32, Ordering::Relaxed}; + + /// A type which represents a component model resource, either imported or + /// exported into this component. + /// + /// This is a low-level wrapper which handles the lifetime of the resource + /// (namely this has a destructor). The `T` provided defines the component model + /// intrinsics that this wrapper uses. + /// + /// One of the chief purposes of this type is to provide `Deref` implementations + /// to access the underlying data when it is owned. + /// + /// This type is primarily used in generated code for exported and imported + /// resources. + #[repr(transparent)] + pub struct Resource { + // NB: This would ideally be `u32` but it is not. The fact that this has + // interior mutability is not exposed in the API of this type except for the + // `take_handle` method which is supposed to in theory be private. + // + // This represents, almost all the time, a valid handle value. When it's + // invalid it's stored as `u32::MAX`. + handle: AtomicU32, + _marker: marker::PhantomData, + } + + /// A trait which all wasm resources implement, namely providing the ability to + /// drop a resource. + /// + /// This generally is implemented by generated code, not user-facing code. + #[allow(clippy::missing_safety_doc)] + pub unsafe trait WasmResource { + /// Invokes the `[resource-drop]...` intrinsic. + unsafe fn drop(handle: u32); + } + + impl Resource { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + debug_assert!(handle != u32::MAX); + Self { + handle: AtomicU32::new(handle), + _marker: marker::PhantomData, + } + } + + /// Takes ownership of the handle owned by `resource`. + /// + /// Note that this ideally would be `into_handle` taking `Resource` by + /// ownership. The code generator does not enable that in all situations, + /// unfortunately, so this is provided instead. + /// + /// Also note that `take_handle` is in theory only ever called on values + /// owned by a generated function. For example a generated function might + /// take `Resource` as an argument but then call `take_handle` on a + /// reference to that argument. In that sense the dynamic nature of + /// `take_handle` should only be exposed internally to generated code, not + /// to user code. + #[doc(hidden)] + pub fn take_handle(resource: &Resource) -> u32 { + resource.handle.swap(u32::MAX, Relaxed) + } + + #[doc(hidden)] + pub fn handle(resource: &Resource) -> u32 { + resource.handle.load(Relaxed) + } + } + + impl fmt::Debug for Resource { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Resource") + .field("handle", &self.handle) + .finish() + } + } + + impl Drop for Resource { + fn drop(&mut self) { + unsafe { + match self.handle.load(Relaxed) { + // If this handle was "taken" then don't do anything in the + // destructor. + u32::MAX => {} + + // ... but otherwise do actually destroy it with the imported + // component model intrinsic as defined through `T`. + other => T::drop(other), + } + } + } + } + pub unsafe fn bool_lift(val: u8) -> bool { + if cfg!(debug_assertions) { + match val { + 0 => false, + 1 => true, + _ => panic!("invalid bool discriminant"), + } + } else { + val != 0 + } + } + pub use alloc_crate::alloc; + pub use alloc_crate::string::String; + pub use alloc_crate::vec::Vec; + + pub fn as_i32(t: T) -> i32 { + t.as_i32() + } + + pub trait AsI32 { + fn as_i32(self) -> i32; + } + + impl<'a, T: Copy + AsI32> AsI32 for &'a T { + fn as_i32(self) -> i32 { + (*self).as_i32() + } + } + + impl AsI32 for i32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for u32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for i16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for u16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for i8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for u8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for char { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for usize { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + pub fn as_i64(t: T) -> i64 { + t.as_i64() + } + + pub trait AsI64 { + fn as_i64(self) -> i64; + } + + impl<'a, T: Copy + AsI64> AsI64 for &'a T { + fn as_i64(self) -> i64 { + (*self).as_i64() + } + } + + impl AsI64 for i64 { + #[inline] + fn as_i64(self) -> i64 { + self as i64 + } + } + + impl AsI64 for u64 { + #[inline] + fn as_i64(self) -> i64 { + self as i64 + } + } + + pub fn as_f32(t: T) -> f32 { + t.as_f32() + } + + pub trait AsF32 { + fn as_f32(self) -> f32; + } + + impl<'a, T: Copy + AsF32> AsF32 for &'a T { + fn as_f32(self) -> f32 { + (*self).as_f32() + } + } + + impl AsF32 for f32 { + #[inline] + fn as_f32(self) -> f32 { + self as f32 + } + } + + pub fn as_f64(t: T) -> f64 { + t.as_f64() + } + + pub trait AsF64 { + fn as_f64(self) -> f64; + } + + impl<'a, T: Copy + AsF64> AsF64 for &'a T { + fn as_f64(self) -> f64 { + (*self).as_f64() + } + } + + impl AsF64 for f64 { + #[inline] + fn as_f64(self) -> f64 { + self as f64 + } + } + pub unsafe fn invalid_enum_discriminant() -> T { + if cfg!(debug_assertions) { + panic!("invalid enum discriminant") + } else { + core::hint::unreachable_unchecked() + } + } + pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) { + if size == 0 { + return; + } + let layout = alloc::Layout::from_size_align_unchecked(size, align); + alloc::dealloc(ptr as *mut u8, layout); + } + pub unsafe fn char_lift(val: u32) -> char { + if cfg!(debug_assertions) { + core::char::from_u32(val).unwrap() + } else { + core::char::from_u32_unchecked(val) + } + } + pub unsafe fn string_lift(bytes: Vec) -> String { + if cfg!(debug_assertions) { + String::from_utf8(bytes).unwrap() + } else { + String::from_utf8_unchecked(bytes) + } + } + extern crate alloc as alloc_crate; +} + +#[cfg(target_arch = "wasm32")] +#[link_section = "component-type:wit-bindgen:0.25.0:wit-value:encoded world"] +#[doc(hidden)] +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1310] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\x9e\x09\x01A\x02\x01\ +A\x05\x01B\x0a\x04\0\x08pollable\x03\x01\x01h\0\x01@\x01\x04self\x01\0\x7f\x04\0\ +\x16[method]pollable.ready\x01\x02\x01@\x01\x04self\x01\x01\0\x04\0\x16[method]p\ +ollable.block\x01\x03\x01p\x01\x01py\x01@\x01\x02in\x04\0\x05\x04\0\x04poll\x01\x06\ +\x03\x01\x12wasi:io/poll@0.2.0\x05\0\x02\x03\0\0\x08pollable\x01B*\x02\x03\x02\x01\ +\x01\x04\0\x08pollable\x03\0\0\x01z\x04\0\x0anode-index\x03\0\x02\x01r\x01\x05va\ +lues\x04\0\x03uri\x03\0\x04\x01p\x03\x01k\x03\x01o\x02y\x07\x01p\x7f\x01j\x01\x07\ +\x01\x07\x01o\x02\x05w\x01q\x16\x0crecord-value\x01\x06\0\x0dvariant-value\x01\x08\ +\0\x0aenum-value\x01y\0\x0bflags-value\x01\x09\0\x0btuple-value\x01\x06\0\x0alis\ +t-value\x01\x06\0\x0coption-value\x01\x07\0\x0cresult-value\x01\x0a\0\x07prim-u8\ +\x01}\0\x08prim-u16\x01{\0\x08prim-u32\x01y\0\x08prim-u64\x01w\0\x07prim-s8\x01~\ +\0\x08prim-s16\x01|\0\x08prim-s32\x01z\0\x08prim-s64\x01x\0\x0cprim-float32\x01v\ +\0\x0cprim-float64\x01u\0\x09prim-char\x01t\0\x09prim-bool\x01\x7f\0\x0bprim-str\ +ing\x01s\0\x06handle\x01\x0b\0\x04\0\x08wit-node\x03\0\x0c\x01p\x0d\x01r\x01\x05\ +nodes\x0e\x04\0\x09wit-value\x03\0\x0f\x01q\x04\x0eprotocol-error\x01s\0\x06deni\ +ed\x01s\0\x09not-found\x01s\0\x15remote-internal-error\x01s\0\x04\0\x09rpc-error\ +\x03\0\x11\x04\0\x08wasm-rpc\x03\x01\x04\0\x14future-invoke-result\x03\x01\x01i\x13\ +\x01@\x01\x08location\x05\0\x15\x04\0\x15[constructor]wasm-rpc\x01\x16\x01h\x13\x01\ +p\x10\x01j\x01\x10\x01\x12\x01@\x03\x04self\x17\x0dfunction-names\x0ffunction-pa\ +rams\x18\0\x19\x04\0![method]wasm-rpc.invoke-and-await\x01\x1a\x01j\0\x01\x12\x01\ +@\x03\x04self\x17\x0dfunction-names\x0ffunction-params\x18\0\x1b\x04\0\x17[metho\ +d]wasm-rpc.invoke\x01\x1c\x01i\x14\x01@\x03\x04self\x17\x0dfunction-names\x0ffun\ +ction-params\x18\0\x1d\x04\0'[method]wasm-rpc.async-invoke-and-await\x01\x1e\x01\ +h\x14\x01i\x01\x01@\x01\x04self\x1f\0\x20\x04\0&[method]future-invoke-result.sub\ +scribe\x01!\x01k\x19\x01@\x01\x04self\x1f\0\"\x04\0\x20[method]future-invoke-res\ +ult.get\x01#\x03\x01\x15golem:rpc/types@0.1.0\x05\x02\x04\x01\x19golem:rpc/wit-v\ +alue@0.1.0\x04\0\x0b\x0f\x01\0\x09wit-value\x03\0\0\0G\x09producers\x01\x0cproce\ +ssed-by\x02\x0dwit-component\x070.208.1\x10wit-bindgen-rust\x060.25.0"; + +#[inline(never)] +#[doc(hidden)] +#[cfg(target_arch = "wasm32")] +pub fn __link_custom_section_describing_imports() { + wit_bindgen_rt::maybe_link_cabi_realloc(); +} From b66a346d3c7d0b957253766c1f8d82d9c8d489f7 Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Fri, 21 Jun 2024 15:16:53 +0200 Subject: [PATCH 6/7] Fixes to the new bindgen version --- wasm-rpc-stubgen/src/rust.rs | 25 ++++++++++++++++++++----- wasm-rpc-stubgen/src/wit.rs | 4 ++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/wasm-rpc-stubgen/src/rust.rs b/wasm-rpc-stubgen/src/rust.rs index 28f976ed..7a8bc150 100644 --- a/wasm-rpc-stubgen/src/rust.rs +++ b/wasm-rpc-stubgen/src/rust.rs @@ -324,9 +324,11 @@ fn generate_result_wrapper_get_source( ); Ok(quote! { - fn get(&self) -> #result_type { - let result = self.future_invoke_result.get().expect(&format!("Failed to invoke remote {}", #remote_function_name));; - (#(#output_values),*) + fn get(&self) -> Option<#result_type> { + self.future_invoke_result.get().map(|result| { + let result = result.expect(&format!("Failed to invoke remote {}", #remote_function_name)); + (#(#output_values),*) + }) } }) } @@ -464,9 +466,22 @@ fn generate_function_stub_source( } } } else { + let root_ns = Ident::new( + &def.root_package_name.namespace.to_snake_case(), + Span::call_site(), + ); + let root_name = Ident::new( + &format!("{}_stub", def.root_package_name.name.to_snake_case()), + Span::call_site(), + ); + let stub_interface_name = format!("stub-{}", def.source_world_name()?); + let stub_interface_name = Ident::new( + &to_rust_ident(&stub_interface_name).to_snake_case(), + Span::call_site(), + ); let result_wrapper = result_wrapper_ident(function, owner); quote! { - fn #function_name(#(#params),*) -> wit_bindgen::rt::Resource<#result_wrapper> { + fn #function_name(#(#params),*) -> crate::bindings::exports::#root_ns::#root_name::#stub_interface_name::#result_wrapper { #init let result = #rpc.async_invoke_and_await( #remote_function_name, @@ -474,7 +489,7 @@ fn generate_function_stub_source( #(#input_values),* ], ); - wit_bindgen::rt::Resource::new(#result_wrapper { future_invoke_result: result}) + crate::bindings::exports::#root_ns::#root_name::#stub_interface_name::#result_wrapper::new(#result_wrapper { future_invoke_result: result}) } } } diff --git a/wasm-rpc-stubgen/src/wit.rs b/wasm-rpc-stubgen/src/wit.rs index b912b768..7160b05d 100644 --- a/wasm-rpc-stubgen/src/wit.rs +++ b/wasm-rpc-stubgen/src/wit.rs @@ -194,9 +194,9 @@ fn write_async_return_type( ) -> anyhow::Result<()> { writeln!(out, " resource {} {{", function.async_result_type(owner))?; writeln!(out, " subscribe: func() -> pollable;")?; - write!(out, " get: func() -> ")?; + write!(out, " get: func() -> option<")?; write_function_result_type(out, function, def)?; - writeln!(out, ";")?; + writeln!(out, ">;")?; writeln!(out, " }}")?; Ok(()) } From 0521870c957ce3b04ea5d3a9df00a958a44e83e5 Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Fri, 21 Jun 2024 15:25:19 +0200 Subject: [PATCH 7/7] More fixes --- wasm-rpc-stubgen/src/rust.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/wasm-rpc-stubgen/src/rust.rs b/wasm-rpc-stubgen/src/rust.rs index 7a8bc150..a49f9f75 100644 --- a/wasm-rpc-stubgen/src/rust.rs +++ b/wasm-rpc-stubgen/src/rust.rs @@ -91,7 +91,11 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> { pub struct #result_wrapper { pub future_invoke_result: FutureInvokeResult } - }) + }); + + resource_type_aliases.push(quote! { + type #result_wrapper = crate::#result_wrapper; + }); } } for function in &interface.static_functions { @@ -101,7 +105,11 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> { pub struct #result_wrapper { pub future_invoke_result: FutureInvokeResult } - }) + }); + + resource_type_aliases.push(quote! { + type #result_wrapper = crate::#result_wrapper; + }); } } } @@ -133,7 +141,7 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> { let pollable = self.future_invoke_result.subscribe(); let pollable = unsafe { bindings::wasi::io::poll::Pollable::from_handle( - pollable.into_handle() + pollable.take_handle() ) }; pollable @@ -169,7 +177,7 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> { let pollable = self.future_invoke_result.subscribe(); let pollable = unsafe { bindings::wasi::io::poll::Pollable::from_handle( - pollable.into_handle() + pollable.take_handle() ) }; pollable