diff --git a/.gitignore b/.gitignore
index aaadf73..09ffa8b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,10 @@
*.dll
*.so
*.dylib
+*.wasm
+
+# Scratch directory used by regenerate_bindings.sh
+tmp/
# Test binary, built with `go test -c`
*.test
diff --git a/.golangci.yml b/.golangci.yml
new file mode 100644
index 0000000..87137e8
--- /dev/null
+++ b/.golangci.yml
@@ -0,0 +1,8 @@
+version: "2"
+
+linters:
+ exclusions:
+ # The wit-bindgen header ("Generated by `wit-bindgen` ... DO NOT EDIT!")
+ # doesn't match the strict Go convention regex, so use the lenient
+ # heuristic to skip the generated bindings in imports/ and exports/.
+ generated: lenient
diff --git a/README.md b/README.md
index 8028582..8877167 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
go-pkg
- Golang packages for the Bytecode Alliance componentize-go project
+ The Go library for building WebAssembly components with componentize-go
A Bytecode Alliance project
@@ -15,7 +15,110 @@
# Overview
-This is a set of Golang packages for the Bytecode Alliance componentize-go project.
+Module `go.bytecodealliance.org/pkg` is the Go library for Wasm components. It adapts standard-library interfaces (`net/http`, `log/slog`) to standard `wasi:*` interfaces and ships the committed bindings and WIT worlds needed to build HTTP components with [componentize-go](https://github.com/bytecodealliance/componentize-go). The use of this package significantly reduces the number of files generated and committed for a typical go application.
+
+The library targets two worlds defined in [`wit/world.wit`](./wit/world.wit):
+
+- **`bytecodealliance:pkg/wasip2`** (default): a sync WASI P2 component exporting `wasi:http/incoming-handler@0.2.8`, buildable with stock Go.
+- **`bytecodealliance:pkg/wasip3`** (opt-in): an async WASI P3 component exporting `wasi:http/handler@0.3.0` with streaming bodies and native concurrency.
+
+## Packages
+
+| Package | Description |
+| --- | --- |
+| `wasihttp` | `net/http` adapter for `wasi:http`: serve incoming requests with a standard `http.Handler` and send outbound requests through an `http.RoundTripper`. One API, two implementations selected by build tag (see below). |
+| `wasilog` | `slog.Handler` implementation over `wasi:logging`. |
+| `wasiconfig` | Helpers over `wasi:config/store`. |
+| `wit/types`, `wit/runtime`, `wit/async` | Core WIT value types (option, result, tuple, stream, future) and the canonical-ABI runtime support used by generated bindings. |
+| `imports/...` | Committed generated bindings for the `wasi:*` interfaces imported by the two worlds (both the 0.2.8 and 0.3.0 families). |
+| `exports/...` | Per-world generated `//go:wasmexport` glue and export trampolines. |
+
+Bindings under `imports/` and `exports/` are generated by
+[`regenerate_bindings.sh`](./regenerate_bindings.sh) — do not edit them.
+
+## Updating WIT dependencies
+
+The `wasi:*` WIT packages under `wit/deps/` are vendored verbatim from the WebAssembly package registry using [wkg](https://github.com/bytecodealliance/wasm-pkg-tools). To update a dependency:
+
+1. Bump its version in [`fetch_wit_deps.sh`](./fetch_wit_deps.sh) and in
+ [`wit/world.wit`](./wit/world.wit).
+2. Re-fetch the vendored WIT:
+
+ ```console
+ $ ./fetch_wit_deps.sh
+ ```
+
+3. Regenerate the committed bindings and commit everything together:
+
+ ```console
+ $ ./regenerate_bindings.sh
+ ```
+
+> **Note**: the script uses `wkg get` with exact versions rather than
+> `wkg wit fetch` because the library intentionally depends on two versions
+> of several packages (e.g. `wasi:http@0.2.8` and `wasi:http@0.3.0`), and
+> `wkg wit fetch` resolves at most one version per package name.
+
+## The `componentizego_async` build tag
+
+`wasihttp` compiles to one of two implementations; the exported API is identical under both:
+
+- **Default (no tag)**: sync WASI P2 (`wasi:http@0.2.8`). Matches the `bytecodealliance:pkg/wasip2` world.
+- **`-tags componentizego_async`**: async WASI P3 (`wasi:http@0.3.0`) with streaming bodies and native concurrency. Matches the `bytecodealliance:pkg/wasip3` world.
+
+componentize-go sets the tag automatically when building an async world.
+
+## Quickstart
+
+```go
+package main
+
+import (
+ "net/http"
+
+ "go.bytecodealliance.org/pkg/wasihttp"
+)
+
+func init() {
+ wasihttp.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Write([]byte("Hello, component!"))
+ })
+}
+
+func main() {}
+```
+
+Add componentize-go as a Go tool and build:
+
+```console
+$ go get -tool github.com/bytecodealliance/componentize-go
+$ go tool componentize-go build
+```
+
+The default world (`bytecodealliance:pkg/wasip2@0.1.0`) is declared in [`componentize-go.toml`](./componentize-go.toml) and discovered automatically. To build the async WASI P3 world instead:
+
+```console
+$ go tool componentize-go -w bytecodealliance:pkg/wasip3 build
+```
+
+## Benchmarks
+
+Pure-Go conversion logic (header conversion and friends) has microbenchmarks that run on the host:
+
+```console
+$ go test -bench=. -benchmem ./...
+```
+
+Packages that call `wasi:*` imports only link on wasm targets, so the benchmarks live in host-compilable packages (e.g. `internal/httpconv`).
+
+For A/B comparisons use [benchstat](https://pkg.go.dev/golang.org/x/perf/cmd/benchstat): collect ≥10 samples per side with the test filter disabled, then compare:
+
+```console
+$ go test -bench=. -benchmem -count=10 -run='^$' ./... > old.txt
+$ # ... apply your change ...
+$ go test -bench=. -benchmem -count=10 -run='^$' ./... > new.txt
+$ benchstat old.txt new.txt
+```
## Questions?
@@ -23,5 +126,4 @@ Ask over in the Bytecode Alliance wit/deps/wasi-http-0.2.8/package.wit
+ dir="wit/deps/$(echo "$pkg" | tr ':@' '--')"
+ mkdir -p "$dir"
+ "$WKG" get "$pkg" --format wit --overwrite -o "$dir/package.wit"
+done
diff --git a/imports/wasi_cli_0_2_8_environment/empty.s b/imports/wasi_cli_0_2_8_environment/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_environment/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_cli_0_2_8_environment/wit_bindings.go b/imports/wasi_cli_0_2_8_environment/wit_bindings.go
new file mode 100644
index 0000000..2dcc8da
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_environment/wit_bindings.go
@@ -0,0 +1,100 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_cli_0_2_8_environment
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+//go:wasmimport wasi:cli/environment@0.2.8 get-environment
+func wasm_import_get_environment(arg0 uintptr)
+
+func GetEnvironment() []witTypes.Tuple2[string, string] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4))
+ wasm_import_get_environment(returnArea)
+ result := make([]witTypes.Tuple2[string, string], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
+ for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ {
+ base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0)))), index*(4*4))
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)))
+ value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4))))
+
+ result = append(result, witTypes.Tuple2[string, string]{value, value0})
+ }
+
+ result1 := result
+ return result1
+
+}
+
+//go:wasmimport wasi:cli/environment@0.2.8 get-arguments
+func wasm_import_get_arguments(arg0 uintptr)
+
+func GetArguments() []string {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4))
+ wasm_import_get_arguments(returnArea)
+ result := make([]string, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
+ for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ {
+ base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0)))), index*(2*4))
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)))
+
+ result = append(result, value)
+ }
+
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:cli/environment@0.2.8 initial-cwd
+func wasm_import_initial_cwd(arg0 uintptr)
+
+func InitialCwd() witTypes.Option[string] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4))
+ wasm_import_initial_cwd(returnArea)
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+
+ option = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
diff --git a/imports/wasi_cli_0_2_8_exit/empty.s b/imports/wasi_cli_0_2_8_exit/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_exit/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_cli_0_2_8_exit/wit_bindings.go b/imports/wasi_cli_0_2_8_exit/wit_bindings.go
new file mode 100644
index 0000000..55e9bb0
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_exit/wit_bindings.go
@@ -0,0 +1,46 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_cli_0_2_8_exit
+
+import (
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+)
+
+//go:wasmimport wasi:cli/exit@0.2.8 exit
+func wasm_import_exit(arg0 int32)
+
+func Exit(status witTypes.Result[witTypes.Unit, witTypes.Unit]) {
+
+ var option int32
+ switch status.Tag() {
+ case witTypes.ResultOk:
+
+ option = int32(0)
+ case witTypes.ResultErr:
+
+ option = int32(1)
+ default:
+ panic("unreachable")
+ }
+ wasm_import_exit(option)
+
+}
diff --git a/imports/wasi_cli_0_2_8_stderr/empty.s b/imports/wasi_cli_0_2_8_stderr/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_stderr/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_cli_0_2_8_stderr/wit_bindings.go b/imports/wasi_cli_0_2_8_stderr/wit_bindings.go
new file mode 100644
index 0000000..e50701c
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_stderr/wit_bindings.go
@@ -0,0 +1,38 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_cli_0_2_8_stderr
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_streams"
+)
+
+type OutputStream = wasi_io_0_2_8_streams.OutputStream
+
+//go:wasmimport wasi:cli/stderr@0.2.8 get-stderr
+func wasm_import_get_stderr() int32
+
+func GetStderr() *wasi_io_0_2_8_streams.OutputStream {
+
+ result := wasm_import_get_stderr()
+ return wasi_io_0_2_8_streams.OutputStreamFromOwnHandle(int32(uintptr(result)))
+
+}
diff --git a/imports/wasi_cli_0_2_8_stdin/empty.s b/imports/wasi_cli_0_2_8_stdin/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_stdin/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_cli_0_2_8_stdin/wit_bindings.go b/imports/wasi_cli_0_2_8_stdin/wit_bindings.go
new file mode 100644
index 0000000..40c224f
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_stdin/wit_bindings.go
@@ -0,0 +1,38 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_cli_0_2_8_stdin
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_streams"
+)
+
+type InputStream = wasi_io_0_2_8_streams.InputStream
+
+//go:wasmimport wasi:cli/stdin@0.2.8 get-stdin
+func wasm_import_get_stdin() int32
+
+func GetStdin() *wasi_io_0_2_8_streams.InputStream {
+
+ result := wasm_import_get_stdin()
+ return wasi_io_0_2_8_streams.InputStreamFromOwnHandle(int32(uintptr(result)))
+
+}
diff --git a/imports/wasi_cli_0_2_8_stdout/empty.s b/imports/wasi_cli_0_2_8_stdout/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_stdout/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_cli_0_2_8_stdout/wit_bindings.go b/imports/wasi_cli_0_2_8_stdout/wit_bindings.go
new file mode 100644
index 0000000..522fbd2
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_stdout/wit_bindings.go
@@ -0,0 +1,38 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_cli_0_2_8_stdout
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_streams"
+)
+
+type OutputStream = wasi_io_0_2_8_streams.OutputStream
+
+//go:wasmimport wasi:cli/stdout@0.2.8 get-stdout
+func wasm_import_get_stdout() int32
+
+func GetStdout() *wasi_io_0_2_8_streams.OutputStream {
+
+ result := wasm_import_get_stdout()
+ return wasi_io_0_2_8_streams.OutputStreamFromOwnHandle(int32(uintptr(result)))
+
+}
diff --git a/imports/wasi_cli_0_2_8_terminal_input/empty.s b/imports/wasi_cli_0_2_8_terminal_input/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_terminal_input/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_cli_0_2_8_terminal_input/wit_bindings.go b/imports/wasi_cli_0_2_8_terminal_input/wit_bindings.go
new file mode 100644
index 0000000..aa66d63
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_terminal_input/wit_bindings.go
@@ -0,0 +1,71 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_cli_0_2_8_terminal_input
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ "runtime"
+)
+
+//go:wasmimport wasi:cli/terminal-input@0.2.8 [resource-drop]terminal-input
+func resourceDropTerminalInput(handle int32)
+
+// The input side of a terminal.
+type TerminalInput struct {
+ handle *witRuntime.Handle
+}
+
+func (self *TerminalInput) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *TerminalInput) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *TerminalInput) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *TerminalInput) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropTerminalInput(handle)
+ }
+}
+
+func TerminalInputFromOwnHandle(handleValue int32) *TerminalInput {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &TerminalInput{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropTerminalInput(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func TerminalInputFromBorrowHandle(handleValue int32) *TerminalInput {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &TerminalInput{handle}
+}
diff --git a/imports/wasi_cli_0_2_8_terminal_output/empty.s b/imports/wasi_cli_0_2_8_terminal_output/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_terminal_output/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_cli_0_2_8_terminal_output/wit_bindings.go b/imports/wasi_cli_0_2_8_terminal_output/wit_bindings.go
new file mode 100644
index 0000000..dfffffd
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_terminal_output/wit_bindings.go
@@ -0,0 +1,71 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_cli_0_2_8_terminal_output
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ "runtime"
+)
+
+//go:wasmimport wasi:cli/terminal-output@0.2.8 [resource-drop]terminal-output
+func resourceDropTerminalOutput(handle int32)
+
+// The output side of a terminal.
+type TerminalOutput struct {
+ handle *witRuntime.Handle
+}
+
+func (self *TerminalOutput) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *TerminalOutput) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *TerminalOutput) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *TerminalOutput) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropTerminalOutput(handle)
+ }
+}
+
+func TerminalOutputFromOwnHandle(handleValue int32) *TerminalOutput {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &TerminalOutput{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropTerminalOutput(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func TerminalOutputFromBorrowHandle(handleValue int32) *TerminalOutput {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &TerminalOutput{handle}
+}
diff --git a/imports/wasi_cli_0_2_8_terminal_stderr/empty.s b/imports/wasi_cli_0_2_8_terminal_stderr/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_terminal_stderr/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_cli_0_2_8_terminal_stderr/wit_bindings.go b/imports/wasi_cli_0_2_8_terminal_stderr/wit_bindings.go
new file mode 100644
index 0000000..28bf501
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_terminal_stderr/wit_bindings.go
@@ -0,0 +1,57 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_cli_0_2_8_terminal_stderr
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_cli_0_2_8_terminal_output"
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+type TerminalOutput = wasi_cli_0_2_8_terminal_output.TerminalOutput
+
+//go:wasmimport wasi:cli/terminal-stderr@0.2.8 get-terminal-stderr
+func wasm_import_get_terminal_stderr(arg0 uintptr)
+
+func GetTerminalStderr() witTypes.Option[*wasi_cli_0_2_8_terminal_output.TerminalOutput] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_get_terminal_stderr(returnArea)
+ var option witTypes.Option[*wasi_cli_0_2_8_terminal_output.TerminalOutput]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[*wasi_cli_0_2_8_terminal_output.TerminalOutput]()
+ case 1:
+
+ option = witTypes.Some[*wasi_cli_0_2_8_terminal_output.TerminalOutput](wasi_cli_0_2_8_terminal_output.TerminalOutputFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
diff --git a/imports/wasi_cli_0_2_8_terminal_stdin/empty.s b/imports/wasi_cli_0_2_8_terminal_stdin/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_terminal_stdin/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_cli_0_2_8_terminal_stdin/wit_bindings.go b/imports/wasi_cli_0_2_8_terminal_stdin/wit_bindings.go
new file mode 100644
index 0000000..a3f311e
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_terminal_stdin/wit_bindings.go
@@ -0,0 +1,57 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_cli_0_2_8_terminal_stdin
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_cli_0_2_8_terminal_input"
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+type TerminalInput = wasi_cli_0_2_8_terminal_input.TerminalInput
+
+//go:wasmimport wasi:cli/terminal-stdin@0.2.8 get-terminal-stdin
+func wasm_import_get_terminal_stdin(arg0 uintptr)
+
+func GetTerminalStdin() witTypes.Option[*wasi_cli_0_2_8_terminal_input.TerminalInput] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_get_terminal_stdin(returnArea)
+ var option witTypes.Option[*wasi_cli_0_2_8_terminal_input.TerminalInput]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[*wasi_cli_0_2_8_terminal_input.TerminalInput]()
+ case 1:
+
+ option = witTypes.Some[*wasi_cli_0_2_8_terminal_input.TerminalInput](wasi_cli_0_2_8_terminal_input.TerminalInputFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
diff --git a/imports/wasi_cli_0_2_8_terminal_stdout/empty.s b/imports/wasi_cli_0_2_8_terminal_stdout/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_terminal_stdout/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_cli_0_2_8_terminal_stdout/wit_bindings.go b/imports/wasi_cli_0_2_8_terminal_stdout/wit_bindings.go
new file mode 100644
index 0000000..f45fc12
--- /dev/null
+++ b/imports/wasi_cli_0_2_8_terminal_stdout/wit_bindings.go
@@ -0,0 +1,57 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_cli_0_2_8_terminal_stdout
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_cli_0_2_8_terminal_output"
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+type TerminalOutput = wasi_cli_0_2_8_terminal_output.TerminalOutput
+
+//go:wasmimport wasi:cli/terminal-stdout@0.2.8 get-terminal-stdout
+func wasm_import_get_terminal_stdout(arg0 uintptr)
+
+func GetTerminalStdout() witTypes.Option[*wasi_cli_0_2_8_terminal_output.TerminalOutput] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_get_terminal_stdout(returnArea)
+ var option witTypes.Option[*wasi_cli_0_2_8_terminal_output.TerminalOutput]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[*wasi_cli_0_2_8_terminal_output.TerminalOutput]()
+ case 1:
+
+ option = witTypes.Some[*wasi_cli_0_2_8_terminal_output.TerminalOutput](wasi_cli_0_2_8_terminal_output.TerminalOutputFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
diff --git a/imports/wasi_cli_0_3_0_stderr/empty.s b/imports/wasi_cli_0_3_0_stderr/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_cli_0_3_0_stderr/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_cli_0_3_0_stderr/wit_bindings.go b/imports/wasi_cli_0_3_0_stderr/wit_bindings.go
new file mode 100644
index 0000000..984ec69
--- /dev/null
+++ b/imports/wasi_cli_0_3_0_stderr/wit_bindings.go
@@ -0,0 +1,118 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_cli_0_3_0_stderr
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_cli_0_3_0_types"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+//go:wasmimport wasi:cli/stderr@0.3.0 [future-new-1]write-via-stream
+func wasm_future_new_result_unit_wasi_cli_0_3_0_types_error_code() uint64
+
+//go:wasmimport wasi:cli/stderr@0.3.0 [async-lower][future-read-1]write-via-stream
+func wasm_future_read_result_unit_wasi_cli_0_3_0_types_error_code(handle int32, item unsafe.Pointer) uint32
+
+//go:wasmimport wasi:cli/stderr@0.3.0 [async-lower][future-write-1]write-via-stream
+func wasm_future_write_result_unit_wasi_cli_0_3_0_types_error_code(handle int32, item unsafe.Pointer) uint32
+
+//go:wasmimport wasi:cli/stderr@0.3.0 [future-drop-readable-1]write-via-stream
+func wasm_future_drop_readable_result_unit_wasi_cli_0_3_0_types_error_code(handle int32)
+
+//go:wasmimport wasi:cli/stderr@0.3.0 [future-drop-writable-1]write-via-stream
+func wasm_future_drop_writable_result_unit_wasi_cli_0_3_0_types_error_code(handle int32)
+
+func wasm_future_lift_result_unit_wasi_cli_0_3_0_types_error_code(src unsafe.Pointer) witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode] {
+ var result witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 1)))))
+ default:
+ panic("unreachable")
+ }
+
+ return result
+}
+
+func wasm_future_lower_result_unit_wasi_cli_0_3_0_types_error_code(
+ pinner *runtime.Pinner,
+ value witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode],
+ dst unsafe.Pointer,
+) func() {
+
+ switch value.Tag() {
+ case witTypes.ResultOk:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 0)) = int8(int32(0))
+
+ case witTypes.ResultErr:
+ payload := value.Err()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 0)) = int8(int32(1))
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 1)) = int8(int32(payload))
+
+ default:
+ panic("unreachable")
+ }
+
+ return func() {}
+}
+
+var wasm_future_vtable_result_unit_wasi_cli_0_3_0_types_error_code = witTypes.FutureVtable[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]]{
+ 2,
+ 1,
+ wasm_future_read_result_unit_wasi_cli_0_3_0_types_error_code,
+ wasm_future_write_result_unit_wasi_cli_0_3_0_types_error_code,
+ nil,
+ nil,
+ wasm_future_drop_readable_result_unit_wasi_cli_0_3_0_types_error_code,
+ wasm_future_drop_writable_result_unit_wasi_cli_0_3_0_types_error_code,
+ wasm_future_lift_result_unit_wasi_cli_0_3_0_types_error_code,
+ wasm_future_lower_result_unit_wasi_cli_0_3_0_types_error_code,
+}
+
+func MakeFutureResultUnitWasiCli030TypesErrorCode() (*witTypes.FutureWriter[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]], *witTypes.FutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]]) {
+ pair := wasm_future_new_result_unit_wasi_cli_0_3_0_types_error_code()
+ return witTypes.MakeFutureWriter[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]](&wasm_future_vtable_result_unit_wasi_cli_0_3_0_types_error_code, int32(pair>>32)),
+ witTypes.MakeFutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]](&wasm_future_vtable_result_unit_wasi_cli_0_3_0_types_error_code, int32(pair&0xFFFFFFFF))
+}
+
+func LiftFutureResultUnitWasiCli030TypesErrorCode(handle int32) *witTypes.FutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]] {
+ return witTypes.MakeFutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]](&wasm_future_vtable_result_unit_wasi_cli_0_3_0_types_error_code, handle)
+}
+
+type ErrorCode = wasi_cli_0_3_0_types.ErrorCode
+
+//go:wasmimport wasi:cli/stderr@0.3.0 write-via-stream
+func wasm_import_write_via_stream(arg0 int32) int32
+
+func WriteViaStream(data *witTypes.StreamReader[uint8]) *witTypes.FutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]] {
+
+ result := wasm_import_write_via_stream((data).TakeHandle())
+ return LiftFutureResultUnitWasiCli030TypesErrorCode(result)
+
+}
diff --git a/imports/wasi_cli_0_3_0_stdin/empty.s b/imports/wasi_cli_0_3_0_stdin/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_cli_0_3_0_stdin/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_cli_0_3_0_stdin/wit_bindings.go b/imports/wasi_cli_0_3_0_stdin/wit_bindings.go
new file mode 100644
index 0000000..562a2a4
--- /dev/null
+++ b/imports/wasi_cli_0_3_0_stdin/wit_bindings.go
@@ -0,0 +1,125 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_cli_0_3_0_stdin
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_cli_0_3_0_stdout"
+ "go.bytecodealliance.org/pkg/imports/wasi_cli_0_3_0_types"
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+//go:wasmimport wasi:cli/stdin@0.3.0 [future-new-1]read-via-stream
+func wasm_future_new_result_unit_wasi_cli_0_3_0_types_error_code() uint64
+
+//go:wasmimport wasi:cli/stdin@0.3.0 [async-lower][future-read-1]read-via-stream
+func wasm_future_read_result_unit_wasi_cli_0_3_0_types_error_code(handle int32, item unsafe.Pointer) uint32
+
+//go:wasmimport wasi:cli/stdin@0.3.0 [async-lower][future-write-1]read-via-stream
+func wasm_future_write_result_unit_wasi_cli_0_3_0_types_error_code(handle int32, item unsafe.Pointer) uint32
+
+//go:wasmimport wasi:cli/stdin@0.3.0 [future-drop-readable-1]read-via-stream
+func wasm_future_drop_readable_result_unit_wasi_cli_0_3_0_types_error_code(handle int32)
+
+//go:wasmimport wasi:cli/stdin@0.3.0 [future-drop-writable-1]read-via-stream
+func wasm_future_drop_writable_result_unit_wasi_cli_0_3_0_types_error_code(handle int32)
+
+func wasm_future_lift_result_unit_wasi_cli_0_3_0_types_error_code(src unsafe.Pointer) witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode] {
+ var result witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 1)))))
+ default:
+ panic("unreachable")
+ }
+
+ return result
+}
+
+func wasm_future_lower_result_unit_wasi_cli_0_3_0_types_error_code(
+ pinner *runtime.Pinner,
+ value witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode],
+ dst unsafe.Pointer,
+) func() {
+
+ switch value.Tag() {
+ case witTypes.ResultOk:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 0)) = int8(int32(0))
+
+ case witTypes.ResultErr:
+ payload := value.Err()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 0)) = int8(int32(1))
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 1)) = int8(int32(payload))
+
+ default:
+ panic("unreachable")
+ }
+
+ return func() {}
+}
+
+var wasm_future_vtable_result_unit_wasi_cli_0_3_0_types_error_code = witTypes.FutureVtable[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]]{
+ 2,
+ 1,
+ wasm_future_read_result_unit_wasi_cli_0_3_0_types_error_code,
+ wasm_future_write_result_unit_wasi_cli_0_3_0_types_error_code,
+ nil,
+ nil,
+ wasm_future_drop_readable_result_unit_wasi_cli_0_3_0_types_error_code,
+ wasm_future_drop_writable_result_unit_wasi_cli_0_3_0_types_error_code,
+ wasm_future_lift_result_unit_wasi_cli_0_3_0_types_error_code,
+ wasm_future_lower_result_unit_wasi_cli_0_3_0_types_error_code,
+}
+
+func MakeFutureResultUnitWasiCli030TypesErrorCode() (*witTypes.FutureWriter[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]], *witTypes.FutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]]) {
+ pair := wasm_future_new_result_unit_wasi_cli_0_3_0_types_error_code()
+ return witTypes.MakeFutureWriter[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]](&wasm_future_vtable_result_unit_wasi_cli_0_3_0_types_error_code, int32(pair>>32)),
+ witTypes.MakeFutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]](&wasm_future_vtable_result_unit_wasi_cli_0_3_0_types_error_code, int32(pair&0xFFFFFFFF))
+}
+
+func LiftFutureResultUnitWasiCli030TypesErrorCode(handle int32) *witTypes.FutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]] {
+ return witTypes.MakeFutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]](&wasm_future_vtable_result_unit_wasi_cli_0_3_0_types_error_code, handle)
+}
+
+type ErrorCode = wasi_cli_0_3_0_types.ErrorCode
+
+//go:wasmimport wasi:cli/stdin@0.3.0 read-via-stream
+func wasm_import_read_via_stream(arg0 uintptr)
+
+func ReadViaStream() (*witTypes.StreamReader[uint8], *witTypes.FutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]]) {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_read_via_stream(returnArea)
+ result := witTypes.Tuple2[*witTypes.StreamReader[uint8], *witTypes.FutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]]]{wasi_cli_0_3_0_stdout.LiftStreamU8(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 0))), LiftFutureResultUnitWasiCli030TypesErrorCode(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))}
+ tuple := result
+ return tuple.F0, tuple.F1
+
+}
diff --git a/imports/wasi_cli_0_3_0_stdout/empty.s b/imports/wasi_cli_0_3_0_stdout/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_cli_0_3_0_stdout/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_cli_0_3_0_stdout/wit_bindings.go b/imports/wasi_cli_0_3_0_stdout/wit_bindings.go
new file mode 100644
index 0000000..0928e07
--- /dev/null
+++ b/imports/wasi_cli_0_3_0_stdout/wit_bindings.go
@@ -0,0 +1,156 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_cli_0_3_0_stdout
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_cli_0_3_0_types"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+//go:wasmimport wasi:cli/stdout@0.3.0 [stream-new-0]write-via-stream
+func wasm_stream_new_u8() uint64
+
+//go:wasmimport wasi:cli/stdout@0.3.0 [async-lower][stream-read-0]write-via-stream
+func wasm_stream_read_u8(handle int32, item unsafe.Pointer, count uint32) uint32
+
+//go:wasmimport wasi:cli/stdout@0.3.0 [async-lower][stream-write-0]write-via-stream
+func wasm_stream_write_u8(handle int32, item unsafe.Pointer, count uint32) uint32
+
+//go:wasmimport wasi:cli/stdout@0.3.0 [stream-drop-readable-0]write-via-stream
+func wasm_stream_drop_readable_u8(handle int32)
+
+//go:wasmimport wasi:cli/stdout@0.3.0 [stream-drop-writable-0]write-via-stream
+func wasm_stream_drop_writable_u8(handle int32)
+
+var wasm_stream_vtable_u8 = witTypes.StreamVtable[uint8]{
+ 1,
+ 1,
+ wasm_stream_read_u8,
+ wasm_stream_write_u8,
+ nil,
+ nil,
+ wasm_stream_drop_readable_u8,
+ wasm_stream_drop_writable_u8,
+ nil,
+ nil,
+}
+
+func MakeStreamU8() (*witTypes.StreamWriter[uint8], *witTypes.StreamReader[uint8]) {
+ pair := wasm_stream_new_u8()
+ return witTypes.MakeStreamWriter[uint8](&wasm_stream_vtable_u8, int32(pair>>32)),
+ witTypes.MakeStreamReader[uint8](&wasm_stream_vtable_u8, int32(pair&0xFFFFFFFF))
+}
+
+func LiftStreamU8(handle int32) *witTypes.StreamReader[uint8] {
+ return witTypes.MakeStreamReader[uint8](&wasm_stream_vtable_u8, handle)
+}
+
+//go:wasmimport wasi:cli/stdout@0.3.0 [future-new-1]write-via-stream
+func wasm_future_new_result_unit_wasi_cli_0_3_0_types_error_code() uint64
+
+//go:wasmimport wasi:cli/stdout@0.3.0 [async-lower][future-read-1]write-via-stream
+func wasm_future_read_result_unit_wasi_cli_0_3_0_types_error_code(handle int32, item unsafe.Pointer) uint32
+
+//go:wasmimport wasi:cli/stdout@0.3.0 [async-lower][future-write-1]write-via-stream
+func wasm_future_write_result_unit_wasi_cli_0_3_0_types_error_code(handle int32, item unsafe.Pointer) uint32
+
+//go:wasmimport wasi:cli/stdout@0.3.0 [future-drop-readable-1]write-via-stream
+func wasm_future_drop_readable_result_unit_wasi_cli_0_3_0_types_error_code(handle int32)
+
+//go:wasmimport wasi:cli/stdout@0.3.0 [future-drop-writable-1]write-via-stream
+func wasm_future_drop_writable_result_unit_wasi_cli_0_3_0_types_error_code(handle int32)
+
+func wasm_future_lift_result_unit_wasi_cli_0_3_0_types_error_code(src unsafe.Pointer) witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode] {
+ var result witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 1)))))
+ default:
+ panic("unreachable")
+ }
+
+ return result
+}
+
+func wasm_future_lower_result_unit_wasi_cli_0_3_0_types_error_code(
+ pinner *runtime.Pinner,
+ value witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode],
+ dst unsafe.Pointer,
+) func() {
+
+ switch value.Tag() {
+ case witTypes.ResultOk:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 0)) = int8(int32(0))
+
+ case witTypes.ResultErr:
+ payload := value.Err()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 0)) = int8(int32(1))
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 1)) = int8(int32(payload))
+
+ default:
+ panic("unreachable")
+ }
+
+ return func() {}
+}
+
+var wasm_future_vtable_result_unit_wasi_cli_0_3_0_types_error_code = witTypes.FutureVtable[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]]{
+ 2,
+ 1,
+ wasm_future_read_result_unit_wasi_cli_0_3_0_types_error_code,
+ wasm_future_write_result_unit_wasi_cli_0_3_0_types_error_code,
+ nil,
+ nil,
+ wasm_future_drop_readable_result_unit_wasi_cli_0_3_0_types_error_code,
+ wasm_future_drop_writable_result_unit_wasi_cli_0_3_0_types_error_code,
+ wasm_future_lift_result_unit_wasi_cli_0_3_0_types_error_code,
+ wasm_future_lower_result_unit_wasi_cli_0_3_0_types_error_code,
+}
+
+func MakeFutureResultUnitWasiCli030TypesErrorCode() (*witTypes.FutureWriter[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]], *witTypes.FutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]]) {
+ pair := wasm_future_new_result_unit_wasi_cli_0_3_0_types_error_code()
+ return witTypes.MakeFutureWriter[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]](&wasm_future_vtable_result_unit_wasi_cli_0_3_0_types_error_code, int32(pair>>32)),
+ witTypes.MakeFutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]](&wasm_future_vtable_result_unit_wasi_cli_0_3_0_types_error_code, int32(pair&0xFFFFFFFF))
+}
+
+func LiftFutureResultUnitWasiCli030TypesErrorCode(handle int32) *witTypes.FutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]] {
+ return witTypes.MakeFutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]](&wasm_future_vtable_result_unit_wasi_cli_0_3_0_types_error_code, handle)
+}
+
+type ErrorCode = wasi_cli_0_3_0_types.ErrorCode
+
+//go:wasmimport wasi:cli/stdout@0.3.0 write-via-stream
+func wasm_import_write_via_stream(arg0 int32) int32
+
+func WriteViaStream(data *witTypes.StreamReader[uint8]) *witTypes.FutureReader[witTypes.Result[witTypes.Unit, wasi_cli_0_3_0_types.ErrorCode]] {
+
+ result := wasm_import_write_via_stream((data).TakeHandle())
+ return LiftFutureResultUnitWasiCli030TypesErrorCode(result)
+
+}
diff --git a/imports/wasi_cli_0_3_0_types/empty.s b/imports/wasi_cli_0_3_0_types/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_cli_0_3_0_types/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_cli_0_3_0_types/wit_bindings.go b/imports/wasi_cli_0_3_0_types/wit_bindings.go
new file mode 100644
index 0000000..9544d99
--- /dev/null
+++ b/imports/wasi_cli_0_3_0_types/wit_bindings.go
@@ -0,0 +1,35 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_cli_0_3_0_types
+
+import ()
+
+const (
+ // Input/output error
+ ErrorCodeIo uint8 = 0
+ // Invalid or incomplete multibyte or wide character
+ ErrorCodeIllegalByteSequence uint8 = 1
+ // Broken pipe
+ ErrorCodePipe uint8 = 2
+)
+
+type ErrorCode = uint8
diff --git a/imports/wasi_clocks_0_2_8_monotonic_clock/empty.s b/imports/wasi_clocks_0_2_8_monotonic_clock/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_clocks_0_2_8_monotonic_clock/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_clocks_0_2_8_monotonic_clock/wit_bindings.go b/imports/wasi_clocks_0_2_8_monotonic_clock/wit_bindings.go
new file mode 100644
index 0000000..9c32591
--- /dev/null
+++ b/imports/wasi_clocks_0_2_8_monotonic_clock/wit_bindings.go
@@ -0,0 +1,76 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_clocks_0_2_8_monotonic_clock
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_poll"
+)
+
+type Pollable = wasi_io_0_2_8_poll.Pollable
+
+// An instant in time, in nanoseconds. An instant is relative to an
+// unspecified initial value, and can only be compared to instances from
+// the same monotonic-clock.
+type Instant = uint64
+
+// A duration of time, in nanoseconds.
+type Duration = uint64
+
+//go:wasmimport wasi:clocks/monotonic-clock@0.2.8 now
+func wasm_import_now() int64
+
+func Now() uint64 {
+
+ result := wasm_import_now()
+ return uint64(result)
+
+}
+
+//go:wasmimport wasi:clocks/monotonic-clock@0.2.8 resolution
+func wasm_import_resolution() int64
+
+func Resolution() uint64 {
+
+ result := wasm_import_resolution()
+ return uint64(result)
+
+}
+
+//go:wasmimport wasi:clocks/monotonic-clock@0.2.8 subscribe-instant
+func wasm_import_subscribe_instant(arg0 int64) int32
+
+func SubscribeInstant(when uint64) *wasi_io_0_2_8_poll.Pollable {
+
+ result := wasm_import_subscribe_instant(int64(when))
+ return wasi_io_0_2_8_poll.PollableFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:clocks/monotonic-clock@0.2.8 subscribe-duration
+func wasm_import_subscribe_duration(arg0 int64) int32
+
+func SubscribeDuration(when uint64) *wasi_io_0_2_8_poll.Pollable {
+
+ result := wasm_import_subscribe_duration(int64(when))
+ return wasi_io_0_2_8_poll.PollableFromOwnHandle(int32(uintptr(result)))
+
+}
diff --git a/imports/wasi_clocks_0_2_8_wall_clock/empty.s b/imports/wasi_clocks_0_2_8_wall_clock/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_clocks_0_2_8_wall_clock/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_clocks_0_2_8_wall_clock/wit_bindings.go b/imports/wasi_clocks_0_2_8_wall_clock/wit_bindings.go
new file mode 100644
index 0000000..d7f503e
--- /dev/null
+++ b/imports/wasi_clocks_0_2_8_wall_clock/wit_bindings.go
@@ -0,0 +1,62 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_clocks_0_2_8_wall_clock
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ "runtime"
+ "unsafe"
+)
+
+// A time and date in seconds plus nanoseconds.
+type Datetime struct {
+ Seconds uint64
+ Nanoseconds uint32
+}
+
+//go:wasmimport wasi:clocks/wall-clock@0.2.8 now
+func wasm_import_now(arg0 uintptr)
+
+func Now() Datetime {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_now(returnArea)
+ result := Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 0))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))}
+ return result
+
+}
+
+//go:wasmimport wasi:clocks/wall-clock@0.2.8 resolution
+func wasm_import_resolution(arg0 uintptr)
+
+func Resolution() Datetime {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_resolution(returnArea)
+ result := Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 0))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))}
+ return result
+
+}
diff --git a/imports/wasi_clocks_0_3_0_monotonic_clock/empty.s b/imports/wasi_clocks_0_3_0_monotonic_clock/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_clocks_0_3_0_monotonic_clock/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_clocks_0_3_0_monotonic_clock/wit_bindings.go b/imports/wasi_clocks_0_3_0_monotonic_clock/wit_bindings.go
new file mode 100644
index 0000000..6e52d76
--- /dev/null
+++ b/imports/wasi_clocks_0_3_0_monotonic_clock/wit_bindings.go
@@ -0,0 +1,71 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_clocks_0_3_0_monotonic_clock
+
+import (
+ witAsync "go.bytecodealliance.org/pkg/wit/async"
+)
+
+type Duration = uint64
+
+// A mark on a monotonic clock is a number of nanoseconds since an
+// unspecified initial value, and can only be compared to instances from
+// the same monotonic-clock.
+type Mark = uint64
+
+//go:wasmimport wasi:clocks/monotonic-clock@0.3.0 now
+func wasm_import_now() int64
+
+func Now() uint64 {
+
+ result := wasm_import_now()
+ return uint64(result)
+
+}
+
+//go:wasmimport wasi:clocks/monotonic-clock@0.3.0 get-resolution
+func wasm_import_get_resolution() int64
+
+func GetResolution() uint64 {
+
+ result := wasm_import_get_resolution()
+ return uint64(result)
+
+}
+
+//go:wasmimport wasi:clocks/monotonic-clock@0.3.0 [async-lower]wait-until
+func wasm_import_wait_until(arg0 int64) int32
+
+func WaitUntil(when uint64) {
+
+ witAsync.SubtaskWait(uint32(wasm_import_wait_until(int64(when))))
+
+}
+
+//go:wasmimport wasi:clocks/monotonic-clock@0.3.0 [async-lower]wait-for
+func wasm_import_wait_for(arg0 int64) int32
+
+func WaitFor(howLong uint64) {
+
+ witAsync.SubtaskWait(uint32(wasm_import_wait_for(int64(howLong))))
+
+}
diff --git a/imports/wasi_clocks_0_3_0_system_clock/empty.s b/imports/wasi_clocks_0_3_0_system_clock/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_clocks_0_3_0_system_clock/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_clocks_0_3_0_system_clock/wit_bindings.go b/imports/wasi_clocks_0_3_0_system_clock/wit_bindings.go
new file mode 100644
index 0000000..90da421
--- /dev/null
+++ b/imports/wasi_clocks_0_3_0_system_clock/wit_bindings.go
@@ -0,0 +1,75 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_clocks_0_3_0_system_clock
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ "runtime"
+ "unsafe"
+)
+
+type Duration = uint64
+
+// An "instant", or "exact time", is a point in time without regard to any
+// time zone: just the time since a particular external reference point,
+// often called an "epoch".
+//
+// Here, the epoch is 1970-01-01T00:00:00Z, also known as
+// [POSIX's Seconds Since the Epoch], also known as [Unix Time].
+//
+// Note that even if the seconds field is negative, incrementing
+// nanoseconds always represents moving forwards in time.
+// For example, `{ -1 seconds, 999999999 nanoseconds }` represents the
+// instant one nanosecond before the epoch.
+// For more on various different ways to represent time, see
+// https://tc39.es/proposal-temporal/docs/timezone.html
+//
+// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
+// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
+type Instant struct {
+ Seconds int64
+ Nanoseconds uint32
+}
+
+//go:wasmimport wasi:clocks/system-clock@0.3.0 now
+func wasm_import_now(arg0 uintptr)
+
+func Now() Instant {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_now(returnArea)
+ result := Instant{*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 0)), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))}
+ return result
+
+}
+
+//go:wasmimport wasi:clocks/system-clock@0.3.0 get-resolution
+func wasm_import_get_resolution() int64
+
+func GetResolution() uint64 {
+
+ result := wasm_import_get_resolution()
+ return uint64(result)
+
+}
diff --git a/imports/wasi_clocks_0_3_0_types/empty.s b/imports/wasi_clocks_0_3_0_types/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_clocks_0_3_0_types/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_clocks_0_3_0_types/wit_bindings.go b/imports/wasi_clocks_0_3_0_types/wit_bindings.go
new file mode 100644
index 0000000..7f0193a
--- /dev/null
+++ b/imports/wasi_clocks_0_3_0_types/wit_bindings.go
@@ -0,0 +1,27 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_clocks_0_3_0_types
+
+import ()
+
+// A duration of time, in nanoseconds.
+type Duration = uint64
diff --git a/imports/wasi_config_0_2_0_rc_1_store/empty.s b/imports/wasi_config_0_2_0_rc_1_store/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_config_0_2_0_rc_1_store/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_config_0_2_0_rc_1_store/wit_bindings.go b/imports/wasi_config_0_2_0_rc_1_store/wit_bindings.go
new file mode 100644
index 0000000..96bea2e
--- /dev/null
+++ b/imports/wasi_config_0_2_0_rc_1_store/wit_bindings.go
@@ -0,0 +1,175 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_config_0_2_0_rc_1_store
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+const (
+ // This indicates an error from an "upstream" config source.
+ // As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue buckets, etc),
+ // the error message is a string.
+ ErrorUpstream uint8 = 0
+ // This indicates an error from an I/O operation.
+ // As this could be almost _anything_ (such as a file read, network connection, etc),
+ // the error message is a string.
+ // Depending on how this ends up being consumed,
+ // we may consider moving this to use the `wasi:io/error` type instead.
+ // For simplicity right now in supporting multiple implementations, it is being left as a string.
+ ErrorIo uint8 = 1
+)
+
+// An error type that encapsulates the different errors that can occur fetching configuration values.
+type Error struct {
+ tag uint8
+ value any
+}
+
+func (self Error) Tag() uint8 {
+ return self.tag
+}
+
+func (self Error) Upstream() string {
+ if self.tag != ErrorUpstream {
+ panic("tag mismatch")
+ }
+ return self.value.(string)
+}
+func (self Error) Io() string {
+ if self.tag != ErrorIo {
+ panic("tag mismatch")
+ }
+ return self.value.(string)
+}
+
+func MakeErrorUpstream(value string) Error {
+ return Error{ErrorUpstream, value}
+}
+func MakeErrorIo(value string) Error {
+ return Error{ErrorIo, value}
+}
+
+//go:wasmimport wasi:config/store@0.2.0-rc.1 get
+func wasm_import_get(arg0 uintptr, arg1 uint32, arg2 uintptr)
+
+func Get(key string) witTypes.Result[witTypes.Option[string], Error] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4))
+ utf8 := unsafe.Pointer(unsafe.StringData(key))
+ pinner.Pin(utf8)
+ wasm_import_get(uintptr(utf8), uint32(len(key)), returnArea)
+ var result witTypes.Result[witTypes.Option[string], Error]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))
+
+ option = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Ok[witTypes.Option[string], Error](option)
+ case 1:
+ var variant Error
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+ value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))
+
+ variant = MakeErrorUpstream(value0)
+
+ case 1:
+ value1 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))
+
+ variant = MakeErrorIo(value1)
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Option[string], Error](variant)
+ default:
+ panic("unreachable")
+ }
+ result2 := result
+ return result2
+
+}
+
+//go:wasmimport wasi:config/store@0.2.0-rc.1 get-all
+func wasm_import_get_all(arg0 uintptr)
+
+func GetAll() witTypes.Result[[]witTypes.Tuple2[string, string], Error] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4))
+ wasm_import_get_all(returnArea)
+ var result3 witTypes.Result[[]witTypes.Tuple2[string, string], Error]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ result := make([]witTypes.Tuple2[string, string], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+ for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ {
+ base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(4*4))
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)))
+ value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4))))
+
+ result = append(result, witTypes.Tuple2[string, string]{value, value0})
+ }
+
+ result3 = witTypes.Ok[[]witTypes.Tuple2[string, string], Error](result)
+ case 1:
+ var variant Error
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+ value1 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))
+
+ variant = MakeErrorUpstream(value1)
+
+ case 1:
+ value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))
+
+ variant = MakeErrorIo(value2)
+
+ default:
+ panic("unreachable")
+ }
+
+ result3 = witTypes.Err[[]witTypes.Tuple2[string, string], Error](variant)
+ default:
+ panic("unreachable")
+ }
+ result4 := result3
+ return result4
+
+}
diff --git a/imports/wasi_filesystem_0_2_8_preopens/empty.s b/imports/wasi_filesystem_0_2_8_preopens/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_filesystem_0_2_8_preopens/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_filesystem_0_2_8_preopens/wit_bindings.go b/imports/wasi_filesystem_0_2_8_preopens/wit_bindings.go
new file mode 100644
index 0000000..88b2078
--- /dev/null
+++ b/imports/wasi_filesystem_0_2_8_preopens/wit_bindings.go
@@ -0,0 +1,54 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_filesystem_0_2_8_preopens
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_filesystem_0_2_8_types"
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+type Descriptor = wasi_filesystem_0_2_8_types.Descriptor
+
+//go:wasmimport wasi:filesystem/preopens@0.2.8 get-directories
+func wasm_import_get_directories(arg0 uintptr)
+
+func GetDirectories() []witTypes.Tuple2[*wasi_filesystem_0_2_8_types.Descriptor, string] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4))
+ wasm_import_get_directories(returnArea)
+ result := make([]witTypes.Tuple2[*wasi_filesystem_0_2_8_types.Descriptor, string], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
+ for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ {
+ base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0)))), index*(3*4))
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4))))
+
+ result = append(result, witTypes.Tuple2[*wasi_filesystem_0_2_8_types.Descriptor, string]{wasi_filesystem_0_2_8_types.DescriptorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(base), 0))))), value})
+ }
+
+ result0 := result
+ return result0
+
+}
diff --git a/imports/wasi_filesystem_0_2_8_types/empty.s b/imports/wasi_filesystem_0_2_8_types/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_filesystem_0_2_8_types/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_filesystem_0_2_8_types/wit_bindings.go b/imports/wasi_filesystem_0_2_8_types/wit_bindings.go
new file mode 100644
index 0000000..d5bfb17
--- /dev/null
+++ b/imports/wasi_filesystem_0_2_8_types/wit_bindings.go
@@ -0,0 +1,1339 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_filesystem_0_2_8_types
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_clocks_0_2_8_wall_clock"
+ "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_error"
+ "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_streams"
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+type InputStream = wasi_io_0_2_8_streams.InputStream
+type OutputStream = wasi_io_0_2_8_streams.OutputStream
+type Error = wasi_io_0_2_8_error.Error
+type Datetime = wasi_clocks_0_2_8_wall_clock.Datetime
+
+// File size or length of a region within a file.
+type Filesize = uint64
+
+const (
+ // The type of the descriptor or file is unknown or is different from
+ // any of the other types specified.
+ DescriptorTypeUnknown uint8 = 0
+ // The descriptor refers to a block device inode.
+ DescriptorTypeBlockDevice uint8 = 1
+ // The descriptor refers to a character device inode.
+ DescriptorTypeCharacterDevice uint8 = 2
+ // The descriptor refers to a directory inode.
+ DescriptorTypeDirectory uint8 = 3
+ // The descriptor refers to a named pipe.
+ DescriptorTypeFifo uint8 = 4
+ // The file refers to a symbolic link inode.
+ DescriptorTypeSymbolicLink uint8 = 5
+ // The descriptor refers to a regular file inode.
+ DescriptorTypeRegularFile uint8 = 6
+ // The descriptor refers to a socket.
+ DescriptorTypeSocket uint8 = 7
+)
+
+// The type of a filesystem object referenced by a descriptor.
+//
+// Note: This was called `filetype` in earlier versions of WASI.
+type DescriptorType = uint8
+
+const (
+ // Read mode: Data can be read.
+ DescriptorFlagsRead uint8 = 1 << 0
+ // Write mode: Data can be written to.
+ DescriptorFlagsWrite uint8 = 1 << 1
+ // Request that writes be performed according to synchronized I/O file
+ // integrity completion. The data stored in the file and the file's
+ // metadata are synchronized. This is similar to `O_SYNC` in POSIX.
+ //
+ // The precise semantics of this operation have not yet been defined for
+ // WASI. At this time, it should be interpreted as a request, and not a
+ // requirement.
+ DescriptorFlagsFileIntegritySync uint8 = 1 << 2
+ // Request that writes be performed according to synchronized I/O data
+ // integrity completion. Only the data stored in the file is
+ // synchronized. This is similar to `O_DSYNC` in POSIX.
+ //
+ // The precise semantics of this operation have not yet been defined for
+ // WASI. At this time, it should be interpreted as a request, and not a
+ // requirement.
+ DescriptorFlagsDataIntegritySync uint8 = 1 << 3
+ // Requests that reads be performed at the same level of integrity
+ // requested for writes. This is similar to `O_RSYNC` in POSIX.
+ //
+ // The precise semantics of this operation have not yet been defined for
+ // WASI. At this time, it should be interpreted as a request, and not a
+ // requirement.
+ DescriptorFlagsRequestedWriteSync uint8 = 1 << 4
+ // Mutating directories mode: Directory contents may be mutated.
+ //
+ // When this flag is unset on a descriptor, operations using the
+ // descriptor which would create, rename, delete, modify the data or
+ // metadata of filesystem objects, or obtain another handle which
+ // would permit any of those, shall fail with `error-code::read-only` if
+ // they would otherwise succeed.
+ //
+ // This may only be set on directories.
+ DescriptorFlagsMutateDirectory uint8 = 1 << 5
+)
+
+// Descriptor flags.
+//
+// Note: This was called `fdflags` in earlier versions of WASI.
+type DescriptorFlags = uint8
+
+const (
+ // As long as the resolved path corresponds to a symbolic link, it is
+ // expanded.
+ PathFlagsSymlinkFollow uint8 = 1 << 0
+)
+
+// Flags determining the method of how paths are resolved.
+type PathFlags = uint8
+
+const (
+ // Create file if it does not exist, similar to `O_CREAT` in POSIX.
+ OpenFlagsCreate uint8 = 1 << 0
+ // Fail if not a directory, similar to `O_DIRECTORY` in POSIX.
+ OpenFlagsDirectory uint8 = 1 << 1
+ // Fail if file already exists, similar to `O_EXCL` in POSIX.
+ OpenFlagsExclusive uint8 = 1 << 2
+ // Truncate file to size 0, similar to `O_TRUNC` in POSIX.
+ OpenFlagsTruncate uint8 = 1 << 3
+)
+
+// Open flags used by `open-at`.
+type OpenFlags = uint8
+
+// Number of hard links to an inode.
+type LinkCount = uint64
+
+// File attributes.
+//
+// Note: This was called `filestat` in earlier versions of WASI.
+type DescriptorStat struct {
+ // File type.
+ Type DescriptorType
+ // Number of hard links to the file.
+ LinkCount uint64
+ // For regular files, the file size in bytes. For symbolic links, the
+ // length in bytes of the pathname contained in the symbolic link.
+ Size uint64
+ // Last data access timestamp.
+ //
+ // If the `option` is none, the platform doesn't maintain an access
+ // timestamp for this file.
+ DataAccessTimestamp witTypes.Option[wasi_clocks_0_2_8_wall_clock.Datetime]
+ // Last data modification timestamp.
+ //
+ // If the `option` is none, the platform doesn't maintain a
+ // modification timestamp for this file.
+ DataModificationTimestamp witTypes.Option[wasi_clocks_0_2_8_wall_clock.Datetime]
+ // Last file status-change timestamp.
+ //
+ // If the `option` is none, the platform doesn't maintain a
+ // status-change timestamp for this file.
+ StatusChangeTimestamp witTypes.Option[wasi_clocks_0_2_8_wall_clock.Datetime]
+}
+
+const (
+ // Leave the timestamp set to its previous value.
+ NewTimestampNoChange uint8 = 0
+ // Set the timestamp to the current time of the system clock associated
+ // with the filesystem.
+ NewTimestampNow uint8 = 1
+ // Set the timestamp to the given value.
+ NewTimestampTimestamp uint8 = 2
+)
+
+// When setting a timestamp, this gives the value to set it to.
+type NewTimestamp struct {
+ tag uint8
+ value any
+}
+
+func (self NewTimestamp) Tag() uint8 {
+ return self.tag
+}
+
+func (self NewTimestamp) Timestamp() wasi_clocks_0_2_8_wall_clock.Datetime {
+ if self.tag != NewTimestampTimestamp {
+ panic("tag mismatch")
+ }
+ return self.value.(wasi_clocks_0_2_8_wall_clock.Datetime)
+}
+
+func MakeNewTimestampNoChange() NewTimestamp {
+ return NewTimestamp{NewTimestampNoChange, nil}
+}
+func MakeNewTimestampNow() NewTimestamp {
+ return NewTimestamp{NewTimestampNow, nil}
+}
+func MakeNewTimestampTimestamp(value wasi_clocks_0_2_8_wall_clock.Datetime) NewTimestamp {
+ return NewTimestamp{NewTimestampTimestamp, value}
+}
+
+// A directory entry.
+type DirectoryEntry struct {
+ // The type of the file referred to by this directory entry.
+ Type DescriptorType
+ // The name of the object.
+ Name string
+}
+
+const (
+ // Permission denied, similar to `EACCES` in POSIX.
+ ErrorCodeAccess uint8 = 0
+ // Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX.
+ ErrorCodeWouldBlock uint8 = 1
+ // Connection already in progress, similar to `EALREADY` in POSIX.
+ ErrorCodeAlready uint8 = 2
+ // Bad descriptor, similar to `EBADF` in POSIX.
+ ErrorCodeBadDescriptor uint8 = 3
+ // Device or resource busy, similar to `EBUSY` in POSIX.
+ ErrorCodeBusy uint8 = 4
+ // Resource deadlock would occur, similar to `EDEADLK` in POSIX.
+ ErrorCodeDeadlock uint8 = 5
+ // Storage quota exceeded, similar to `EDQUOT` in POSIX.
+ ErrorCodeQuota uint8 = 6
+ // File exists, similar to `EEXIST` in POSIX.
+ ErrorCodeExist uint8 = 7
+ // File too large, similar to `EFBIG` in POSIX.
+ ErrorCodeFileTooLarge uint8 = 8
+ // Illegal byte sequence, similar to `EILSEQ` in POSIX.
+ ErrorCodeIllegalByteSequence uint8 = 9
+ // Operation in progress, similar to `EINPROGRESS` in POSIX.
+ ErrorCodeInProgress uint8 = 10
+ // Interrupted function, similar to `EINTR` in POSIX.
+ ErrorCodeInterrupted uint8 = 11
+ // Invalid argument, similar to `EINVAL` in POSIX.
+ ErrorCodeInvalid uint8 = 12
+ // I/O error, similar to `EIO` in POSIX.
+ ErrorCodeIo uint8 = 13
+ // Is a directory, similar to `EISDIR` in POSIX.
+ ErrorCodeIsDirectory uint8 = 14
+ // Too many levels of symbolic links, similar to `ELOOP` in POSIX.
+ ErrorCodeLoop uint8 = 15
+ // Too many links, similar to `EMLINK` in POSIX.
+ ErrorCodeTooManyLinks uint8 = 16
+ // Message too large, similar to `EMSGSIZE` in POSIX.
+ ErrorCodeMessageSize uint8 = 17
+ // Filename too long, similar to `ENAMETOOLONG` in POSIX.
+ ErrorCodeNameTooLong uint8 = 18
+ // No such device, similar to `ENODEV` in POSIX.
+ ErrorCodeNoDevice uint8 = 19
+ // No such file or directory, similar to `ENOENT` in POSIX.
+ ErrorCodeNoEntry uint8 = 20
+ // No locks available, similar to `ENOLCK` in POSIX.
+ ErrorCodeNoLock uint8 = 21
+ // Not enough space, similar to `ENOMEM` in POSIX.
+ ErrorCodeInsufficientMemory uint8 = 22
+ // No space left on device, similar to `ENOSPC` in POSIX.
+ ErrorCodeInsufficientSpace uint8 = 23
+ // Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX.
+ ErrorCodeNotDirectory uint8 = 24
+ // Directory not empty, similar to `ENOTEMPTY` in POSIX.
+ ErrorCodeNotEmpty uint8 = 25
+ // State not recoverable, similar to `ENOTRECOVERABLE` in POSIX.
+ ErrorCodeNotRecoverable uint8 = 26
+ // Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX.
+ ErrorCodeUnsupported uint8 = 27
+ // Inappropriate I/O control operation, similar to `ENOTTY` in POSIX.
+ ErrorCodeNoTty uint8 = 28
+ // No such device or address, similar to `ENXIO` in POSIX.
+ ErrorCodeNoSuchDevice uint8 = 29
+ // Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX.
+ ErrorCodeOverflow uint8 = 30
+ // Operation not permitted, similar to `EPERM` in POSIX.
+ ErrorCodeNotPermitted uint8 = 31
+ // Broken pipe, similar to `EPIPE` in POSIX.
+ ErrorCodePipe uint8 = 32
+ // Read-only file system, similar to `EROFS` in POSIX.
+ ErrorCodeReadOnly uint8 = 33
+ // Invalid seek, similar to `ESPIPE` in POSIX.
+ ErrorCodeInvalidSeek uint8 = 34
+ // Text file busy, similar to `ETXTBSY` in POSIX.
+ ErrorCodeTextFileBusy uint8 = 35
+ // Cross-device link, similar to `EXDEV` in POSIX.
+ ErrorCodeCrossDevice uint8 = 36
+)
+
+// Error codes returned by functions, similar to `errno` in POSIX.
+// Not all of these error codes are returned by the functions provided by this
+// API; some are used in higher-level library layers, and others are provided
+// merely for alignment with POSIX.
+type ErrorCode = uint8
+
+const (
+ // The application has no advice to give on its behavior with respect
+ // to the specified data.
+ AdviceNormal uint8 = 0
+ // The application expects to access the specified data sequentially
+ // from lower offsets to higher offsets.
+ AdviceSequential uint8 = 1
+ // The application expects to access the specified data in a random
+ // order.
+ AdviceRandom uint8 = 2
+ // The application expects to access the specified data in the near
+ // future.
+ AdviceWillNeed uint8 = 3
+ // The application expects that it will not access the specified data
+ // in the near future.
+ AdviceDontNeed uint8 = 4
+ // The application expects to access the specified data once and then
+ // not reuse it thereafter.
+ AdviceNoReuse uint8 = 5
+)
+
+// File or memory access pattern advisory information.
+type Advice = uint8
+
+// A 128-bit hash value, split into parts because wasm doesn't have a
+// 128-bit integer type.
+type MetadataHashValue struct {
+ // 64 bits of a 128-bit hash value.
+ Lower uint64
+ // Another 64 bits of a 128-bit hash value.
+ Upper uint64
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [resource-drop]descriptor
+func resourceDropDescriptor(handle int32)
+
+// A descriptor is a reference to a filesystem object, which may be a file,
+// directory, named pipe, special file, or other object on which filesystem
+// calls may be made.
+type Descriptor struct {
+ handle *witRuntime.Handle
+}
+
+func (self *Descriptor) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *Descriptor) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *Descriptor) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *Descriptor) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropDescriptor(handle)
+ }
+}
+
+func DescriptorFromOwnHandle(handleValue int32) *Descriptor {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &Descriptor{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropDescriptor(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func DescriptorFromBorrowHandle(handleValue int32) *Descriptor {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &Descriptor{handle}
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [resource-drop]directory-entry-stream
+func resourceDropDirectoryEntryStream(handle int32)
+
+// A stream of directory entries.
+type DirectoryEntryStream struct {
+ handle *witRuntime.Handle
+}
+
+func (self *DirectoryEntryStream) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *DirectoryEntryStream) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *DirectoryEntryStream) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *DirectoryEntryStream) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropDirectoryEntryStream(handle)
+ }
+}
+
+func DirectoryEntryStreamFromOwnHandle(handleValue int32) *DirectoryEntryStream {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &DirectoryEntryStream{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropDirectoryEntryStream(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func DirectoryEntryStreamFromBorrowHandle(handleValue int32) *DirectoryEntryStream {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &DirectoryEntryStream{handle}
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.read-via-stream
+func wasm_import_method_descriptor_read_via_stream(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *Descriptor) ReadViaStream(offset uint64) witTypes.Result[*wasi_io_0_2_8_streams.InputStream, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_method_descriptor_read_via_stream((self).Handle(), int64(offset), returnArea)
+ var result witTypes.Result[*wasi_io_0_2_8_streams.InputStream, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*wasi_io_0_2_8_streams.InputStream, ErrorCode](wasi_io_0_2_8_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+
+ result = witTypes.Err[*wasi_io_0_2_8_streams.InputStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.write-via-stream
+func wasm_import_method_descriptor_write_via_stream(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *Descriptor) WriteViaStream(offset uint64) witTypes.Result[*wasi_io_0_2_8_streams.OutputStream, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_method_descriptor_write_via_stream((self).Handle(), int64(offset), returnArea)
+ var result witTypes.Result[*wasi_io_0_2_8_streams.OutputStream, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*wasi_io_0_2_8_streams.OutputStream, ErrorCode](wasi_io_0_2_8_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+
+ result = witTypes.Err[*wasi_io_0_2_8_streams.OutputStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.append-via-stream
+func wasm_import_method_descriptor_append_via_stream(arg0 int32, arg1 uintptr)
+
+func (self *Descriptor) AppendViaStream() witTypes.Result[*wasi_io_0_2_8_streams.OutputStream, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_method_descriptor_append_via_stream((self).Handle(), returnArea)
+ var result witTypes.Result[*wasi_io_0_2_8_streams.OutputStream, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*wasi_io_0_2_8_streams.OutputStream, ErrorCode](wasi_io_0_2_8_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+
+ result = witTypes.Err[*wasi_io_0_2_8_streams.OutputStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.advise
+func wasm_import_method_descriptor_advise(arg0 int32, arg1 int64, arg2 int64, arg3 int32, arg4 uintptr)
+
+func (self *Descriptor) Advise(offset uint64, length uint64, advice Advice) witTypes.Result[witTypes.Unit, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_descriptor_advise((self).Handle(), int64(offset), int64(length), int32(advice), returnArea)
+ var result witTypes.Result[witTypes.Unit, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.sync-data
+func wasm_import_method_descriptor_sync_data(arg0 int32, arg1 uintptr)
+
+func (self *Descriptor) SyncData() witTypes.Result[witTypes.Unit, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_descriptor_sync_data((self).Handle(), returnArea)
+ var result witTypes.Result[witTypes.Unit, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.get-flags
+func wasm_import_method_descriptor_get_flags(arg0 int32, arg1 uintptr)
+
+func (self *Descriptor) GetFlags() witTypes.Result[DescriptorFlags, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_descriptor_get_flags((self).Handle(), returnArea)
+ var result witTypes.Result[DescriptorFlags, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[DescriptorFlags, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ case 1:
+
+ result = witTypes.Err[DescriptorFlags, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.get-type
+func wasm_import_method_descriptor_get_type(arg0 int32, arg1 uintptr)
+
+func (self *Descriptor) GetType() witTypes.Result[DescriptorType, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_descriptor_get_type((self).Handle(), returnArea)
+ var result witTypes.Result[DescriptorType, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[DescriptorType, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ case 1:
+
+ result = witTypes.Err[DescriptorType, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.set-size
+func wasm_import_method_descriptor_set_size(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *Descriptor) SetSize(size uint64) witTypes.Result[witTypes.Unit, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_descriptor_set_size((self).Handle(), int64(size), returnArea)
+ var result witTypes.Result[witTypes.Unit, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.set-times
+func wasm_import_method_descriptor_set_times(arg0 int32, arg1 int32, arg2 int64, arg3 int32, arg4 int32, arg5 int64, arg6 int32, arg7 uintptr)
+
+func (self *Descriptor) SetTimes(dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) witTypes.Result[witTypes.Unit, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ var variant int32
+ var variant0 int64
+ var variant1 int32
+ switch dataAccessTimestamp.Tag() {
+ case NewTimestampNoChange:
+
+ variant = int32(0)
+ variant0 = 0
+ variant1 = 0
+
+ case NewTimestampNow:
+
+ variant = int32(1)
+ variant0 = 0
+ variant1 = 0
+
+ case NewTimestampTimestamp:
+ payload := dataAccessTimestamp.Timestamp()
+
+ variant = int32(2)
+ variant0 = int64((payload).Seconds)
+ variant1 = int32((payload).Nanoseconds)
+
+ default:
+ panic("unreachable")
+ }
+ var variant2 int32
+ var variant3 int64
+ var variant4 int32
+ switch dataModificationTimestamp.Tag() {
+ case NewTimestampNoChange:
+
+ variant2 = int32(0)
+ variant3 = 0
+ variant4 = 0
+
+ case NewTimestampNow:
+
+ variant2 = int32(1)
+ variant3 = 0
+ variant4 = 0
+
+ case NewTimestampTimestamp:
+ payload := dataModificationTimestamp.Timestamp()
+
+ variant2 = int32(2)
+ variant3 = int64((payload).Seconds)
+ variant4 = int32((payload).Nanoseconds)
+
+ default:
+ panic("unreachable")
+ }
+ wasm_import_method_descriptor_set_times((self).Handle(), variant, variant0, variant1, variant2, variant3, variant4, returnArea)
+ var result witTypes.Result[witTypes.Unit, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result5 := result
+ return result5
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.read
+func wasm_import_method_descriptor_read(arg0 int32, arg1 int64, arg2 int64, arg3 uintptr)
+
+func (self *Descriptor) Read(length uint64, offset uint64) witTypes.Result[witTypes.Tuple2[[]uint8, bool], ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4))
+ wasm_import_method_descriptor_read((self).Handle(), int64(length), int64(offset), returnArea)
+ var result witTypes.Result[witTypes.Tuple2[[]uint8, bool], ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+
+ result = witTypes.Ok[witTypes.Tuple2[[]uint8, bool], ErrorCode](witTypes.Tuple2[[]uint8, bool]{value, (uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) != 0)})
+ case 1:
+
+ result = witTypes.Err[witTypes.Tuple2[[]uint8, bool], ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.write
+func wasm_import_method_descriptor_write(arg0 int32, arg1 uintptr, arg2 uint32, arg3 int64, arg4 uintptr)
+
+func (self *Descriptor) Write(buffer []uint8, offset uint64) witTypes.Result[uint64, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ data := unsafe.Pointer(unsafe.SliceData(buffer))
+ pinner.Pin(data)
+ wasm_import_method_descriptor_write((self).Handle(), uintptr(data), uint32(len(buffer)), int64(offset), returnArea)
+ var result witTypes.Result[uint64, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint64, ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ case 1:
+
+ result = witTypes.Err[uint64, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.read-directory
+func wasm_import_method_descriptor_read_directory(arg0 int32, arg1 uintptr)
+
+func (self *Descriptor) ReadDirectory() witTypes.Result[*DirectoryEntryStream, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_method_descriptor_read_directory((self).Handle(), returnArea)
+ var result witTypes.Result[*DirectoryEntryStream, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*DirectoryEntryStream, ErrorCode](DirectoryEntryStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+
+ result = witTypes.Err[*DirectoryEntryStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.sync
+func wasm_import_method_descriptor_sync(arg0 int32, arg1 uintptr)
+
+func (self *Descriptor) Sync() witTypes.Result[witTypes.Unit, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_descriptor_sync((self).Handle(), returnArea)
+ var result witTypes.Result[witTypes.Unit, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.create-directory-at
+func wasm_import_method_descriptor_create_directory_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr)
+
+func (self *Descriptor) CreateDirectoryAt(path string) witTypes.Result[witTypes.Unit, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ utf8 := unsafe.Pointer(unsafe.StringData(path))
+ pinner.Pin(utf8)
+ wasm_import_method_descriptor_create_directory_at((self).Handle(), uintptr(utf8), uint32(len(path)), returnArea)
+ var result witTypes.Result[witTypes.Unit, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.stat
+func wasm_import_method_descriptor_stat(arg0 int32, arg1 uintptr)
+
+func (self *Descriptor) Stat() witTypes.Result[DescriptorStat, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 104, 8))
+ wasm_import_method_descriptor_stat((self).Handle(), returnArea)
+ var result witTypes.Result[DescriptorStat, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ var option witTypes.Option[wasi_clocks_0_2_8_wall_clock.Datetime]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option = witTypes.None[wasi_clocks_0_2_8_wall_clock.Datetime]()
+ case 1:
+
+ option = witTypes.Some[wasi_clocks_0_2_8_wall_clock.Datetime](wasi_clocks_0_2_8_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 48)))})
+ default:
+ panic("unreachable")
+ }
+ var option0 witTypes.Option[wasi_clocks_0_2_8_wall_clock.Datetime]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 56))) {
+ case 0:
+
+ option0 = witTypes.None[wasi_clocks_0_2_8_wall_clock.Datetime]()
+ case 1:
+
+ option0 = witTypes.Some[wasi_clocks_0_2_8_wall_clock.Datetime](wasi_clocks_0_2_8_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 64))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 72)))})
+ default:
+ panic("unreachable")
+ }
+ var option1 witTypes.Option[wasi_clocks_0_2_8_wall_clock.Datetime]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 80))) {
+ case 0:
+
+ option1 = witTypes.None[wasi_clocks_0_2_8_wall_clock.Datetime]()
+ case 1:
+
+ option1 = witTypes.Some[wasi_clocks_0_2_8_wall_clock.Datetime](wasi_clocks_0_2_8_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 88))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 96)))})
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Ok[DescriptorStat, ErrorCode](DescriptorStat{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))), option, option0, option1})
+ case 1:
+
+ result = witTypes.Err[DescriptorStat, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))
+ default:
+ panic("unreachable")
+ }
+ result2 := result
+ return result2
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.stat-at
+func wasm_import_method_descriptor_stat_at(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 uintptr)
+
+func (self *Descriptor) StatAt(pathFlags PathFlags, path string) witTypes.Result[DescriptorStat, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 104, 8))
+ utf8 := unsafe.Pointer(unsafe.StringData(path))
+ pinner.Pin(utf8)
+ wasm_import_method_descriptor_stat_at((self).Handle(), int32(pathFlags), uintptr(utf8), uint32(len(path)), returnArea)
+ var result witTypes.Result[DescriptorStat, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ var option witTypes.Option[wasi_clocks_0_2_8_wall_clock.Datetime]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option = witTypes.None[wasi_clocks_0_2_8_wall_clock.Datetime]()
+ case 1:
+
+ option = witTypes.Some[wasi_clocks_0_2_8_wall_clock.Datetime](wasi_clocks_0_2_8_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 48)))})
+ default:
+ panic("unreachable")
+ }
+ var option0 witTypes.Option[wasi_clocks_0_2_8_wall_clock.Datetime]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 56))) {
+ case 0:
+
+ option0 = witTypes.None[wasi_clocks_0_2_8_wall_clock.Datetime]()
+ case 1:
+
+ option0 = witTypes.Some[wasi_clocks_0_2_8_wall_clock.Datetime](wasi_clocks_0_2_8_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 64))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 72)))})
+ default:
+ panic("unreachable")
+ }
+ var option1 witTypes.Option[wasi_clocks_0_2_8_wall_clock.Datetime]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 80))) {
+ case 0:
+
+ option1 = witTypes.None[wasi_clocks_0_2_8_wall_clock.Datetime]()
+ case 1:
+
+ option1 = witTypes.Some[wasi_clocks_0_2_8_wall_clock.Datetime](wasi_clocks_0_2_8_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 88))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 96)))})
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Ok[DescriptorStat, ErrorCode](DescriptorStat{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))), option, option0, option1})
+ case 1:
+
+ result = witTypes.Err[DescriptorStat, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))
+ default:
+ panic("unreachable")
+ }
+ result2 := result
+ return result2
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.set-times-at
+func wasm_import_method_descriptor_set_times_at(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 int32, arg5 int64, arg6 int32, arg7 int32, arg8 int64, arg9 int32, arg10 uintptr)
+
+func (self *Descriptor) SetTimesAt(pathFlags PathFlags, path string, dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) witTypes.Result[witTypes.Unit, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ utf8 := unsafe.Pointer(unsafe.StringData(path))
+ pinner.Pin(utf8)
+ var variant int32
+ var variant0 int64
+ var variant1 int32
+ switch dataAccessTimestamp.Tag() {
+ case NewTimestampNoChange:
+
+ variant = int32(0)
+ variant0 = 0
+ variant1 = 0
+
+ case NewTimestampNow:
+
+ variant = int32(1)
+ variant0 = 0
+ variant1 = 0
+
+ case NewTimestampTimestamp:
+ payload := dataAccessTimestamp.Timestamp()
+
+ variant = int32(2)
+ variant0 = int64((payload).Seconds)
+ variant1 = int32((payload).Nanoseconds)
+
+ default:
+ panic("unreachable")
+ }
+ var variant2 int32
+ var variant3 int64
+ var variant4 int32
+ switch dataModificationTimestamp.Tag() {
+ case NewTimestampNoChange:
+
+ variant2 = int32(0)
+ variant3 = 0
+ variant4 = 0
+
+ case NewTimestampNow:
+
+ variant2 = int32(1)
+ variant3 = 0
+ variant4 = 0
+
+ case NewTimestampTimestamp:
+ payload := dataModificationTimestamp.Timestamp()
+
+ variant2 = int32(2)
+ variant3 = int64((payload).Seconds)
+ variant4 = int32((payload).Nanoseconds)
+
+ default:
+ panic("unreachable")
+ }
+ wasm_import_method_descriptor_set_times_at((self).Handle(), int32(pathFlags), uintptr(utf8), uint32(len(path)), variant, variant0, variant1, variant2, variant3, variant4, returnArea)
+ var result witTypes.Result[witTypes.Unit, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result5 := result
+ return result5
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.link-at
+func wasm_import_method_descriptor_link_at(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 int32, arg5 uintptr, arg6 uint32, arg7 uintptr)
+
+func (self *Descriptor) LinkAt(oldPathFlags PathFlags, oldPath string, newDescriptor *Descriptor, newPath string) witTypes.Result[witTypes.Unit, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ utf8 := unsafe.Pointer(unsafe.StringData(oldPath))
+ pinner.Pin(utf8)
+ utf80 := unsafe.Pointer(unsafe.StringData(newPath))
+ pinner.Pin(utf80)
+ wasm_import_method_descriptor_link_at((self).Handle(), int32(oldPathFlags), uintptr(utf8), uint32(len(oldPath)), (newDescriptor).Handle(), uintptr(utf80), uint32(len(newPath)), returnArea)
+ var result witTypes.Result[witTypes.Unit, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result1 := result
+ return result1
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.open-at
+func wasm_import_method_descriptor_open_at(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 int32, arg5 int32, arg6 uintptr)
+
+func (self *Descriptor) OpenAt(pathFlags PathFlags, path string, openFlags OpenFlags, flags DescriptorFlags) witTypes.Result[*Descriptor, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ utf8 := unsafe.Pointer(unsafe.StringData(path))
+ pinner.Pin(utf8)
+ wasm_import_method_descriptor_open_at((self).Handle(), int32(pathFlags), uintptr(utf8), uint32(len(path)), int32(openFlags), int32(flags), returnArea)
+ var result witTypes.Result[*Descriptor, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*Descriptor, ErrorCode](DescriptorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+
+ result = witTypes.Err[*Descriptor, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.readlink-at
+func wasm_import_method_descriptor_readlink_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr)
+
+func (self *Descriptor) ReadlinkAt(path string) witTypes.Result[string, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4))
+ utf8 := unsafe.Pointer(unsafe.StringData(path))
+ pinner.Pin(utf8)
+ wasm_import_method_descriptor_readlink_at((self).Handle(), uintptr(utf8), uint32(len(path)), returnArea)
+ var result witTypes.Result[string, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+
+ result = witTypes.Ok[string, ErrorCode](value)
+ case 1:
+
+ result = witTypes.Err[string, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.remove-directory-at
+func wasm_import_method_descriptor_remove_directory_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr)
+
+func (self *Descriptor) RemoveDirectoryAt(path string) witTypes.Result[witTypes.Unit, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ utf8 := unsafe.Pointer(unsafe.StringData(path))
+ pinner.Pin(utf8)
+ wasm_import_method_descriptor_remove_directory_at((self).Handle(), uintptr(utf8), uint32(len(path)), returnArea)
+ var result witTypes.Result[witTypes.Unit, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.rename-at
+func wasm_import_method_descriptor_rename_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 int32, arg4 uintptr, arg5 uint32, arg6 uintptr)
+
+func (self *Descriptor) RenameAt(oldPath string, newDescriptor *Descriptor, newPath string) witTypes.Result[witTypes.Unit, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ utf8 := unsafe.Pointer(unsafe.StringData(oldPath))
+ pinner.Pin(utf8)
+ utf80 := unsafe.Pointer(unsafe.StringData(newPath))
+ pinner.Pin(utf80)
+ wasm_import_method_descriptor_rename_at((self).Handle(), uintptr(utf8), uint32(len(oldPath)), (newDescriptor).Handle(), uintptr(utf80), uint32(len(newPath)), returnArea)
+ var result witTypes.Result[witTypes.Unit, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result1 := result
+ return result1
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.symlink-at
+func wasm_import_method_descriptor_symlink_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr)
+
+func (self *Descriptor) SymlinkAt(oldPath string, newPath string) witTypes.Result[witTypes.Unit, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ utf8 := unsafe.Pointer(unsafe.StringData(oldPath))
+ pinner.Pin(utf8)
+ utf80 := unsafe.Pointer(unsafe.StringData(newPath))
+ pinner.Pin(utf80)
+ wasm_import_method_descriptor_symlink_at((self).Handle(), uintptr(utf8), uint32(len(oldPath)), uintptr(utf80), uint32(len(newPath)), returnArea)
+ var result witTypes.Result[witTypes.Unit, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result1 := result
+ return result1
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.unlink-file-at
+func wasm_import_method_descriptor_unlink_file_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr)
+
+func (self *Descriptor) UnlinkFileAt(path string) witTypes.Result[witTypes.Unit, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ utf8 := unsafe.Pointer(unsafe.StringData(path))
+ pinner.Pin(utf8)
+ wasm_import_method_descriptor_unlink_file_at((self).Handle(), uintptr(utf8), uint32(len(path)), returnArea)
+ var result witTypes.Result[witTypes.Unit, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.is-same-object
+func wasm_import_method_descriptor_is_same_object(arg0 int32, arg1 int32) int32
+
+func (self *Descriptor) IsSameObject(other *Descriptor) bool {
+
+ result := wasm_import_method_descriptor_is_same_object((self).Handle(), (other).Handle())
+ return (result != 0)
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.metadata-hash
+func wasm_import_method_descriptor_metadata_hash(arg0 int32, arg1 uintptr)
+
+func (self *Descriptor) MetadataHash() witTypes.Result[MetadataHashValue, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 24, 8))
+ wasm_import_method_descriptor_metadata_hash((self).Handle(), returnArea)
+ var result witTypes.Result[MetadataHashValue, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[MetadataHashValue, ErrorCode](MetadataHashValue{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16)))})
+ case 1:
+
+ result = witTypes.Err[MetadataHashValue, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]descriptor.metadata-hash-at
+func wasm_import_method_descriptor_metadata_hash_at(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 uintptr)
+
+func (self *Descriptor) MetadataHashAt(pathFlags PathFlags, path string) witTypes.Result[MetadataHashValue, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 24, 8))
+ utf8 := unsafe.Pointer(unsafe.StringData(path))
+ pinner.Pin(utf8)
+ wasm_import_method_descriptor_metadata_hash_at((self).Handle(), int32(pathFlags), uintptr(utf8), uint32(len(path)), returnArea)
+ var result witTypes.Result[MetadataHashValue, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[MetadataHashValue, ErrorCode](MetadataHashValue{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16)))})
+ case 1:
+
+ result = witTypes.Err[MetadataHashValue, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 [method]directory-entry-stream.read-directory-entry
+func wasm_import_method_directory_entry_stream_read_directory_entry(arg0 int32, arg1 uintptr)
+
+func (self *DirectoryEntryStream) ReadDirectoryEntry() witTypes.Result[witTypes.Option[DirectoryEntry], ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4))
+ wasm_import_method_directory_entry_stream_read_directory_entry((self).Handle(), returnArea)
+ var result witTypes.Result[witTypes.Option[DirectoryEntry], ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ var option witTypes.Option[DirectoryEntry]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ option = witTypes.None[DirectoryEntry]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4))))
+
+ option = witTypes.Some[DirectoryEntry](DirectoryEntry{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))), value})
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Ok[witTypes.Option[DirectoryEntry], ErrorCode](option)
+ case 1:
+
+ result = witTypes.Err[witTypes.Option[DirectoryEntry], ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:filesystem/types@0.2.8 filesystem-error-code
+func wasm_import_filesystem_error_code(arg0 int32, arg1 uintptr)
+
+func FilesystemErrorCode(err *wasi_io_0_2_8_error.Error) witTypes.Option[ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_filesystem_error_code((err).Handle(), returnArea)
+ var option witTypes.Option[ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[ErrorCode]()
+ case 1:
+
+ option = witTypes.Some[ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
diff --git a/imports/wasi_http_0_2_8_incoming_handler/empty.s b/imports/wasi_http_0_2_8_incoming_handler/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_http_0_2_8_incoming_handler/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_http_0_2_8_incoming_handler/wit_bindings.go b/imports/wasi_http_0_2_8_incoming_handler/wit_bindings.go
new file mode 100644
index 0000000..4ad2b78
--- /dev/null
+++ b/imports/wasi_http_0_2_8_incoming_handler/wit_bindings.go
@@ -0,0 +1,29 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_http_0_2_8_incoming_handler
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_http_0_2_8_types"
+)
+
+type IncomingRequest = wasi_http_0_2_8_types.IncomingRequest
+type ResponseOutparam = wasi_http_0_2_8_types.ResponseOutparam
diff --git a/imports/wasi_http_0_2_8_outgoing_handler/empty.s b/imports/wasi_http_0_2_8_outgoing_handler/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_http_0_2_8_outgoing_handler/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_http_0_2_8_outgoing_handler/wit_bindings.go b/imports/wasi_http_0_2_8_outgoing_handler/wit_bindings.go
new file mode 100644
index 0000000..078d45a
--- /dev/null
+++ b/imports/wasi_http_0_2_8_outgoing_handler/wit_bindings.go
@@ -0,0 +1,487 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_http_0_2_8_outgoing_handler
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_http_0_2_8_types"
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+type OutgoingRequest = wasi_http_0_2_8_types.OutgoingRequest
+type RequestOptions = wasi_http_0_2_8_types.RequestOptions
+type FutureIncomingResponse = wasi_http_0_2_8_types.FutureIncomingResponse
+type ErrorCode = wasi_http_0_2_8_types.ErrorCode
+
+//go:wasmimport wasi:http/outgoing-handler@0.2.8 handle
+func wasm_import_handle(arg0 int32, arg1 int32, arg2 int32, arg3 uintptr)
+
+func Handle(request *wasi_http_0_2_8_types.OutgoingRequest, options witTypes.Option[*wasi_http_0_2_8_types.RequestOptions]) witTypes.Result[*wasi_http_0_2_8_types.FutureIncomingResponse, wasi_http_0_2_8_types.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (24 + 4*4), 8))
+ var option int32
+ var option0 int32
+ switch options.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option0 = 0
+ case witTypes.OptionSome:
+ payload := options.Some()
+
+ option = int32(1)
+ option0 = (payload).TakeHandle()
+ default:
+ panic("unreachable")
+ }
+ wasm_import_handle((request).TakeHandle(), option, option0, returnArea)
+ var result witTypes.Result[*wasi_http_0_2_8_types.FutureIncomingResponse, wasi_http_0_2_8_types.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*wasi_http_0_2_8_types.FutureIncomingResponse, wasi_http_0_2_8_types.ErrorCode](wasi_http_0_2_8_types.FutureIncomingResponseFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))))
+ case 1:
+ var variant wasi_http_0_2_8_types.ErrorCode
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) {
+ case 0:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeDnsTimeout()
+
+ case 1:
+ var option1 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option1 = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option1 = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+ var option2 witTypes.Option[uint16]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option2 = witTypes.None[uint16]()
+ case 1:
+
+ option2 = witTypes.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (18 + 3*4))))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeDnsError(wasi_http_0_2_8_types.DnsErrorPayload{option1, option2})
+
+ case 2:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeDestinationNotFound()
+
+ case 3:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeDestinationUnavailable()
+
+ case 4:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeDestinationIpProhibited()
+
+ case 5:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeDestinationIpUnroutable()
+
+ case 6:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeConnectionRefused()
+
+ case 7:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeConnectionTerminated()
+
+ case 8:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeConnectionTimeout()
+
+ case 9:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeConnectionReadTimeout()
+
+ case 10:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeConnectionWriteTimeout()
+
+ case 11:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeConnectionLimitReached()
+
+ case 12:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeTlsProtocolError()
+
+ case 13:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeTlsCertificateError()
+
+ case 14:
+ var option3 witTypes.Option[uint8]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option3 = witTypes.None[uint8]()
+ case 1:
+
+ option3 = witTypes.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 17)))))
+ default:
+ panic("unreachable")
+ }
+ var option5 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) {
+ case 0:
+
+ option5 = witTypes.None[string]()
+ case 1:
+ value4 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4))))
+
+ option5 = witTypes.Some[string](value4)
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeTlsAlertReceived(wasi_http_0_2_8_types.TlsAlertReceivedPayload{option3, option5})
+
+ case 15:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpRequestDenied()
+
+ case 16:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpRequestLengthRequired()
+
+ case 17:
+ var option6 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option6 = witTypes.None[uint64]()
+ case 1:
+
+ option6 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpRequestBodySize(option6)
+
+ case 18:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpRequestMethodInvalid()
+
+ case 19:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpRequestUriInvalid()
+
+ case 20:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpRequestUriTooLong()
+
+ case 21:
+ var option7 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option7 = witTypes.None[uint32]()
+ case 1:
+
+ option7 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpRequestHeaderSectionSize(option7)
+
+ case 22:
+ var option11 witTypes.Option[wasi_http_0_2_8_types.FieldSizePayload]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option11 = witTypes.None[wasi_http_0_2_8_types.FieldSizePayload]()
+ case 1:
+ var option9 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) {
+ case 0:
+
+ option9 = witTypes.None[string]()
+ case 1:
+ value8 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4))))
+
+ option9 = witTypes.Some[string](value8)
+ default:
+ panic("unreachable")
+ }
+ var option10 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 4*4)))) {
+ case 0:
+
+ option10 = witTypes.None[uint32]()
+ case 1:
+
+ option10 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 4*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ option11 = witTypes.Some[wasi_http_0_2_8_types.FieldSizePayload](wasi_http_0_2_8_types.FieldSizePayload{option9, option10})
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpRequestHeaderSize(option11)
+
+ case 23:
+ var option12 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option12 = witTypes.None[uint32]()
+ case 1:
+
+ option12 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpRequestTrailerSectionSize(option12)
+
+ case 24:
+ var option14 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option14 = witTypes.None[string]()
+ case 1:
+ value13 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option14 = witTypes.Some[string](value13)
+ default:
+ panic("unreachable")
+ }
+ var option15 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option15 = witTypes.None[uint32]()
+ case 1:
+
+ option15 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpRequestTrailerSize(wasi_http_0_2_8_types.FieldSizePayload{option14, option15})
+
+ case 25:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpResponseIncomplete()
+
+ case 26:
+ var option16 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option16 = witTypes.None[uint32]()
+ case 1:
+
+ option16 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpResponseHeaderSectionSize(option16)
+
+ case 27:
+ var option18 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option18 = witTypes.None[string]()
+ case 1:
+ value17 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option18 = witTypes.Some[string](value17)
+ default:
+ panic("unreachable")
+ }
+ var option19 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option19 = witTypes.None[uint32]()
+ case 1:
+
+ option19 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpResponseHeaderSize(wasi_http_0_2_8_types.FieldSizePayload{option18, option19})
+
+ case 28:
+ var option20 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option20 = witTypes.None[uint64]()
+ case 1:
+
+ option20 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpResponseBodySize(option20)
+
+ case 29:
+ var option21 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option21 = witTypes.None[uint32]()
+ case 1:
+
+ option21 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpResponseTrailerSectionSize(option21)
+
+ case 30:
+ var option23 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option23 = witTypes.None[string]()
+ case 1:
+ value22 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option23 = witTypes.Some[string](value22)
+ default:
+ panic("unreachable")
+ }
+ var option24 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option24 = witTypes.None[uint32]()
+ case 1:
+
+ option24 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpResponseTrailerSize(wasi_http_0_2_8_types.FieldSizePayload{option23, option24})
+
+ case 31:
+ var option26 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option26 = witTypes.None[string]()
+ case 1:
+ value25 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option26 = witTypes.Some[string](value25)
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpResponseTransferCoding(option26)
+
+ case 32:
+ var option28 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option28 = witTypes.None[string]()
+ case 1:
+ value27 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option28 = witTypes.Some[string](value27)
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpResponseContentCoding(option28)
+
+ case 33:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpResponseTimeout()
+
+ case 34:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpUpgradeFailed()
+
+ case 35:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeHttpProtocolError()
+
+ case 36:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeLoopDetected()
+
+ case 37:
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeConfigurationError()
+
+ case 38:
+ var option30 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option30 = witTypes.None[string]()
+ case 1:
+ value29 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option30 = witTypes.Some[string](value29)
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_2_8_types.MakeErrorCodeInternalError(option30)
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[*wasi_http_0_2_8_types.FutureIncomingResponse, wasi_http_0_2_8_types.ErrorCode](variant)
+ default:
+ panic("unreachable")
+ }
+ result31 := result
+ return result31
+
+}
diff --git a/imports/wasi_http_0_2_8_types/empty.s b/imports/wasi_http_0_2_8_types/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_http_0_2_8_types/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_http_0_2_8_types/wit_bindings.go b/imports/wasi_http_0_2_8_types/wit_bindings.go
new file mode 100644
index 0000000..aacb419
--- /dev/null
+++ b/imports/wasi_http_0_2_8_types/wit_bindings.go
@@ -0,0 +1,5000 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_http_0_2_8_types
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_error"
+ "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_poll"
+ "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_streams"
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+type Duration = uint64
+type InputStream = wasi_io_0_2_8_streams.InputStream
+type OutputStream = wasi_io_0_2_8_streams.OutputStream
+type IoError = wasi_io_0_2_8_error.Error
+type Pollable = wasi_io_0_2_8_poll.Pollable
+
+const (
+ MethodGet uint8 = 0
+ MethodHead uint8 = 1
+ MethodPost uint8 = 2
+ MethodPut uint8 = 3
+ MethodDelete uint8 = 4
+ MethodConnect uint8 = 5
+ MethodOptions uint8 = 6
+ MethodTrace uint8 = 7
+ MethodPatch uint8 = 8
+ MethodOther uint8 = 9
+)
+
+// This type corresponds to HTTP standard Methods.
+type Method struct {
+ tag uint8
+ value any
+}
+
+func (self Method) Tag() uint8 {
+ return self.tag
+}
+
+func (self Method) Other() string {
+ if self.tag != MethodOther {
+ panic("tag mismatch")
+ }
+ return self.value.(string)
+}
+
+func MakeMethodGet() Method {
+ return Method{MethodGet, nil}
+}
+func MakeMethodHead() Method {
+ return Method{MethodHead, nil}
+}
+func MakeMethodPost() Method {
+ return Method{MethodPost, nil}
+}
+func MakeMethodPut() Method {
+ return Method{MethodPut, nil}
+}
+func MakeMethodDelete() Method {
+ return Method{MethodDelete, nil}
+}
+func MakeMethodConnect() Method {
+ return Method{MethodConnect, nil}
+}
+func MakeMethodOptions() Method {
+ return Method{MethodOptions, nil}
+}
+func MakeMethodTrace() Method {
+ return Method{MethodTrace, nil}
+}
+func MakeMethodPatch() Method {
+ return Method{MethodPatch, nil}
+}
+func MakeMethodOther(value string) Method {
+ return Method{MethodOther, value}
+}
+
+const (
+ SchemeHttp uint8 = 0
+ SchemeHttps uint8 = 1
+ SchemeOther uint8 = 2
+)
+
+// This type corresponds to HTTP standard Related Schemes.
+type Scheme struct {
+ tag uint8
+ value any
+}
+
+func (self Scheme) Tag() uint8 {
+ return self.tag
+}
+
+func (self Scheme) Other() string {
+ if self.tag != SchemeOther {
+ panic("tag mismatch")
+ }
+ return self.value.(string)
+}
+
+func MakeSchemeHttp() Scheme {
+ return Scheme{SchemeHttp, nil}
+}
+func MakeSchemeHttps() Scheme {
+ return Scheme{SchemeHttps, nil}
+}
+func MakeSchemeOther(value string) Scheme {
+ return Scheme{SchemeOther, value}
+}
+
+// Defines the case payload type for `DNS-error` above:
+type DnsErrorPayload struct {
+ Rcode witTypes.Option[string]
+ InfoCode witTypes.Option[uint16]
+}
+
+// Defines the case payload type for `TLS-alert-received` above:
+type TlsAlertReceivedPayload struct {
+ AlertId witTypes.Option[uint8]
+ AlertMessage witTypes.Option[string]
+}
+
+// Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
+type FieldSizePayload struct {
+ FieldName witTypes.Option[string]
+ FieldSize witTypes.Option[uint32]
+}
+
+const (
+ ErrorCodeDnsTimeout uint8 = 0
+ ErrorCodeDnsError uint8 = 1
+ ErrorCodeDestinationNotFound uint8 = 2
+ ErrorCodeDestinationUnavailable uint8 = 3
+ ErrorCodeDestinationIpProhibited uint8 = 4
+ ErrorCodeDestinationIpUnroutable uint8 = 5
+ ErrorCodeConnectionRefused uint8 = 6
+ ErrorCodeConnectionTerminated uint8 = 7
+ ErrorCodeConnectionTimeout uint8 = 8
+ ErrorCodeConnectionReadTimeout uint8 = 9
+ ErrorCodeConnectionWriteTimeout uint8 = 10
+ ErrorCodeConnectionLimitReached uint8 = 11
+ ErrorCodeTlsProtocolError uint8 = 12
+ ErrorCodeTlsCertificateError uint8 = 13
+ ErrorCodeTlsAlertReceived uint8 = 14
+ ErrorCodeHttpRequestDenied uint8 = 15
+ ErrorCodeHttpRequestLengthRequired uint8 = 16
+ ErrorCodeHttpRequestBodySize uint8 = 17
+ ErrorCodeHttpRequestMethodInvalid uint8 = 18
+ ErrorCodeHttpRequestUriInvalid uint8 = 19
+ ErrorCodeHttpRequestUriTooLong uint8 = 20
+ ErrorCodeHttpRequestHeaderSectionSize uint8 = 21
+ ErrorCodeHttpRequestHeaderSize uint8 = 22
+ ErrorCodeHttpRequestTrailerSectionSize uint8 = 23
+ ErrorCodeHttpRequestTrailerSize uint8 = 24
+ ErrorCodeHttpResponseIncomplete uint8 = 25
+ ErrorCodeHttpResponseHeaderSectionSize uint8 = 26
+ ErrorCodeHttpResponseHeaderSize uint8 = 27
+ ErrorCodeHttpResponseBodySize uint8 = 28
+ ErrorCodeHttpResponseTrailerSectionSize uint8 = 29
+ ErrorCodeHttpResponseTrailerSize uint8 = 30
+ ErrorCodeHttpResponseTransferCoding uint8 = 31
+ ErrorCodeHttpResponseContentCoding uint8 = 32
+ ErrorCodeHttpResponseTimeout uint8 = 33
+ ErrorCodeHttpUpgradeFailed uint8 = 34
+ ErrorCodeHttpProtocolError uint8 = 35
+ ErrorCodeLoopDetected uint8 = 36
+ ErrorCodeConfigurationError uint8 = 37
+ // This is a catch-all error for anything that doesn't fit cleanly into a
+ // more specific case. It also includes an optional string for an
+ // unstructured description of the error. Users should not depend on the
+ // string for diagnosing errors, as it's not required to be consistent
+ // between implementations.
+ ErrorCodeInternalError uint8 = 38
+)
+
+// These cases are inspired by the IANA HTTP Proxy Error Types:
+//
+//
+type ErrorCode struct {
+ tag uint8
+ value any
+}
+
+func (self ErrorCode) Tag() uint8 {
+ return self.tag
+}
+
+func (self ErrorCode) DnsError() DnsErrorPayload {
+ if self.tag != ErrorCodeDnsError {
+ panic("tag mismatch")
+ }
+ return self.value.(DnsErrorPayload)
+}
+func (self ErrorCode) TlsAlertReceived() TlsAlertReceivedPayload {
+ if self.tag != ErrorCodeTlsAlertReceived {
+ panic("tag mismatch")
+ }
+ return self.value.(TlsAlertReceivedPayload)
+}
+func (self ErrorCode) HttpRequestBodySize() witTypes.Option[uint64] {
+ if self.tag != ErrorCodeHttpRequestBodySize {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[uint64])
+}
+func (self ErrorCode) HttpRequestHeaderSectionSize() witTypes.Option[uint32] {
+ if self.tag != ErrorCodeHttpRequestHeaderSectionSize {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[uint32])
+}
+func (self ErrorCode) HttpRequestHeaderSize() witTypes.Option[FieldSizePayload] {
+ if self.tag != ErrorCodeHttpRequestHeaderSize {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[FieldSizePayload])
+}
+func (self ErrorCode) HttpRequestTrailerSectionSize() witTypes.Option[uint32] {
+ if self.tag != ErrorCodeHttpRequestTrailerSectionSize {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[uint32])
+}
+func (self ErrorCode) HttpRequestTrailerSize() FieldSizePayload {
+ if self.tag != ErrorCodeHttpRequestTrailerSize {
+ panic("tag mismatch")
+ }
+ return self.value.(FieldSizePayload)
+}
+func (self ErrorCode) HttpResponseHeaderSectionSize() witTypes.Option[uint32] {
+ if self.tag != ErrorCodeHttpResponseHeaderSectionSize {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[uint32])
+}
+func (self ErrorCode) HttpResponseHeaderSize() FieldSizePayload {
+ if self.tag != ErrorCodeHttpResponseHeaderSize {
+ panic("tag mismatch")
+ }
+ return self.value.(FieldSizePayload)
+}
+func (self ErrorCode) HttpResponseBodySize() witTypes.Option[uint64] {
+ if self.tag != ErrorCodeHttpResponseBodySize {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[uint64])
+}
+func (self ErrorCode) HttpResponseTrailerSectionSize() witTypes.Option[uint32] {
+ if self.tag != ErrorCodeHttpResponseTrailerSectionSize {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[uint32])
+}
+func (self ErrorCode) HttpResponseTrailerSize() FieldSizePayload {
+ if self.tag != ErrorCodeHttpResponseTrailerSize {
+ panic("tag mismatch")
+ }
+ return self.value.(FieldSizePayload)
+}
+func (self ErrorCode) HttpResponseTransferCoding() witTypes.Option[string] {
+ if self.tag != ErrorCodeHttpResponseTransferCoding {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[string])
+}
+func (self ErrorCode) HttpResponseContentCoding() witTypes.Option[string] {
+ if self.tag != ErrorCodeHttpResponseContentCoding {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[string])
+}
+func (self ErrorCode) InternalError() witTypes.Option[string] {
+ if self.tag != ErrorCodeInternalError {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[string])
+}
+
+func MakeErrorCodeDnsTimeout() ErrorCode {
+ return ErrorCode{ErrorCodeDnsTimeout, nil}
+}
+func MakeErrorCodeDnsError(value DnsErrorPayload) ErrorCode {
+ return ErrorCode{ErrorCodeDnsError, value}
+}
+func MakeErrorCodeDestinationNotFound() ErrorCode {
+ return ErrorCode{ErrorCodeDestinationNotFound, nil}
+}
+func MakeErrorCodeDestinationUnavailable() ErrorCode {
+ return ErrorCode{ErrorCodeDestinationUnavailable, nil}
+}
+func MakeErrorCodeDestinationIpProhibited() ErrorCode {
+ return ErrorCode{ErrorCodeDestinationIpProhibited, nil}
+}
+func MakeErrorCodeDestinationIpUnroutable() ErrorCode {
+ return ErrorCode{ErrorCodeDestinationIpUnroutable, nil}
+}
+func MakeErrorCodeConnectionRefused() ErrorCode {
+ return ErrorCode{ErrorCodeConnectionRefused, nil}
+}
+func MakeErrorCodeConnectionTerminated() ErrorCode {
+ return ErrorCode{ErrorCodeConnectionTerminated, nil}
+}
+func MakeErrorCodeConnectionTimeout() ErrorCode {
+ return ErrorCode{ErrorCodeConnectionTimeout, nil}
+}
+func MakeErrorCodeConnectionReadTimeout() ErrorCode {
+ return ErrorCode{ErrorCodeConnectionReadTimeout, nil}
+}
+func MakeErrorCodeConnectionWriteTimeout() ErrorCode {
+ return ErrorCode{ErrorCodeConnectionWriteTimeout, nil}
+}
+func MakeErrorCodeConnectionLimitReached() ErrorCode {
+ return ErrorCode{ErrorCodeConnectionLimitReached, nil}
+}
+func MakeErrorCodeTlsProtocolError() ErrorCode {
+ return ErrorCode{ErrorCodeTlsProtocolError, nil}
+}
+func MakeErrorCodeTlsCertificateError() ErrorCode {
+ return ErrorCode{ErrorCodeTlsCertificateError, nil}
+}
+func MakeErrorCodeTlsAlertReceived(value TlsAlertReceivedPayload) ErrorCode {
+ return ErrorCode{ErrorCodeTlsAlertReceived, value}
+}
+func MakeErrorCodeHttpRequestDenied() ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestDenied, nil}
+}
+func MakeErrorCodeHttpRequestLengthRequired() ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestLengthRequired, nil}
+}
+func MakeErrorCodeHttpRequestBodySize(value witTypes.Option[uint64]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestBodySize, value}
+}
+func MakeErrorCodeHttpRequestMethodInvalid() ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestMethodInvalid, nil}
+}
+func MakeErrorCodeHttpRequestUriInvalid() ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestUriInvalid, nil}
+}
+func MakeErrorCodeHttpRequestUriTooLong() ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestUriTooLong, nil}
+}
+func MakeErrorCodeHttpRequestHeaderSectionSize(value witTypes.Option[uint32]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestHeaderSectionSize, value}
+}
+func MakeErrorCodeHttpRequestHeaderSize(value witTypes.Option[FieldSizePayload]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestHeaderSize, value}
+}
+func MakeErrorCodeHttpRequestTrailerSectionSize(value witTypes.Option[uint32]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestTrailerSectionSize, value}
+}
+func MakeErrorCodeHttpRequestTrailerSize(value FieldSizePayload) ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestTrailerSize, value}
+}
+func MakeErrorCodeHttpResponseIncomplete() ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseIncomplete, nil}
+}
+func MakeErrorCodeHttpResponseHeaderSectionSize(value witTypes.Option[uint32]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseHeaderSectionSize, value}
+}
+func MakeErrorCodeHttpResponseHeaderSize(value FieldSizePayload) ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseHeaderSize, value}
+}
+func MakeErrorCodeHttpResponseBodySize(value witTypes.Option[uint64]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseBodySize, value}
+}
+func MakeErrorCodeHttpResponseTrailerSectionSize(value witTypes.Option[uint32]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseTrailerSectionSize, value}
+}
+func MakeErrorCodeHttpResponseTrailerSize(value FieldSizePayload) ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseTrailerSize, value}
+}
+func MakeErrorCodeHttpResponseTransferCoding(value witTypes.Option[string]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseTransferCoding, value}
+}
+func MakeErrorCodeHttpResponseContentCoding(value witTypes.Option[string]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseContentCoding, value}
+}
+func MakeErrorCodeHttpResponseTimeout() ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseTimeout, nil}
+}
+func MakeErrorCodeHttpUpgradeFailed() ErrorCode {
+ return ErrorCode{ErrorCodeHttpUpgradeFailed, nil}
+}
+func MakeErrorCodeHttpProtocolError() ErrorCode {
+ return ErrorCode{ErrorCodeHttpProtocolError, nil}
+}
+func MakeErrorCodeLoopDetected() ErrorCode {
+ return ErrorCode{ErrorCodeLoopDetected, nil}
+}
+func MakeErrorCodeConfigurationError() ErrorCode {
+ return ErrorCode{ErrorCodeConfigurationError, nil}
+}
+func MakeErrorCodeInternalError(value witTypes.Option[string]) ErrorCode {
+ return ErrorCode{ErrorCodeInternalError, value}
+}
+
+const (
+ // This error indicates that a `field-name` or `field-value` was
+ // syntactically invalid when used with an operation that sets headers in a
+ // `fields`.
+ HeaderErrorInvalidSyntax uint8 = 0
+ // This error indicates that a forbidden `field-name` was used when trying
+ // to set a header in a `fields`.
+ HeaderErrorForbidden uint8 = 1
+ // This error indicates that the operation on the `fields` was not
+ // permitted because the fields are immutable.
+ HeaderErrorImmutable uint8 = 2
+)
+
+// This type enumerates the different kinds of errors that may occur when
+// setting or appending to a `fields` resource.
+type HeaderError struct {
+ tag uint8
+ value any
+}
+
+func (self HeaderError) Tag() uint8 {
+ return self.tag
+}
+
+func MakeHeaderErrorInvalidSyntax() HeaderError {
+ return HeaderError{HeaderErrorInvalidSyntax, nil}
+}
+func MakeHeaderErrorForbidden() HeaderError {
+ return HeaderError{HeaderErrorForbidden, nil}
+}
+func MakeHeaderErrorImmutable() HeaderError {
+ return HeaderError{HeaderErrorImmutable, nil}
+}
+
+// Field keys are always strings.
+//
+// Field keys should always be treated as case insensitive by the `fields`
+// resource for the purposes of equality checking.
+//
+// # Deprecation
+//
+// This type has been deprecated in favor of the `field-name` type.
+type FieldKey = string
+
+// Field names are always strings.
+//
+// Field names should always be treated as case insensitive by the `fields`
+// resource for the purposes of equality checking.
+type FieldName = string
+
+// Field values should always be ASCII strings. However, in
+// reality, HTTP implementations often have to interpret malformed values,
+// so they are provided as a list of bytes.
+type FieldValue = []uint8
+
+//go:wasmimport wasi:http/types@0.2.8 [resource-drop]fields
+func resourceDropFields(handle int32)
+
+// This following block defines the `fields` resource which corresponds to
+// HTTP standard Fields. Fields are a common representation used for both
+// Headers and Trailers.
+//
+// A `fields` may be mutable or immutable. A `fields` created using the
+// constructor, `from-list`, or `clone` will be mutable, but a `fields`
+// resource given by other means (including, but not limited to,
+// `incoming-request.headers`, `outgoing-request.headers`) might be
+// immutable. In an immutable fields, the `set`, `append`, and `delete`
+// operations will fail with `header-error.immutable`.
+type Fields struct {
+ handle *witRuntime.Handle
+}
+
+func (self *Fields) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *Fields) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *Fields) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *Fields) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropFields(handle)
+ }
+}
+
+func FieldsFromOwnHandle(handleValue int32) *Fields {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &Fields{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropFields(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func FieldsFromBorrowHandle(handleValue int32) *Fields {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &Fields{handle}
+}
+
+// Headers is an alias for Fields.
+type Headers = Fields
+
+// Trailers is an alias for Fields.
+type Trailers = Fields
+
+//go:wasmimport wasi:http/types@0.2.8 [resource-drop]incoming-request
+func resourceDropIncomingRequest(handle int32)
+
+// Represents an incoming HTTP Request.
+type IncomingRequest struct {
+ handle *witRuntime.Handle
+}
+
+func (self *IncomingRequest) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *IncomingRequest) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *IncomingRequest) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *IncomingRequest) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropIncomingRequest(handle)
+ }
+}
+
+func IncomingRequestFromOwnHandle(handleValue int32) *IncomingRequest {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &IncomingRequest{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropIncomingRequest(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func IncomingRequestFromBorrowHandle(handleValue int32) *IncomingRequest {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &IncomingRequest{handle}
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [resource-drop]outgoing-request
+func resourceDropOutgoingRequest(handle int32)
+
+// Represents an outgoing HTTP Request.
+type OutgoingRequest struct {
+ handle *witRuntime.Handle
+}
+
+func (self *OutgoingRequest) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *OutgoingRequest) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *OutgoingRequest) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *OutgoingRequest) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropOutgoingRequest(handle)
+ }
+}
+
+func OutgoingRequestFromOwnHandle(handleValue int32) *OutgoingRequest {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &OutgoingRequest{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropOutgoingRequest(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func OutgoingRequestFromBorrowHandle(handleValue int32) *OutgoingRequest {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &OutgoingRequest{handle}
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [resource-drop]request-options
+func resourceDropRequestOptions(handle int32)
+
+// Parameters for making an HTTP Request. Each of these parameters is
+// currently an optional timeout applicable to the transport layer of the
+// HTTP protocol.
+//
+// These timeouts are separate from any the user may use to bound a
+// blocking call to `wasi:io/poll.poll`.
+type RequestOptions struct {
+ handle *witRuntime.Handle
+}
+
+func (self *RequestOptions) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *RequestOptions) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *RequestOptions) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *RequestOptions) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropRequestOptions(handle)
+ }
+}
+
+func RequestOptionsFromOwnHandle(handleValue int32) *RequestOptions {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &RequestOptions{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropRequestOptions(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func RequestOptionsFromBorrowHandle(handleValue int32) *RequestOptions {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &RequestOptions{handle}
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [resource-drop]response-outparam
+func resourceDropResponseOutparam(handle int32)
+
+// Represents the ability to send an HTTP Response.
+//
+// This resource is used by the `wasi:http/incoming-handler` interface to
+// allow a Response to be sent corresponding to the Request provided as the
+// other argument to `incoming-handler.handle`.
+type ResponseOutparam struct {
+ handle *witRuntime.Handle
+}
+
+func (self *ResponseOutparam) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *ResponseOutparam) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *ResponseOutparam) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *ResponseOutparam) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropResponseOutparam(handle)
+ }
+}
+
+func ResponseOutparamFromOwnHandle(handleValue int32) *ResponseOutparam {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &ResponseOutparam{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropResponseOutparam(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func ResponseOutparamFromBorrowHandle(handleValue int32) *ResponseOutparam {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &ResponseOutparam{handle}
+}
+
+// This type corresponds to the HTTP standard Status Code.
+type StatusCode = uint16
+
+//go:wasmimport wasi:http/types@0.2.8 [resource-drop]incoming-response
+func resourceDropIncomingResponse(handle int32)
+
+// Represents an incoming HTTP Response.
+type IncomingResponse struct {
+ handle *witRuntime.Handle
+}
+
+func (self *IncomingResponse) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *IncomingResponse) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *IncomingResponse) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *IncomingResponse) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropIncomingResponse(handle)
+ }
+}
+
+func IncomingResponseFromOwnHandle(handleValue int32) *IncomingResponse {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &IncomingResponse{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropIncomingResponse(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func IncomingResponseFromBorrowHandle(handleValue int32) *IncomingResponse {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &IncomingResponse{handle}
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [resource-drop]incoming-body
+func resourceDropIncomingBody(handle int32)
+
+// Represents an incoming HTTP Request or Response's Body.
+//
+// A body has both its contents - a stream of bytes - and a (possibly
+// empty) set of trailers, indicating that the full contents of the
+// body have been received. This resource represents the contents as
+// an `input-stream` and the delivery of trailers as a `future-trailers`,
+// and ensures that the user of this interface may only be consuming either
+// the body contents or waiting on trailers at any given time.
+type IncomingBody struct {
+ handle *witRuntime.Handle
+}
+
+func (self *IncomingBody) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *IncomingBody) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *IncomingBody) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *IncomingBody) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropIncomingBody(handle)
+ }
+}
+
+func IncomingBodyFromOwnHandle(handleValue int32) *IncomingBody {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &IncomingBody{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropIncomingBody(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func IncomingBodyFromBorrowHandle(handleValue int32) *IncomingBody {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &IncomingBody{handle}
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [resource-drop]future-trailers
+func resourceDropFutureTrailers(handle int32)
+
+// Represents a future which may eventually return trailers, or an error.
+//
+// In the case that the incoming HTTP Request or Response did not have any
+// trailers, this future will resolve to the empty set of trailers once the
+// complete Request or Response body has been received.
+type FutureTrailers struct {
+ handle *witRuntime.Handle
+}
+
+func (self *FutureTrailers) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *FutureTrailers) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *FutureTrailers) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *FutureTrailers) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropFutureTrailers(handle)
+ }
+}
+
+func FutureTrailersFromOwnHandle(handleValue int32) *FutureTrailers {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &FutureTrailers{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropFutureTrailers(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func FutureTrailersFromBorrowHandle(handleValue int32) *FutureTrailers {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &FutureTrailers{handle}
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [resource-drop]outgoing-response
+func resourceDropOutgoingResponse(handle int32)
+
+// Represents an outgoing HTTP Response.
+type OutgoingResponse struct {
+ handle *witRuntime.Handle
+}
+
+func (self *OutgoingResponse) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *OutgoingResponse) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *OutgoingResponse) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *OutgoingResponse) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropOutgoingResponse(handle)
+ }
+}
+
+func OutgoingResponseFromOwnHandle(handleValue int32) *OutgoingResponse {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &OutgoingResponse{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropOutgoingResponse(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func OutgoingResponseFromBorrowHandle(handleValue int32) *OutgoingResponse {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &OutgoingResponse{handle}
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [resource-drop]outgoing-body
+func resourceDropOutgoingBody(handle int32)
+
+// Represents an outgoing HTTP Request or Response's Body.
+//
+// A body has both its contents - a stream of bytes - and a (possibly
+// empty) set of trailers, inducating the full contents of the body
+// have been sent. This resource represents the contents as an
+// `output-stream` child resource, and the completion of the body (with
+// optional trailers) with a static function that consumes the
+// `outgoing-body` resource, and ensures that the user of this interface
+// may not write to the body contents after the body has been finished.
+//
+// If the user code drops this resource, as opposed to calling the static
+// method `finish`, the implementation should treat the body as incomplete,
+// and that an error has occurred. The implementation should propagate this
+// error to the HTTP protocol by whatever means it has available,
+// including: corrupting the body on the wire, aborting the associated
+// Request, or sending a late status code for the Response.
+type OutgoingBody struct {
+ handle *witRuntime.Handle
+}
+
+func (self *OutgoingBody) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *OutgoingBody) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *OutgoingBody) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *OutgoingBody) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropOutgoingBody(handle)
+ }
+}
+
+func OutgoingBodyFromOwnHandle(handleValue int32) *OutgoingBody {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &OutgoingBody{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropOutgoingBody(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func OutgoingBodyFromBorrowHandle(handleValue int32) *OutgoingBody {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &OutgoingBody{handle}
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [resource-drop]future-incoming-response
+func resourceDropFutureIncomingResponse(handle int32)
+
+// Represents a future which may eventually return an incoming HTTP
+// Response, or an error.
+//
+// This resource is returned by the `wasi:http/outgoing-handler` interface to
+// provide the HTTP Response corresponding to the sent Request.
+type FutureIncomingResponse struct {
+ handle *witRuntime.Handle
+}
+
+func (self *FutureIncomingResponse) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *FutureIncomingResponse) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *FutureIncomingResponse) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *FutureIncomingResponse) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropFutureIncomingResponse(handle)
+ }
+}
+
+func FutureIncomingResponseFromOwnHandle(handleValue int32) *FutureIncomingResponse {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &FutureIncomingResponse{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropFutureIncomingResponse(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func FutureIncomingResponseFromBorrowHandle(handleValue int32) *FutureIncomingResponse {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &FutureIncomingResponse{handle}
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [constructor]fields
+func wasm_import_constructor_fields() int32
+
+func MakeFields() *Fields {
+
+ result := wasm_import_constructor_fields()
+ return FieldsFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [static]fields.from-list
+func wasm_import_static_fields_from_list(arg0 uintptr, arg1 uint32, arg2 uintptr)
+
+func FieldsFromList(entries []witTypes.Tuple2[string, []uint8]) witTypes.Result[*Fields, HeaderError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ slice := entries
+ length := uint32(len(slice))
+ result := witRuntime.Allocate(pinner, uintptr(length*(4*4)), 4)
+ for index, element := range slice {
+ base := unsafe.Add(result, index*(4*4))
+ utf8 := unsafe.Pointer(unsafe.StringData((element).F0))
+ pinner.Pin(utf8)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len((element).F0)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf8)))
+ data := unsafe.Pointer(unsafe.SliceData((element).F1))
+ pinner.Pin(data)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4))) = uint32(uint32(len((element).F1)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = uint32(uintptr(uintptr(data)))
+
+ }
+
+ wasm_import_static_fields_from_list(uintptr(result), length, returnArea)
+ var result0 witTypes.Result[*Fields, HeaderError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result0 = witTypes.Ok[*Fields, HeaderError](FieldsFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+ var variant HeaderError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeHeaderErrorInvalidSyntax()
+
+ case 1:
+
+ variant = MakeHeaderErrorForbidden()
+
+ case 2:
+
+ variant = MakeHeaderErrorImmutable()
+
+ default:
+ panic("unreachable")
+ }
+
+ result0 = witTypes.Err[*Fields, HeaderError](variant)
+ default:
+ panic("unreachable")
+ }
+ result1 := result0
+ return result1
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]fields.get
+func wasm_import_method_fields_get(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr)
+
+func (self *Fields) Get(name string) [][]uint8 {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4))
+ utf8 := unsafe.Pointer(unsafe.StringData(name))
+ pinner.Pin(utf8)
+ wasm_import_method_fields_get((self).Handle(), uintptr(utf8), uint32(len(name)), returnArea)
+ result := make([][]uint8, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
+ for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ {
+ base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0)))), index*(2*4))
+ value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)))
+
+ result = append(result, value)
+ }
+
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]fields.has
+func wasm_import_method_fields_has(arg0 int32, arg1 uintptr, arg2 uint32) int32
+
+func (self *Fields) Has(name string) bool {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ utf8 := unsafe.Pointer(unsafe.StringData(name))
+ pinner.Pin(utf8)
+ result := wasm_import_method_fields_has((self).Handle(), uintptr(utf8), uint32(len(name)))
+ return (result != 0)
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]fields.set
+func wasm_import_method_fields_set(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr)
+
+func (self *Fields) Set(name string, value [][]uint8) witTypes.Result[witTypes.Unit, HeaderError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ utf8 := unsafe.Pointer(unsafe.StringData(name))
+ pinner.Pin(utf8)
+ slice := value
+ length := uint32(len(slice))
+ result := witRuntime.Allocate(pinner, uintptr(length*(2*4)), 4)
+ for index, element := range slice {
+ base := unsafe.Add(result, index*(2*4))
+ data := unsafe.Pointer(unsafe.SliceData(element))
+ pinner.Pin(data)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len(element)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(data)))
+
+ }
+
+ wasm_import_method_fields_set((self).Handle(), uintptr(utf8), uint32(len(name)), uintptr(result), length, returnArea)
+ var result0 witTypes.Result[witTypes.Unit, HeaderError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result0 = witTypes.Ok[witTypes.Unit, HeaderError](witTypes.Unit{})
+ case 1:
+ var variant HeaderError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))) {
+ case 0:
+
+ variant = MakeHeaderErrorInvalidSyntax()
+
+ case 1:
+
+ variant = MakeHeaderErrorForbidden()
+
+ case 2:
+
+ variant = MakeHeaderErrorImmutable()
+
+ default:
+ panic("unreachable")
+ }
+
+ result0 = witTypes.Err[witTypes.Unit, HeaderError](variant)
+ default:
+ panic("unreachable")
+ }
+ result1 := result0
+ return result1
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]fields.delete
+func wasm_import_method_fields_delete(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr)
+
+func (self *Fields) Delete(name string) witTypes.Result[witTypes.Unit, HeaderError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ utf8 := unsafe.Pointer(unsafe.StringData(name))
+ pinner.Pin(utf8)
+ wasm_import_method_fields_delete((self).Handle(), uintptr(utf8), uint32(len(name)), returnArea)
+ var result witTypes.Result[witTypes.Unit, HeaderError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, HeaderError](witTypes.Unit{})
+ case 1:
+ var variant HeaderError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))) {
+ case 0:
+
+ variant = MakeHeaderErrorInvalidSyntax()
+
+ case 1:
+
+ variant = MakeHeaderErrorForbidden()
+
+ case 2:
+
+ variant = MakeHeaderErrorImmutable()
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Unit, HeaderError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]fields.append
+func wasm_import_method_fields_append(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr)
+
+func (self *Fields) Append(name string, value []uint8) witTypes.Result[witTypes.Unit, HeaderError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ utf8 := unsafe.Pointer(unsafe.StringData(name))
+ pinner.Pin(utf8)
+ data := unsafe.Pointer(unsafe.SliceData(value))
+ pinner.Pin(data)
+ wasm_import_method_fields_append((self).Handle(), uintptr(utf8), uint32(len(name)), uintptr(data), uint32(len(value)), returnArea)
+ var result witTypes.Result[witTypes.Unit, HeaderError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, HeaderError](witTypes.Unit{})
+ case 1:
+ var variant HeaderError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))) {
+ case 0:
+
+ variant = MakeHeaderErrorInvalidSyntax()
+
+ case 1:
+
+ variant = MakeHeaderErrorForbidden()
+
+ case 2:
+
+ variant = MakeHeaderErrorImmutable()
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Unit, HeaderError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]fields.entries
+func wasm_import_method_fields_entries(arg0 int32, arg1 uintptr)
+
+func (self *Fields) Entries() []witTypes.Tuple2[string, []uint8] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4))
+ wasm_import_method_fields_entries((self).Handle(), returnArea)
+ result := make([]witTypes.Tuple2[string, []uint8], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
+ for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ {
+ base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0)))), index*(4*4))
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)))
+ value0 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4))))
+
+ result = append(result, witTypes.Tuple2[string, []uint8]{value, value0})
+ }
+
+ result1 := result
+ return result1
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]fields.clone
+func wasm_import_method_fields_clone(arg0 int32) int32
+
+func (self *Fields) Clone() *Fields {
+
+ result := wasm_import_method_fields_clone((self).Handle())
+ return FieldsFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]incoming-request.method
+func wasm_import_method_incoming_request_method(arg0 int32, arg1 uintptr)
+
+func (self *IncomingRequest) Method() Method {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4))
+ wasm_import_method_incoming_request_method((self).Handle(), returnArea)
+ var variant Method
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ variant = MakeMethodGet()
+
+ case 1:
+
+ variant = MakeMethodHead()
+
+ case 2:
+
+ variant = MakeMethodPost()
+
+ case 3:
+
+ variant = MakeMethodPut()
+
+ case 4:
+
+ variant = MakeMethodDelete()
+
+ case 5:
+
+ variant = MakeMethodConnect()
+
+ case 6:
+
+ variant = MakeMethodOptions()
+
+ case 7:
+
+ variant = MakeMethodTrace()
+
+ case 8:
+
+ variant = MakeMethodPatch()
+
+ case 9:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+
+ variant = MakeMethodOther(value)
+
+ default:
+ panic("unreachable")
+ }
+ result := variant
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]incoming-request.path-with-query
+func wasm_import_method_incoming_request_path_with_query(arg0 int32, arg1 uintptr)
+
+func (self *IncomingRequest) PathWithQuery() witTypes.Option[string] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4))
+ wasm_import_method_incoming_request_path_with_query((self).Handle(), returnArea)
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+
+ option = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]incoming-request.scheme
+func wasm_import_method_incoming_request_scheme(arg0 int32, arg1 uintptr)
+
+func (self *IncomingRequest) Scheme() witTypes.Option[Scheme] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4))
+ wasm_import_method_incoming_request_scheme((self).Handle(), returnArea)
+ var option witTypes.Option[Scheme]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[Scheme]()
+ case 1:
+ var variant Scheme
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeSchemeHttp()
+
+ case 1:
+
+ variant = MakeSchemeHttps()
+
+ case 2:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))
+
+ variant = MakeSchemeOther(value)
+
+ default:
+ panic("unreachable")
+ }
+
+ option = witTypes.Some[Scheme](variant)
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]incoming-request.authority
+func wasm_import_method_incoming_request_authority(arg0 int32, arg1 uintptr)
+
+func (self *IncomingRequest) Authority() witTypes.Option[string] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4))
+ wasm_import_method_incoming_request_authority((self).Handle(), returnArea)
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+
+ option = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]incoming-request.headers
+func wasm_import_method_incoming_request_headers(arg0 int32) int32
+
+func (self *IncomingRequest) Headers() *Fields {
+
+ result := wasm_import_method_incoming_request_headers((self).Handle())
+ return FieldsFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]incoming-request.consume
+func wasm_import_method_incoming_request_consume(arg0 int32, arg1 uintptr)
+
+func (self *IncomingRequest) Consume() witTypes.Result[*IncomingBody, witTypes.Unit] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_method_incoming_request_consume((self).Handle(), returnArea)
+ var result witTypes.Result[*IncomingBody, witTypes.Unit]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*IncomingBody, witTypes.Unit](IncomingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+
+ result = witTypes.Err[*IncomingBody, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [constructor]outgoing-request
+func wasm_import_constructor_outgoing_request(arg0 int32) int32
+
+func MakeOutgoingRequest(headers *Fields) *OutgoingRequest {
+
+ result := wasm_import_constructor_outgoing_request((headers).TakeHandle())
+ return OutgoingRequestFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]outgoing-request.body
+func wasm_import_method_outgoing_request_body(arg0 int32, arg1 uintptr)
+
+func (self *OutgoingRequest) Body() witTypes.Result[*OutgoingBody, witTypes.Unit] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_method_outgoing_request_body((self).Handle(), returnArea)
+ var result witTypes.Result[*OutgoingBody, witTypes.Unit]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*OutgoingBody, witTypes.Unit](OutgoingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+
+ result = witTypes.Err[*OutgoingBody, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]outgoing-request.method
+func wasm_import_method_outgoing_request_method(arg0 int32, arg1 uintptr)
+
+func (self *OutgoingRequest) Method() Method {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4))
+ wasm_import_method_outgoing_request_method((self).Handle(), returnArea)
+ var variant Method
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ variant = MakeMethodGet()
+
+ case 1:
+
+ variant = MakeMethodHead()
+
+ case 2:
+
+ variant = MakeMethodPost()
+
+ case 3:
+
+ variant = MakeMethodPut()
+
+ case 4:
+
+ variant = MakeMethodDelete()
+
+ case 5:
+
+ variant = MakeMethodConnect()
+
+ case 6:
+
+ variant = MakeMethodOptions()
+
+ case 7:
+
+ variant = MakeMethodTrace()
+
+ case 8:
+
+ variant = MakeMethodPatch()
+
+ case 9:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+
+ variant = MakeMethodOther(value)
+
+ default:
+ panic("unreachable")
+ }
+ result := variant
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]outgoing-request.set-method
+func wasm_import_method_outgoing_request_set_method(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32) int32
+
+func (self *OutgoingRequest) SetMethod(method Method) witTypes.Result[witTypes.Unit, witTypes.Unit] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ var variant int32
+ var variant0 uintptr
+ var variant1 uint32
+ switch method.Tag() {
+ case MethodGet:
+
+ variant = int32(0)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodHead:
+
+ variant = int32(1)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodPost:
+
+ variant = int32(2)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodPut:
+
+ variant = int32(3)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodDelete:
+
+ variant = int32(4)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodConnect:
+
+ variant = int32(5)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodOptions:
+
+ variant = int32(6)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodTrace:
+
+ variant = int32(7)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodPatch:
+
+ variant = int32(8)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodOther:
+ payload := method.Other()
+ utf8 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf8)
+
+ variant = int32(9)
+ variant0 = uintptr(utf8)
+ variant1 = uint32(len(payload))
+
+ default:
+ panic("unreachable")
+ }
+ result := wasm_import_method_outgoing_request_set_method((self).Handle(), variant, variant0, variant1)
+ var result2 witTypes.Result[witTypes.Unit, witTypes.Unit]
+ switch result {
+ case 0:
+
+ result2 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ case 1:
+
+ result2 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ return result2
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]outgoing-request.path-with-query
+func wasm_import_method_outgoing_request_path_with_query(arg0 int32, arg1 uintptr)
+
+func (self *OutgoingRequest) PathWithQuery() witTypes.Option[string] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4))
+ wasm_import_method_outgoing_request_path_with_query((self).Handle(), returnArea)
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+
+ option = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]outgoing-request.set-path-with-query
+func wasm_import_method_outgoing_request_set_path_with_query(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32) int32
+
+func (self *OutgoingRequest) SetPathWithQuery(pathWithQuery witTypes.Option[string]) witTypes.Result[witTypes.Unit, witTypes.Unit] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ var option int32
+ var option0 uintptr
+ var option1 uint32
+ switch pathWithQuery.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option0 = 0
+ option1 = 0
+ case witTypes.OptionSome:
+ payload := pathWithQuery.Some()
+ utf8 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf8)
+
+ option = int32(1)
+ option0 = uintptr(utf8)
+ option1 = uint32(len(payload))
+ default:
+ panic("unreachable")
+ }
+ result := wasm_import_method_outgoing_request_set_path_with_query((self).Handle(), option, option0, option1)
+ var result2 witTypes.Result[witTypes.Unit, witTypes.Unit]
+ switch result {
+ case 0:
+
+ result2 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ case 1:
+
+ result2 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ return result2
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]outgoing-request.scheme
+func wasm_import_method_outgoing_request_scheme(arg0 int32, arg1 uintptr)
+
+func (self *OutgoingRequest) Scheme() witTypes.Option[Scheme] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4))
+ wasm_import_method_outgoing_request_scheme((self).Handle(), returnArea)
+ var option witTypes.Option[Scheme]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[Scheme]()
+ case 1:
+ var variant Scheme
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeSchemeHttp()
+
+ case 1:
+
+ variant = MakeSchemeHttps()
+
+ case 2:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))
+
+ variant = MakeSchemeOther(value)
+
+ default:
+ panic("unreachable")
+ }
+
+ option = witTypes.Some[Scheme](variant)
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]outgoing-request.set-scheme
+func wasm_import_method_outgoing_request_set_scheme(arg0 int32, arg1 int32, arg2 int32, arg3 uintptr, arg4 uint32) int32
+
+func (self *OutgoingRequest) SetScheme(scheme witTypes.Option[Scheme]) witTypes.Result[witTypes.Unit, witTypes.Unit] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ var option int32
+ var option2 int32
+ var option3 uintptr
+ var option4 uint32
+ switch scheme.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option2 = 0
+ option3 = 0
+ option4 = 0
+ case witTypes.OptionSome:
+ payload := scheme.Some()
+ var variant int32
+ var variant0 uintptr
+ var variant1 uint32
+ switch payload.Tag() {
+ case SchemeHttp:
+
+ variant = int32(0)
+ variant0 = 0
+ variant1 = 0
+
+ case SchemeHttps:
+
+ variant = int32(1)
+ variant0 = 0
+ variant1 = 0
+
+ case SchemeOther:
+ payload := payload.Other()
+ utf8 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf8)
+
+ variant = int32(2)
+ variant0 = uintptr(utf8)
+ variant1 = uint32(len(payload))
+
+ default:
+ panic("unreachable")
+ }
+
+ option = int32(1)
+ option2 = variant
+ option3 = variant0
+ option4 = variant1
+ default:
+ panic("unreachable")
+ }
+ result := wasm_import_method_outgoing_request_set_scheme((self).Handle(), option, option2, option3, option4)
+ var result5 witTypes.Result[witTypes.Unit, witTypes.Unit]
+ switch result {
+ case 0:
+
+ result5 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ case 1:
+
+ result5 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ return result5
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]outgoing-request.authority
+func wasm_import_method_outgoing_request_authority(arg0 int32, arg1 uintptr)
+
+func (self *OutgoingRequest) Authority() witTypes.Option[string] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4))
+ wasm_import_method_outgoing_request_authority((self).Handle(), returnArea)
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+
+ option = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]outgoing-request.set-authority
+func wasm_import_method_outgoing_request_set_authority(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32) int32
+
+func (self *OutgoingRequest) SetAuthority(authority witTypes.Option[string]) witTypes.Result[witTypes.Unit, witTypes.Unit] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ var option int32
+ var option0 uintptr
+ var option1 uint32
+ switch authority.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option0 = 0
+ option1 = 0
+ case witTypes.OptionSome:
+ payload := authority.Some()
+ utf8 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf8)
+
+ option = int32(1)
+ option0 = uintptr(utf8)
+ option1 = uint32(len(payload))
+ default:
+ panic("unreachable")
+ }
+ result := wasm_import_method_outgoing_request_set_authority((self).Handle(), option, option0, option1)
+ var result2 witTypes.Result[witTypes.Unit, witTypes.Unit]
+ switch result {
+ case 0:
+
+ result2 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ case 1:
+
+ result2 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ return result2
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]outgoing-request.headers
+func wasm_import_method_outgoing_request_headers(arg0 int32) int32
+
+func (self *OutgoingRequest) Headers() *Fields {
+
+ result := wasm_import_method_outgoing_request_headers((self).Handle())
+ return FieldsFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [constructor]request-options
+func wasm_import_constructor_request_options() int32
+
+func MakeRequestOptions() *RequestOptions {
+
+ result := wasm_import_constructor_request_options()
+ return RequestOptionsFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]request-options.connect-timeout
+func wasm_import_method_request_options_connect_timeout(arg0 int32, arg1 uintptr)
+
+func (self *RequestOptions) ConnectTimeout() witTypes.Option[uint64] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_request_options_connect_timeout((self).Handle(), returnArea)
+ var option witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[uint64]()
+ case 1:
+
+ option = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]request-options.set-connect-timeout
+func wasm_import_method_request_options_set_connect_timeout(arg0 int32, arg1 int32, arg2 int64) int32
+
+func (self *RequestOptions) SetConnectTimeout(duration witTypes.Option[uint64]) witTypes.Result[witTypes.Unit, witTypes.Unit] {
+
+ var option int32
+ var option0 int64
+ switch duration.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option0 = 0
+ case witTypes.OptionSome:
+ payload := duration.Some()
+
+ option = int32(1)
+ option0 = int64(payload)
+ default:
+ panic("unreachable")
+ }
+ result := wasm_import_method_request_options_set_connect_timeout((self).Handle(), option, option0)
+ var result1 witTypes.Result[witTypes.Unit, witTypes.Unit]
+ switch result {
+ case 0:
+
+ result1 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ case 1:
+
+ result1 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ return result1
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]request-options.first-byte-timeout
+func wasm_import_method_request_options_first_byte_timeout(arg0 int32, arg1 uintptr)
+
+func (self *RequestOptions) FirstByteTimeout() witTypes.Option[uint64] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_request_options_first_byte_timeout((self).Handle(), returnArea)
+ var option witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[uint64]()
+ case 1:
+
+ option = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]request-options.set-first-byte-timeout
+func wasm_import_method_request_options_set_first_byte_timeout(arg0 int32, arg1 int32, arg2 int64) int32
+
+func (self *RequestOptions) SetFirstByteTimeout(duration witTypes.Option[uint64]) witTypes.Result[witTypes.Unit, witTypes.Unit] {
+
+ var option int32
+ var option0 int64
+ switch duration.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option0 = 0
+ case witTypes.OptionSome:
+ payload := duration.Some()
+
+ option = int32(1)
+ option0 = int64(payload)
+ default:
+ panic("unreachable")
+ }
+ result := wasm_import_method_request_options_set_first_byte_timeout((self).Handle(), option, option0)
+ var result1 witTypes.Result[witTypes.Unit, witTypes.Unit]
+ switch result {
+ case 0:
+
+ result1 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ case 1:
+
+ result1 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ return result1
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]request-options.between-bytes-timeout
+func wasm_import_method_request_options_between_bytes_timeout(arg0 int32, arg1 uintptr)
+
+func (self *RequestOptions) BetweenBytesTimeout() witTypes.Option[uint64] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_request_options_between_bytes_timeout((self).Handle(), returnArea)
+ var option witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[uint64]()
+ case 1:
+
+ option = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]request-options.set-between-bytes-timeout
+func wasm_import_method_request_options_set_between_bytes_timeout(arg0 int32, arg1 int32, arg2 int64) int32
+
+func (self *RequestOptions) SetBetweenBytesTimeout(duration witTypes.Option[uint64]) witTypes.Result[witTypes.Unit, witTypes.Unit] {
+
+ var option int32
+ var option0 int64
+ switch duration.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option0 = 0
+ case witTypes.OptionSome:
+ payload := duration.Some()
+
+ option = int32(1)
+ option0 = int64(payload)
+ default:
+ panic("unreachable")
+ }
+ result := wasm_import_method_request_options_set_between_bytes_timeout((self).Handle(), option, option0)
+ var result1 witTypes.Result[witTypes.Unit, witTypes.Unit]
+ switch result {
+ case 0:
+
+ result1 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ case 1:
+
+ result1 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ return result1
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [static]response-outparam.set
+func wasm_import_static_response_outparam_set(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int64, arg5 uintptr, arg6 uintptr, arg7 uint32, arg8 int32)
+
+func ResponseOutparamSet(param *ResponseOutparam, response witTypes.Result[*OutgoingResponse, ErrorCode]) {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ var option70 int32
+ var option71 int32
+ var option72 int32
+ var option73 int64
+ var option74 uintptr
+ var option75 uintptr
+ var option76 uint32
+ var option77 int32
+ switch response.Tag() {
+ case witTypes.ResultOk:
+ payload := response.Ok()
+
+ option70 = int32(0)
+ option71 = (payload).TakeHandle()
+ option72 = 0
+ option73 = 0
+ option74 = 0
+ option75 = 0
+ option76 = 0
+ option77 = 0
+ case witTypes.ResultErr:
+ payload := response.Err()
+ var variant int32
+ var variant64 int32
+ var variant65 int64
+ var variant66 uintptr
+ var variant67 uintptr
+ var variant68 uint32
+ var variant69 int32
+ switch payload.Tag() {
+ case ErrorCodeDnsTimeout:
+
+ variant = int32(0)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeDnsError:
+ payload := payload.DnsError()
+ var option int32
+ var option0 uintptr
+ var option1 uint32
+ switch (payload).Rcode.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option0 = 0
+ option1 = 0
+ case witTypes.OptionSome:
+ payload := (payload).Rcode.Some()
+ utf8 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf8)
+
+ option = int32(1)
+ option0 = uintptr(utf8)
+ option1 = uint32(len(payload))
+ default:
+ panic("unreachable")
+ }
+ var option2 int32
+ var option3 int32
+ switch (payload).InfoCode.Tag() {
+ case witTypes.OptionNone:
+
+ option2 = int32(0)
+ option3 = 0
+ case witTypes.OptionSome:
+ payload := (payload).InfoCode.Some()
+
+ option2 = int32(1)
+ option3 = int32(payload)
+ default:
+ panic("unreachable")
+ }
+
+ variant = int32(1)
+ variant64 = option
+ variant65 = int64(option0)
+ variant66 = uintptr(option1)
+ variant67 = uintptr(option2)
+ variant68 = uint32(option3)
+ variant69 = 0
+
+ case ErrorCodeDestinationNotFound:
+
+ variant = int32(2)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeDestinationUnavailable:
+
+ variant = int32(3)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeDestinationIpProhibited:
+
+ variant = int32(4)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeDestinationIpUnroutable:
+
+ variant = int32(5)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeConnectionRefused:
+
+ variant = int32(6)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeConnectionTerminated:
+
+ variant = int32(7)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeConnectionTimeout:
+
+ variant = int32(8)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeConnectionReadTimeout:
+
+ variant = int32(9)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeConnectionWriteTimeout:
+
+ variant = int32(10)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeConnectionLimitReached:
+
+ variant = int32(11)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeTlsProtocolError:
+
+ variant = int32(12)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeTlsCertificateError:
+
+ variant = int32(13)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeTlsAlertReceived:
+ payload := payload.TlsAlertReceived()
+ var option4 int32
+ var option5 int32
+ switch (payload).AlertId.Tag() {
+ case witTypes.OptionNone:
+
+ option4 = int32(0)
+ option5 = 0
+ case witTypes.OptionSome:
+ payload := (payload).AlertId.Some()
+
+ option4 = int32(1)
+ option5 = int32(payload)
+ default:
+ panic("unreachable")
+ }
+ var option7 int32
+ var option8 uintptr
+ var option9 uint32
+ switch (payload).AlertMessage.Tag() {
+ case witTypes.OptionNone:
+
+ option7 = int32(0)
+ option8 = 0
+ option9 = 0
+ case witTypes.OptionSome:
+ payload := (payload).AlertMessage.Some()
+ utf86 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf86)
+
+ option7 = int32(1)
+ option8 = uintptr(utf86)
+ option9 = uint32(len(payload))
+ default:
+ panic("unreachable")
+ }
+
+ variant = int32(14)
+ variant64 = option4
+ variant65 = int64(option5)
+ variant66 = uintptr(option7)
+ variant67 = option8
+ variant68 = option9
+ variant69 = 0
+
+ case ErrorCodeHttpRequestDenied:
+
+ variant = int32(15)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpRequestLengthRequired:
+
+ variant = int32(16)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpRequestBodySize:
+ payload := payload.HttpRequestBodySize()
+ var option10 int32
+ var option11 int64
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+
+ option10 = int32(0)
+ option11 = 0
+ case witTypes.OptionSome:
+ payload := payload.Some()
+
+ option10 = int32(1)
+ option11 = int64(payload)
+ default:
+ panic("unreachable")
+ }
+
+ variant = int32(17)
+ variant64 = option10
+ variant65 = option11
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpRequestMethodInvalid:
+
+ variant = int32(18)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpRequestUriInvalid:
+
+ variant = int32(19)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpRequestUriTooLong:
+
+ variant = int32(20)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpRequestHeaderSectionSize:
+ payload := payload.HttpRequestHeaderSectionSize()
+ var option12 int32
+ var option13 int32
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+
+ option12 = int32(0)
+ option13 = 0
+ case witTypes.OptionSome:
+ payload := payload.Some()
+
+ option12 = int32(1)
+ option13 = int32(payload)
+ default:
+ panic("unreachable")
+ }
+
+ variant = int32(21)
+ variant64 = option12
+ variant65 = int64(option13)
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpRequestHeaderSize:
+ payload := payload.HttpRequestHeaderSize()
+ var option20 int32
+ var option21 int32
+ var option22 uintptr
+ var option23 uint32
+ var option24 int32
+ var option25 int32
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+
+ option20 = int32(0)
+ option21 = 0
+ option22 = 0
+ option23 = 0
+ option24 = 0
+ option25 = 0
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ var option15 int32
+ var option16 uintptr
+ var option17 uint32
+ switch (payload).FieldName.Tag() {
+ case witTypes.OptionNone:
+
+ option15 = int32(0)
+ option16 = 0
+ option17 = 0
+ case witTypes.OptionSome:
+ payload := (payload).FieldName.Some()
+ utf814 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf814)
+
+ option15 = int32(1)
+ option16 = uintptr(utf814)
+ option17 = uint32(len(payload))
+ default:
+ panic("unreachable")
+ }
+ var option18 int32
+ var option19 int32
+ switch (payload).FieldSize.Tag() {
+ case witTypes.OptionNone:
+
+ option18 = int32(0)
+ option19 = 0
+ case witTypes.OptionSome:
+ payload := (payload).FieldSize.Some()
+
+ option18 = int32(1)
+ option19 = int32(payload)
+ default:
+ panic("unreachable")
+ }
+
+ option20 = int32(1)
+ option21 = option15
+ option22 = option16
+ option23 = option17
+ option24 = option18
+ option25 = option19
+ default:
+ panic("unreachable")
+ }
+
+ variant = int32(22)
+ variant64 = option20
+ variant65 = int64(option21)
+ variant66 = option22
+ variant67 = uintptr(option23)
+ variant68 = uint32(option24)
+ variant69 = option25
+
+ case ErrorCodeHttpRequestTrailerSectionSize:
+ payload := payload.HttpRequestTrailerSectionSize()
+ var option26 int32
+ var option27 int32
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+
+ option26 = int32(0)
+ option27 = 0
+ case witTypes.OptionSome:
+ payload := payload.Some()
+
+ option26 = int32(1)
+ option27 = int32(payload)
+ default:
+ panic("unreachable")
+ }
+
+ variant = int32(23)
+ variant64 = option26
+ variant65 = int64(option27)
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpRequestTrailerSize:
+ payload := payload.HttpRequestTrailerSize()
+ var option29 int32
+ var option30 uintptr
+ var option31 uint32
+ switch (payload).FieldName.Tag() {
+ case witTypes.OptionNone:
+
+ option29 = int32(0)
+ option30 = 0
+ option31 = 0
+ case witTypes.OptionSome:
+ payload := (payload).FieldName.Some()
+ utf828 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf828)
+
+ option29 = int32(1)
+ option30 = uintptr(utf828)
+ option31 = uint32(len(payload))
+ default:
+ panic("unreachable")
+ }
+ var option32 int32
+ var option33 int32
+ switch (payload).FieldSize.Tag() {
+ case witTypes.OptionNone:
+
+ option32 = int32(0)
+ option33 = 0
+ case witTypes.OptionSome:
+ payload := (payload).FieldSize.Some()
+
+ option32 = int32(1)
+ option33 = int32(payload)
+ default:
+ panic("unreachable")
+ }
+
+ variant = int32(24)
+ variant64 = option29
+ variant65 = int64(option30)
+ variant66 = uintptr(option31)
+ variant67 = uintptr(option32)
+ variant68 = uint32(option33)
+ variant69 = 0
+
+ case ErrorCodeHttpResponseIncomplete:
+
+ variant = int32(25)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpResponseHeaderSectionSize:
+ payload := payload.HttpResponseHeaderSectionSize()
+ var option34 int32
+ var option35 int32
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+
+ option34 = int32(0)
+ option35 = 0
+ case witTypes.OptionSome:
+ payload := payload.Some()
+
+ option34 = int32(1)
+ option35 = int32(payload)
+ default:
+ panic("unreachable")
+ }
+
+ variant = int32(26)
+ variant64 = option34
+ variant65 = int64(option35)
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpResponseHeaderSize:
+ payload := payload.HttpResponseHeaderSize()
+ var option37 int32
+ var option38 uintptr
+ var option39 uint32
+ switch (payload).FieldName.Tag() {
+ case witTypes.OptionNone:
+
+ option37 = int32(0)
+ option38 = 0
+ option39 = 0
+ case witTypes.OptionSome:
+ payload := (payload).FieldName.Some()
+ utf836 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf836)
+
+ option37 = int32(1)
+ option38 = uintptr(utf836)
+ option39 = uint32(len(payload))
+ default:
+ panic("unreachable")
+ }
+ var option40 int32
+ var option41 int32
+ switch (payload).FieldSize.Tag() {
+ case witTypes.OptionNone:
+
+ option40 = int32(0)
+ option41 = 0
+ case witTypes.OptionSome:
+ payload := (payload).FieldSize.Some()
+
+ option40 = int32(1)
+ option41 = int32(payload)
+ default:
+ panic("unreachable")
+ }
+
+ variant = int32(27)
+ variant64 = option37
+ variant65 = int64(option38)
+ variant66 = uintptr(option39)
+ variant67 = uintptr(option40)
+ variant68 = uint32(option41)
+ variant69 = 0
+
+ case ErrorCodeHttpResponseBodySize:
+ payload := payload.HttpResponseBodySize()
+ var option42 int32
+ var option43 int64
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+
+ option42 = int32(0)
+ option43 = 0
+ case witTypes.OptionSome:
+ payload := payload.Some()
+
+ option42 = int32(1)
+ option43 = int64(payload)
+ default:
+ panic("unreachable")
+ }
+
+ variant = int32(28)
+ variant64 = option42
+ variant65 = option43
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpResponseTrailerSectionSize:
+ payload := payload.HttpResponseTrailerSectionSize()
+ var option44 int32
+ var option45 int32
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+
+ option44 = int32(0)
+ option45 = 0
+ case witTypes.OptionSome:
+ payload := payload.Some()
+
+ option44 = int32(1)
+ option45 = int32(payload)
+ default:
+ panic("unreachable")
+ }
+
+ variant = int32(29)
+ variant64 = option44
+ variant65 = int64(option45)
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpResponseTrailerSize:
+ payload := payload.HttpResponseTrailerSize()
+ var option47 int32
+ var option48 uintptr
+ var option49 uint32
+ switch (payload).FieldName.Tag() {
+ case witTypes.OptionNone:
+
+ option47 = int32(0)
+ option48 = 0
+ option49 = 0
+ case witTypes.OptionSome:
+ payload := (payload).FieldName.Some()
+ utf846 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf846)
+
+ option47 = int32(1)
+ option48 = uintptr(utf846)
+ option49 = uint32(len(payload))
+ default:
+ panic("unreachable")
+ }
+ var option50 int32
+ var option51 int32
+ switch (payload).FieldSize.Tag() {
+ case witTypes.OptionNone:
+
+ option50 = int32(0)
+ option51 = 0
+ case witTypes.OptionSome:
+ payload := (payload).FieldSize.Some()
+
+ option50 = int32(1)
+ option51 = int32(payload)
+ default:
+ panic("unreachable")
+ }
+
+ variant = int32(30)
+ variant64 = option47
+ variant65 = int64(option48)
+ variant66 = uintptr(option49)
+ variant67 = uintptr(option50)
+ variant68 = uint32(option51)
+ variant69 = 0
+
+ case ErrorCodeHttpResponseTransferCoding:
+ payload := payload.HttpResponseTransferCoding()
+ var option53 int32
+ var option54 uintptr
+ var option55 uint32
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+
+ option53 = int32(0)
+ option54 = 0
+ option55 = 0
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ utf852 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf852)
+
+ option53 = int32(1)
+ option54 = uintptr(utf852)
+ option55 = uint32(len(payload))
+ default:
+ panic("unreachable")
+ }
+
+ variant = int32(31)
+ variant64 = option53
+ variant65 = int64(option54)
+ variant66 = uintptr(option55)
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpResponseContentCoding:
+ payload := payload.HttpResponseContentCoding()
+ var option57 int32
+ var option58 uintptr
+ var option59 uint32
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+
+ option57 = int32(0)
+ option58 = 0
+ option59 = 0
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ utf856 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf856)
+
+ option57 = int32(1)
+ option58 = uintptr(utf856)
+ option59 = uint32(len(payload))
+ default:
+ panic("unreachable")
+ }
+
+ variant = int32(32)
+ variant64 = option57
+ variant65 = int64(option58)
+ variant66 = uintptr(option59)
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpResponseTimeout:
+
+ variant = int32(33)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpUpgradeFailed:
+
+ variant = int32(34)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeHttpProtocolError:
+
+ variant = int32(35)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeLoopDetected:
+
+ variant = int32(36)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeConfigurationError:
+
+ variant = int32(37)
+ variant64 = 0
+ variant65 = 0
+ variant66 = 0
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ case ErrorCodeInternalError:
+ payload := payload.InternalError()
+ var option61 int32
+ var option62 uintptr
+ var option63 uint32
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+
+ option61 = int32(0)
+ option62 = 0
+ option63 = 0
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ utf860 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf860)
+
+ option61 = int32(1)
+ option62 = uintptr(utf860)
+ option63 = uint32(len(payload))
+ default:
+ panic("unreachable")
+ }
+
+ variant = int32(38)
+ variant64 = option61
+ variant65 = int64(option62)
+ variant66 = uintptr(option63)
+ variant67 = 0
+ variant68 = 0
+ variant69 = 0
+
+ default:
+ panic("unreachable")
+ }
+
+ option70 = int32(1)
+ option71 = variant
+ option72 = variant64
+ option73 = variant65
+ option74 = variant66
+ option75 = variant67
+ option76 = variant68
+ option77 = variant69
+ default:
+ panic("unreachable")
+ }
+ wasm_import_static_response_outparam_set((param).TakeHandle(), option70, option71, option72, option73, option74, option75, option76, option77)
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]incoming-response.status
+func wasm_import_method_incoming_response_status(arg0 int32) int32
+
+func (self *IncomingResponse) Status() uint16 {
+
+ result := wasm_import_method_incoming_response_status((self).Handle())
+ return uint16(result)
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]incoming-response.headers
+func wasm_import_method_incoming_response_headers(arg0 int32) int32
+
+func (self *IncomingResponse) Headers() *Fields {
+
+ result := wasm_import_method_incoming_response_headers((self).Handle())
+ return FieldsFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]incoming-response.consume
+func wasm_import_method_incoming_response_consume(arg0 int32, arg1 uintptr)
+
+func (self *IncomingResponse) Consume() witTypes.Result[*IncomingBody, witTypes.Unit] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_method_incoming_response_consume((self).Handle(), returnArea)
+ var result witTypes.Result[*IncomingBody, witTypes.Unit]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*IncomingBody, witTypes.Unit](IncomingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+
+ result = witTypes.Err[*IncomingBody, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]incoming-body.stream
+func wasm_import_method_incoming_body_stream(arg0 int32, arg1 uintptr)
+
+func (self *IncomingBody) Stream() witTypes.Result[*wasi_io_0_2_8_streams.InputStream, witTypes.Unit] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_method_incoming_body_stream((self).Handle(), returnArea)
+ var result witTypes.Result[*wasi_io_0_2_8_streams.InputStream, witTypes.Unit]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*wasi_io_0_2_8_streams.InputStream, witTypes.Unit](wasi_io_0_2_8_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+
+ result = witTypes.Err[*wasi_io_0_2_8_streams.InputStream, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [static]incoming-body.finish
+func wasm_import_static_incoming_body_finish(arg0 int32) int32
+
+func IncomingBodyFinish(this *IncomingBody) *FutureTrailers {
+
+ result := wasm_import_static_incoming_body_finish((this).TakeHandle())
+ return FutureTrailersFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]future-trailers.subscribe
+func wasm_import_method_future_trailers_subscribe(arg0 int32) int32
+
+func (self *FutureTrailers) Subscribe() *wasi_io_0_2_8_poll.Pollable {
+
+ result := wasm_import_method_future_trailers_subscribe((self).Handle())
+ return wasi_io_0_2_8_poll.PollableFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]future-trailers.get
+func wasm_import_method_future_trailers_get(arg0 int32, arg1 uintptr)
+
+func (self *FutureTrailers) Get() witTypes.Option[witTypes.Result[witTypes.Result[witTypes.Option[*Fields], ErrorCode], witTypes.Unit]] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (40 + 4*4), 8))
+ wasm_import_method_future_trailers_get((self).Handle(), returnArea)
+ var option31 witTypes.Option[witTypes.Result[witTypes.Result[witTypes.Option[*Fields], ErrorCode], witTypes.Unit]]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option31 = witTypes.None[witTypes.Result[witTypes.Result[witTypes.Option[*Fields], ErrorCode], witTypes.Unit]]()
+ case 1:
+ var result30 witTypes.Result[witTypes.Result[witTypes.Option[*Fields], ErrorCode], witTypes.Unit]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) {
+ case 0:
+ var result witTypes.Result[witTypes.Option[*Fields], ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+ var option witTypes.Option[*Fields]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24))) {
+ case 0:
+
+ option = witTypes.None[*Fields]()
+ case 1:
+
+ option = witTypes.Some[*Fields](FieldsFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 28))))))
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Ok[witTypes.Option[*Fields], ErrorCode](option)
+ case 1:
+ var variant ErrorCode
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24))) {
+ case 0:
+
+ variant = MakeErrorCodeDnsTimeout()
+
+ case 1:
+ var option0 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option0 = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4))))
+
+ option0 = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+ var option1 witTypes.Option[uint16]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) {
+ case 0:
+
+ option1 = witTypes.None[uint16]()
+ case 1:
+
+ option1 = witTypes.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (34 + 3*4))))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeDnsError(DnsErrorPayload{option0, option1})
+
+ case 2:
+
+ variant = MakeErrorCodeDestinationNotFound()
+
+ case 3:
+
+ variant = MakeErrorCodeDestinationUnavailable()
+
+ case 4:
+
+ variant = MakeErrorCodeDestinationIpProhibited()
+
+ case 5:
+
+ variant = MakeErrorCodeDestinationIpUnroutable()
+
+ case 6:
+
+ variant = MakeErrorCodeConnectionRefused()
+
+ case 7:
+
+ variant = MakeErrorCodeConnectionTerminated()
+
+ case 8:
+
+ variant = MakeErrorCodeConnectionTimeout()
+
+ case 9:
+
+ variant = MakeErrorCodeConnectionReadTimeout()
+
+ case 10:
+
+ variant = MakeErrorCodeConnectionWriteTimeout()
+
+ case 11:
+
+ variant = MakeErrorCodeConnectionLimitReached()
+
+ case 12:
+
+ variant = MakeErrorCodeTlsProtocolError()
+
+ case 13:
+
+ variant = MakeErrorCodeTlsCertificateError()
+
+ case 14:
+ var option2 witTypes.Option[uint8]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option2 = witTypes.None[uint8]()
+ case 1:
+
+ option2 = witTypes.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 33)))))
+ default:
+ panic("unreachable")
+ }
+ var option4 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))) {
+ case 0:
+
+ option4 = witTypes.None[string]()
+ case 1:
+ value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4))))
+
+ option4 = witTypes.Some[string](value3)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeTlsAlertReceived(TlsAlertReceivedPayload{option2, option4})
+
+ case 15:
+
+ variant = MakeErrorCodeHttpRequestDenied()
+
+ case 16:
+
+ variant = MakeErrorCodeHttpRequestLengthRequired()
+
+ case 17:
+ var option5 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option5 = witTypes.None[uint64]()
+ case 1:
+
+ option5 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestBodySize(option5)
+
+ case 18:
+
+ variant = MakeErrorCodeHttpRequestMethodInvalid()
+
+ case 19:
+
+ variant = MakeErrorCodeHttpRequestUriInvalid()
+
+ case 20:
+
+ variant = MakeErrorCodeHttpRequestUriTooLong()
+
+ case 21:
+ var option6 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option6 = witTypes.None[uint32]()
+ case 1:
+
+ option6 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestHeaderSectionSize(option6)
+
+ case 22:
+ var option10 witTypes.Option[FieldSizePayload]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option10 = witTypes.None[FieldSizePayload]()
+ case 1:
+ var option8 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))) {
+ case 0:
+
+ option8 = witTypes.None[string]()
+ case 1:
+ value7 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4))))
+
+ option8 = witTypes.Some[string](value7)
+ default:
+ panic("unreachable")
+ }
+ var option9 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 4*4)))) {
+ case 0:
+
+ option9 = witTypes.None[uint32]()
+ case 1:
+
+ option9 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 4*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ option10 = witTypes.Some[FieldSizePayload](FieldSizePayload{option8, option9})
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestHeaderSize(option10)
+
+ case 23:
+ var option11 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option11 = witTypes.None[uint32]()
+ case 1:
+
+ option11 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestTrailerSectionSize(option11)
+
+ case 24:
+ var option13 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option13 = witTypes.None[string]()
+ case 1:
+ value12 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4))))
+
+ option13 = witTypes.Some[string](value12)
+ default:
+ panic("unreachable")
+ }
+ var option14 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) {
+ case 0:
+
+ option14 = witTypes.None[uint32]()
+ case 1:
+
+ option14 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestTrailerSize(FieldSizePayload{option13, option14})
+
+ case 25:
+
+ variant = MakeErrorCodeHttpResponseIncomplete()
+
+ case 26:
+ var option15 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option15 = witTypes.None[uint32]()
+ case 1:
+
+ option15 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseHeaderSectionSize(option15)
+
+ case 27:
+ var option17 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option17 = witTypes.None[string]()
+ case 1:
+ value16 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4))))
+
+ option17 = witTypes.Some[string](value16)
+ default:
+ panic("unreachable")
+ }
+ var option18 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) {
+ case 0:
+
+ option18 = witTypes.None[uint32]()
+ case 1:
+
+ option18 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseHeaderSize(FieldSizePayload{option17, option18})
+
+ case 28:
+ var option19 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option19 = witTypes.None[uint64]()
+ case 1:
+
+ option19 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseBodySize(option19)
+
+ case 29:
+ var option20 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option20 = witTypes.None[uint32]()
+ case 1:
+
+ option20 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTrailerSectionSize(option20)
+
+ case 30:
+ var option22 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option22 = witTypes.None[string]()
+ case 1:
+ value21 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4))))
+
+ option22 = witTypes.Some[string](value21)
+ default:
+ panic("unreachable")
+ }
+ var option23 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) {
+ case 0:
+
+ option23 = witTypes.None[uint32]()
+ case 1:
+
+ option23 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTrailerSize(FieldSizePayload{option22, option23})
+
+ case 31:
+ var option25 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option25 = witTypes.None[string]()
+ case 1:
+ value24 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4))))
+
+ option25 = witTypes.Some[string](value24)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTransferCoding(option25)
+
+ case 32:
+ var option27 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option27 = witTypes.None[string]()
+ case 1:
+ value26 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4))))
+
+ option27 = witTypes.Some[string](value26)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseContentCoding(option27)
+
+ case 33:
+
+ variant = MakeErrorCodeHttpResponseTimeout()
+
+ case 34:
+
+ variant = MakeErrorCodeHttpUpgradeFailed()
+
+ case 35:
+
+ variant = MakeErrorCodeHttpProtocolError()
+
+ case 36:
+
+ variant = MakeErrorCodeLoopDetected()
+
+ case 37:
+
+ variant = MakeErrorCodeConfigurationError()
+
+ case 38:
+ var option29 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option29 = witTypes.None[string]()
+ case 1:
+ value28 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4))))
+
+ option29 = witTypes.Some[string](value28)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeInternalError(option29)
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Option[*Fields], ErrorCode](variant)
+ default:
+ panic("unreachable")
+ }
+
+ result30 = witTypes.Ok[witTypes.Result[witTypes.Option[*Fields], ErrorCode], witTypes.Unit](result)
+ case 1:
+
+ result30 = witTypes.Err[witTypes.Result[witTypes.Option[*Fields], ErrorCode], witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+
+ option31 = witTypes.Some[witTypes.Result[witTypes.Result[witTypes.Option[*Fields], ErrorCode], witTypes.Unit]](result30)
+ default:
+ panic("unreachable")
+ }
+ result32 := option31
+ return result32
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [constructor]outgoing-response
+func wasm_import_constructor_outgoing_response(arg0 int32) int32
+
+func MakeOutgoingResponse(headers *Fields) *OutgoingResponse {
+
+ result := wasm_import_constructor_outgoing_response((headers).TakeHandle())
+ return OutgoingResponseFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]outgoing-response.status-code
+func wasm_import_method_outgoing_response_status_code(arg0 int32) int32
+
+func (self *OutgoingResponse) StatusCode() uint16 {
+
+ result := wasm_import_method_outgoing_response_status_code((self).Handle())
+ return uint16(result)
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]outgoing-response.set-status-code
+func wasm_import_method_outgoing_response_set_status_code(arg0 int32, arg1 int32) int32
+
+func (self *OutgoingResponse) SetStatusCode(statusCode uint16) witTypes.Result[witTypes.Unit, witTypes.Unit] {
+
+ result := wasm_import_method_outgoing_response_set_status_code((self).Handle(), int32(statusCode))
+ var result0 witTypes.Result[witTypes.Unit, witTypes.Unit]
+ switch result {
+ case 0:
+
+ result0 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ case 1:
+
+ result0 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ return result0
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]outgoing-response.headers
+func wasm_import_method_outgoing_response_headers(arg0 int32) int32
+
+func (self *OutgoingResponse) Headers() *Fields {
+
+ result := wasm_import_method_outgoing_response_headers((self).Handle())
+ return FieldsFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]outgoing-response.body
+func wasm_import_method_outgoing_response_body(arg0 int32, arg1 uintptr)
+
+func (self *OutgoingResponse) Body() witTypes.Result[*OutgoingBody, witTypes.Unit] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_method_outgoing_response_body((self).Handle(), returnArea)
+ var result witTypes.Result[*OutgoingBody, witTypes.Unit]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*OutgoingBody, witTypes.Unit](OutgoingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+
+ result = witTypes.Err[*OutgoingBody, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]outgoing-body.write
+func wasm_import_method_outgoing_body_write(arg0 int32, arg1 uintptr)
+
+func (self *OutgoingBody) Write() witTypes.Result[*wasi_io_0_2_8_streams.OutputStream, witTypes.Unit] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_method_outgoing_body_write((self).Handle(), returnArea)
+ var result witTypes.Result[*wasi_io_0_2_8_streams.OutputStream, witTypes.Unit]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*wasi_io_0_2_8_streams.OutputStream, witTypes.Unit](wasi_io_0_2_8_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+
+ result = witTypes.Err[*wasi_io_0_2_8_streams.OutputStream, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [static]outgoing-body.finish
+func wasm_import_static_outgoing_body_finish(arg0 int32, arg1 int32, arg2 int32, arg3 uintptr)
+
+func OutgoingBodyFinish(this *OutgoingBody, trailers witTypes.Option[*Fields]) witTypes.Result[witTypes.Unit, ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (24 + 4*4), 8))
+ var option int32
+ var option0 int32
+ switch trailers.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option0 = 0
+ case witTypes.OptionSome:
+ payload := trailers.Some()
+
+ option = int32(1)
+ option0 = (payload).TakeHandle()
+ default:
+ panic("unreachable")
+ }
+ wasm_import_static_outgoing_body_finish((this).TakeHandle(), option, option0, returnArea)
+ var result witTypes.Result[witTypes.Unit, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{})
+ case 1:
+ var variant ErrorCode
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) {
+ case 0:
+
+ variant = MakeErrorCodeDnsTimeout()
+
+ case 1:
+ var option1 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option1 = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option1 = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+ var option2 witTypes.Option[uint16]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option2 = witTypes.None[uint16]()
+ case 1:
+
+ option2 = witTypes.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (18 + 3*4))))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeDnsError(DnsErrorPayload{option1, option2})
+
+ case 2:
+
+ variant = MakeErrorCodeDestinationNotFound()
+
+ case 3:
+
+ variant = MakeErrorCodeDestinationUnavailable()
+
+ case 4:
+
+ variant = MakeErrorCodeDestinationIpProhibited()
+
+ case 5:
+
+ variant = MakeErrorCodeDestinationIpUnroutable()
+
+ case 6:
+
+ variant = MakeErrorCodeConnectionRefused()
+
+ case 7:
+
+ variant = MakeErrorCodeConnectionTerminated()
+
+ case 8:
+
+ variant = MakeErrorCodeConnectionTimeout()
+
+ case 9:
+
+ variant = MakeErrorCodeConnectionReadTimeout()
+
+ case 10:
+
+ variant = MakeErrorCodeConnectionWriteTimeout()
+
+ case 11:
+
+ variant = MakeErrorCodeConnectionLimitReached()
+
+ case 12:
+
+ variant = MakeErrorCodeTlsProtocolError()
+
+ case 13:
+
+ variant = MakeErrorCodeTlsCertificateError()
+
+ case 14:
+ var option3 witTypes.Option[uint8]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option3 = witTypes.None[uint8]()
+ case 1:
+
+ option3 = witTypes.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 17)))))
+ default:
+ panic("unreachable")
+ }
+ var option5 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) {
+ case 0:
+
+ option5 = witTypes.None[string]()
+ case 1:
+ value4 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4))))
+
+ option5 = witTypes.Some[string](value4)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeTlsAlertReceived(TlsAlertReceivedPayload{option3, option5})
+
+ case 15:
+
+ variant = MakeErrorCodeHttpRequestDenied()
+
+ case 16:
+
+ variant = MakeErrorCodeHttpRequestLengthRequired()
+
+ case 17:
+ var option6 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option6 = witTypes.None[uint64]()
+ case 1:
+
+ option6 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestBodySize(option6)
+
+ case 18:
+
+ variant = MakeErrorCodeHttpRequestMethodInvalid()
+
+ case 19:
+
+ variant = MakeErrorCodeHttpRequestUriInvalid()
+
+ case 20:
+
+ variant = MakeErrorCodeHttpRequestUriTooLong()
+
+ case 21:
+ var option7 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option7 = witTypes.None[uint32]()
+ case 1:
+
+ option7 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestHeaderSectionSize(option7)
+
+ case 22:
+ var option11 witTypes.Option[FieldSizePayload]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option11 = witTypes.None[FieldSizePayload]()
+ case 1:
+ var option9 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) {
+ case 0:
+
+ option9 = witTypes.None[string]()
+ case 1:
+ value8 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4))))
+
+ option9 = witTypes.Some[string](value8)
+ default:
+ panic("unreachable")
+ }
+ var option10 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 4*4)))) {
+ case 0:
+
+ option10 = witTypes.None[uint32]()
+ case 1:
+
+ option10 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 4*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ option11 = witTypes.Some[FieldSizePayload](FieldSizePayload{option9, option10})
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestHeaderSize(option11)
+
+ case 23:
+ var option12 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option12 = witTypes.None[uint32]()
+ case 1:
+
+ option12 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestTrailerSectionSize(option12)
+
+ case 24:
+ var option14 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option14 = witTypes.None[string]()
+ case 1:
+ value13 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option14 = witTypes.Some[string](value13)
+ default:
+ panic("unreachable")
+ }
+ var option15 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option15 = witTypes.None[uint32]()
+ case 1:
+
+ option15 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestTrailerSize(FieldSizePayload{option14, option15})
+
+ case 25:
+
+ variant = MakeErrorCodeHttpResponseIncomplete()
+
+ case 26:
+ var option16 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option16 = witTypes.None[uint32]()
+ case 1:
+
+ option16 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseHeaderSectionSize(option16)
+
+ case 27:
+ var option18 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option18 = witTypes.None[string]()
+ case 1:
+ value17 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option18 = witTypes.Some[string](value17)
+ default:
+ panic("unreachable")
+ }
+ var option19 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option19 = witTypes.None[uint32]()
+ case 1:
+
+ option19 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseHeaderSize(FieldSizePayload{option18, option19})
+
+ case 28:
+ var option20 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option20 = witTypes.None[uint64]()
+ case 1:
+
+ option20 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseBodySize(option20)
+
+ case 29:
+ var option21 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option21 = witTypes.None[uint32]()
+ case 1:
+
+ option21 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTrailerSectionSize(option21)
+
+ case 30:
+ var option23 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option23 = witTypes.None[string]()
+ case 1:
+ value22 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option23 = witTypes.Some[string](value22)
+ default:
+ panic("unreachable")
+ }
+ var option24 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option24 = witTypes.None[uint32]()
+ case 1:
+
+ option24 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTrailerSize(FieldSizePayload{option23, option24})
+
+ case 31:
+ var option26 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option26 = witTypes.None[string]()
+ case 1:
+ value25 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option26 = witTypes.Some[string](value25)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTransferCoding(option26)
+
+ case 32:
+ var option28 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option28 = witTypes.None[string]()
+ case 1:
+ value27 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option28 = witTypes.Some[string](value27)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseContentCoding(option28)
+
+ case 33:
+
+ variant = MakeErrorCodeHttpResponseTimeout()
+
+ case 34:
+
+ variant = MakeErrorCodeHttpUpgradeFailed()
+
+ case 35:
+
+ variant = MakeErrorCodeHttpProtocolError()
+
+ case 36:
+
+ variant = MakeErrorCodeLoopDetected()
+
+ case 37:
+
+ variant = MakeErrorCodeConfigurationError()
+
+ case 38:
+ var option30 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option30 = witTypes.None[string]()
+ case 1:
+ value29 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option30 = witTypes.Some[string](value29)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeInternalError(option30)
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Unit, ErrorCode](variant)
+ default:
+ panic("unreachable")
+ }
+ result31 := result
+ return result31
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]future-incoming-response.subscribe
+func wasm_import_method_future_incoming_response_subscribe(arg0 int32) int32
+
+func (self *FutureIncomingResponse) Subscribe() *wasi_io_0_2_8_poll.Pollable {
+
+ result := wasm_import_method_future_incoming_response_subscribe((self).Handle())
+ return wasi_io_0_2_8_poll.PollableFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 [method]future-incoming-response.get
+func wasm_import_method_future_incoming_response_get(arg0 int32, arg1 uintptr)
+
+func (self *FutureIncomingResponse) Get() witTypes.Option[witTypes.Result[witTypes.Result[*IncomingResponse, ErrorCode], witTypes.Unit]] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (40 + 4*4), 8))
+ wasm_import_method_future_incoming_response_get((self).Handle(), returnArea)
+ var option30 witTypes.Option[witTypes.Result[witTypes.Result[*IncomingResponse, ErrorCode], witTypes.Unit]]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option30 = witTypes.None[witTypes.Result[witTypes.Result[*IncomingResponse, ErrorCode], witTypes.Unit]]()
+ case 1:
+ var result29 witTypes.Result[witTypes.Result[*IncomingResponse, ErrorCode], witTypes.Unit]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) {
+ case 0:
+ var result witTypes.Result[*IncomingResponse, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ result = witTypes.Ok[*IncomingResponse, ErrorCode](IncomingResponseFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 24))))))
+ case 1:
+ var variant ErrorCode
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24))) {
+ case 0:
+
+ variant = MakeErrorCodeDnsTimeout()
+
+ case 1:
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4))))
+
+ option = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+ var option0 witTypes.Option[uint16]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) {
+ case 0:
+
+ option0 = witTypes.None[uint16]()
+ case 1:
+
+ option0 = witTypes.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (34 + 3*4))))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeDnsError(DnsErrorPayload{option, option0})
+
+ case 2:
+
+ variant = MakeErrorCodeDestinationNotFound()
+
+ case 3:
+
+ variant = MakeErrorCodeDestinationUnavailable()
+
+ case 4:
+
+ variant = MakeErrorCodeDestinationIpProhibited()
+
+ case 5:
+
+ variant = MakeErrorCodeDestinationIpUnroutable()
+
+ case 6:
+
+ variant = MakeErrorCodeConnectionRefused()
+
+ case 7:
+
+ variant = MakeErrorCodeConnectionTerminated()
+
+ case 8:
+
+ variant = MakeErrorCodeConnectionTimeout()
+
+ case 9:
+
+ variant = MakeErrorCodeConnectionReadTimeout()
+
+ case 10:
+
+ variant = MakeErrorCodeConnectionWriteTimeout()
+
+ case 11:
+
+ variant = MakeErrorCodeConnectionLimitReached()
+
+ case 12:
+
+ variant = MakeErrorCodeTlsProtocolError()
+
+ case 13:
+
+ variant = MakeErrorCodeTlsCertificateError()
+
+ case 14:
+ var option1 witTypes.Option[uint8]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option1 = witTypes.None[uint8]()
+ case 1:
+
+ option1 = witTypes.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 33)))))
+ default:
+ panic("unreachable")
+ }
+ var option3 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))) {
+ case 0:
+
+ option3 = witTypes.None[string]()
+ case 1:
+ value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4))))
+
+ option3 = witTypes.Some[string](value2)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeTlsAlertReceived(TlsAlertReceivedPayload{option1, option3})
+
+ case 15:
+
+ variant = MakeErrorCodeHttpRequestDenied()
+
+ case 16:
+
+ variant = MakeErrorCodeHttpRequestLengthRequired()
+
+ case 17:
+ var option4 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option4 = witTypes.None[uint64]()
+ case 1:
+
+ option4 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestBodySize(option4)
+
+ case 18:
+
+ variant = MakeErrorCodeHttpRequestMethodInvalid()
+
+ case 19:
+
+ variant = MakeErrorCodeHttpRequestUriInvalid()
+
+ case 20:
+
+ variant = MakeErrorCodeHttpRequestUriTooLong()
+
+ case 21:
+ var option5 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option5 = witTypes.None[uint32]()
+ case 1:
+
+ option5 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestHeaderSectionSize(option5)
+
+ case 22:
+ var option9 witTypes.Option[FieldSizePayload]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option9 = witTypes.None[FieldSizePayload]()
+ case 1:
+ var option7 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))) {
+ case 0:
+
+ option7 = witTypes.None[string]()
+ case 1:
+ value6 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4))))
+
+ option7 = witTypes.Some[string](value6)
+ default:
+ panic("unreachable")
+ }
+ var option8 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 4*4)))) {
+ case 0:
+
+ option8 = witTypes.None[uint32]()
+ case 1:
+
+ option8 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 4*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ option9 = witTypes.Some[FieldSizePayload](FieldSizePayload{option7, option8})
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestHeaderSize(option9)
+
+ case 23:
+ var option10 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option10 = witTypes.None[uint32]()
+ case 1:
+
+ option10 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestTrailerSectionSize(option10)
+
+ case 24:
+ var option12 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option12 = witTypes.None[string]()
+ case 1:
+ value11 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4))))
+
+ option12 = witTypes.Some[string](value11)
+ default:
+ panic("unreachable")
+ }
+ var option13 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) {
+ case 0:
+
+ option13 = witTypes.None[uint32]()
+ case 1:
+
+ option13 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestTrailerSize(FieldSizePayload{option12, option13})
+
+ case 25:
+
+ variant = MakeErrorCodeHttpResponseIncomplete()
+
+ case 26:
+ var option14 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option14 = witTypes.None[uint32]()
+ case 1:
+
+ option14 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseHeaderSectionSize(option14)
+
+ case 27:
+ var option16 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option16 = witTypes.None[string]()
+ case 1:
+ value15 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4))))
+
+ option16 = witTypes.Some[string](value15)
+ default:
+ panic("unreachable")
+ }
+ var option17 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) {
+ case 0:
+
+ option17 = witTypes.None[uint32]()
+ case 1:
+
+ option17 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseHeaderSize(FieldSizePayload{option16, option17})
+
+ case 28:
+ var option18 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option18 = witTypes.None[uint64]()
+ case 1:
+
+ option18 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseBodySize(option18)
+
+ case 29:
+ var option19 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option19 = witTypes.None[uint32]()
+ case 1:
+
+ option19 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTrailerSectionSize(option19)
+
+ case 30:
+ var option21 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option21 = witTypes.None[string]()
+ case 1:
+ value20 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4))))
+
+ option21 = witTypes.Some[string](value20)
+ default:
+ panic("unreachable")
+ }
+ var option22 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) {
+ case 0:
+
+ option22 = witTypes.None[uint32]()
+ case 1:
+
+ option22 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTrailerSize(FieldSizePayload{option21, option22})
+
+ case 31:
+ var option24 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option24 = witTypes.None[string]()
+ case 1:
+ value23 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4))))
+
+ option24 = witTypes.Some[string](value23)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTransferCoding(option24)
+
+ case 32:
+ var option26 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option26 = witTypes.None[string]()
+ case 1:
+ value25 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4))))
+
+ option26 = witTypes.Some[string](value25)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseContentCoding(option26)
+
+ case 33:
+
+ variant = MakeErrorCodeHttpResponseTimeout()
+
+ case 34:
+
+ variant = MakeErrorCodeHttpUpgradeFailed()
+
+ case 35:
+
+ variant = MakeErrorCodeHttpProtocolError()
+
+ case 36:
+
+ variant = MakeErrorCodeLoopDetected()
+
+ case 37:
+
+ variant = MakeErrorCodeConfigurationError()
+
+ case 38:
+ var option28 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) {
+ case 0:
+
+ option28 = witTypes.None[string]()
+ case 1:
+ value27 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4))))
+
+ option28 = witTypes.Some[string](value27)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeInternalError(option28)
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[*IncomingResponse, ErrorCode](variant)
+ default:
+ panic("unreachable")
+ }
+
+ result29 = witTypes.Ok[witTypes.Result[*IncomingResponse, ErrorCode], witTypes.Unit](result)
+ case 1:
+
+ result29 = witTypes.Err[witTypes.Result[*IncomingResponse, ErrorCode], witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+
+ option30 = witTypes.Some[witTypes.Result[witTypes.Result[*IncomingResponse, ErrorCode], witTypes.Unit]](result29)
+ default:
+ panic("unreachable")
+ }
+ result31 := option30
+ return result31
+
+}
+
+//go:wasmimport wasi:http/types@0.2.8 http-error-code
+func wasm_import_http_error_code(arg0 int32, arg1 uintptr)
+
+func HttpErrorCode(err *wasi_io_0_2_8_error.Error) witTypes.Option[ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (24 + 4*4), 8))
+ wasm_import_http_error_code((err).Handle(), returnArea)
+ var option29 witTypes.Option[ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option29 = witTypes.None[ErrorCode]()
+ case 1:
+ var variant ErrorCode
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) {
+ case 0:
+
+ variant = MakeErrorCodeDnsTimeout()
+
+ case 1:
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+ var option0 witTypes.Option[uint16]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option0 = witTypes.None[uint16]()
+ case 1:
+
+ option0 = witTypes.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (18 + 3*4))))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeDnsError(DnsErrorPayload{option, option0})
+
+ case 2:
+
+ variant = MakeErrorCodeDestinationNotFound()
+
+ case 3:
+
+ variant = MakeErrorCodeDestinationUnavailable()
+
+ case 4:
+
+ variant = MakeErrorCodeDestinationIpProhibited()
+
+ case 5:
+
+ variant = MakeErrorCodeDestinationIpUnroutable()
+
+ case 6:
+
+ variant = MakeErrorCodeConnectionRefused()
+
+ case 7:
+
+ variant = MakeErrorCodeConnectionTerminated()
+
+ case 8:
+
+ variant = MakeErrorCodeConnectionTimeout()
+
+ case 9:
+
+ variant = MakeErrorCodeConnectionReadTimeout()
+
+ case 10:
+
+ variant = MakeErrorCodeConnectionWriteTimeout()
+
+ case 11:
+
+ variant = MakeErrorCodeConnectionLimitReached()
+
+ case 12:
+
+ variant = MakeErrorCodeTlsProtocolError()
+
+ case 13:
+
+ variant = MakeErrorCodeTlsCertificateError()
+
+ case 14:
+ var option1 witTypes.Option[uint8]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option1 = witTypes.None[uint8]()
+ case 1:
+
+ option1 = witTypes.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 17)))))
+ default:
+ panic("unreachable")
+ }
+ var option3 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) {
+ case 0:
+
+ option3 = witTypes.None[string]()
+ case 1:
+ value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4))))
+
+ option3 = witTypes.Some[string](value2)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeTlsAlertReceived(TlsAlertReceivedPayload{option1, option3})
+
+ case 15:
+
+ variant = MakeErrorCodeHttpRequestDenied()
+
+ case 16:
+
+ variant = MakeErrorCodeHttpRequestLengthRequired()
+
+ case 17:
+ var option4 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option4 = witTypes.None[uint64]()
+ case 1:
+
+ option4 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestBodySize(option4)
+
+ case 18:
+
+ variant = MakeErrorCodeHttpRequestMethodInvalid()
+
+ case 19:
+
+ variant = MakeErrorCodeHttpRequestUriInvalid()
+
+ case 20:
+
+ variant = MakeErrorCodeHttpRequestUriTooLong()
+
+ case 21:
+ var option5 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option5 = witTypes.None[uint32]()
+ case 1:
+
+ option5 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestHeaderSectionSize(option5)
+
+ case 22:
+ var option9 witTypes.Option[FieldSizePayload]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option9 = witTypes.None[FieldSizePayload]()
+ case 1:
+ var option7 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) {
+ case 0:
+
+ option7 = witTypes.None[string]()
+ case 1:
+ value6 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4))))
+
+ option7 = witTypes.Some[string](value6)
+ default:
+ panic("unreachable")
+ }
+ var option8 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 4*4)))) {
+ case 0:
+
+ option8 = witTypes.None[uint32]()
+ case 1:
+
+ option8 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 4*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ option9 = witTypes.Some[FieldSizePayload](FieldSizePayload{option7, option8})
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestHeaderSize(option9)
+
+ case 23:
+ var option10 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option10 = witTypes.None[uint32]()
+ case 1:
+
+ option10 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestTrailerSectionSize(option10)
+
+ case 24:
+ var option12 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option12 = witTypes.None[string]()
+ case 1:
+ value11 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option12 = witTypes.Some[string](value11)
+ default:
+ panic("unreachable")
+ }
+ var option13 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option13 = witTypes.None[uint32]()
+ case 1:
+
+ option13 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestTrailerSize(FieldSizePayload{option12, option13})
+
+ case 25:
+
+ variant = MakeErrorCodeHttpResponseIncomplete()
+
+ case 26:
+ var option14 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option14 = witTypes.None[uint32]()
+ case 1:
+
+ option14 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseHeaderSectionSize(option14)
+
+ case 27:
+ var option16 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option16 = witTypes.None[string]()
+ case 1:
+ value15 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option16 = witTypes.Some[string](value15)
+ default:
+ panic("unreachable")
+ }
+ var option17 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option17 = witTypes.None[uint32]()
+ case 1:
+
+ option17 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseHeaderSize(FieldSizePayload{option16, option17})
+
+ case 28:
+ var option18 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option18 = witTypes.None[uint64]()
+ case 1:
+
+ option18 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseBodySize(option18)
+
+ case 29:
+ var option19 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option19 = witTypes.None[uint32]()
+ case 1:
+
+ option19 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTrailerSectionSize(option19)
+
+ case 30:
+ var option21 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option21 = witTypes.None[string]()
+ case 1:
+ value20 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option21 = witTypes.Some[string](value20)
+ default:
+ panic("unreachable")
+ }
+ var option22 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option22 = witTypes.None[uint32]()
+ case 1:
+
+ option22 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTrailerSize(FieldSizePayload{option21, option22})
+
+ case 31:
+ var option24 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option24 = witTypes.None[string]()
+ case 1:
+ value23 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option24 = witTypes.Some[string](value23)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTransferCoding(option24)
+
+ case 32:
+ var option26 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option26 = witTypes.None[string]()
+ case 1:
+ value25 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option26 = witTypes.Some[string](value25)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseContentCoding(option26)
+
+ case 33:
+
+ variant = MakeErrorCodeHttpResponseTimeout()
+
+ case 34:
+
+ variant = MakeErrorCodeHttpUpgradeFailed()
+
+ case 35:
+
+ variant = MakeErrorCodeHttpProtocolError()
+
+ case 36:
+
+ variant = MakeErrorCodeLoopDetected()
+
+ case 37:
+
+ variant = MakeErrorCodeConfigurationError()
+
+ case 38:
+ var option28 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option28 = witTypes.None[string]()
+ case 1:
+ value27 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option28 = witTypes.Some[string](value27)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeInternalError(option28)
+
+ default:
+ panic("unreachable")
+ }
+
+ option29 = witTypes.Some[ErrorCode](variant)
+ default:
+ panic("unreachable")
+ }
+ result := option29
+ return result
+
+}
diff --git a/imports/wasi_http_0_3_0_client/empty.s b/imports/wasi_http_0_3_0_client/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_http_0_3_0_client/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_http_0_3_0_client/wit_bindings.go b/imports/wasi_http_0_3_0_client/wit_bindings.go
new file mode 100644
index 0000000..f016a5d
--- /dev/null
+++ b/imports/wasi_http_0_3_0_client/wit_bindings.go
@@ -0,0 +1,473 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_http_0_3_0_client
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_http_0_3_0_types"
+ witAsync "go.bytecodealliance.org/pkg/wit/async"
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+type Request = wasi_http_0_3_0_types.Request
+type Response = wasi_http_0_3_0_types.Response
+type ErrorCode = wasi_http_0_3_0_types.ErrorCode
+
+//go:wasmimport wasi:http/client@0.3.0 [async-lower]send
+func wasm_import_send(arg0 int32, arg1 uintptr) int32
+
+func Send(request *wasi_http_0_3_0_types.Request) witTypes.Result[*wasi_http_0_3_0_types.Response, wasi_http_0_3_0_types.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (24 + 4*4), 8))
+
+ witAsync.SubtaskWait(uint32(wasm_import_send((request).TakeHandle(), returnArea)))
+ var result witTypes.Result[*wasi_http_0_3_0_types.Response, wasi_http_0_3_0_types.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*wasi_http_0_3_0_types.Response, wasi_http_0_3_0_types.ErrorCode](wasi_http_0_3_0_types.ResponseFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))))
+ case 1:
+ var variant wasi_http_0_3_0_types.ErrorCode
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) {
+ case 0:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeDnsTimeout()
+
+ case 1:
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+ var option0 witTypes.Option[uint16]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option0 = witTypes.None[uint16]()
+ case 1:
+
+ option0 = witTypes.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (18 + 3*4))))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeDnsError(wasi_http_0_3_0_types.DnsErrorPayload{option, option0})
+
+ case 2:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeDestinationNotFound()
+
+ case 3:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeDestinationUnavailable()
+
+ case 4:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeDestinationIpProhibited()
+
+ case 5:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeDestinationIpUnroutable()
+
+ case 6:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeConnectionRefused()
+
+ case 7:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeConnectionTerminated()
+
+ case 8:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeConnectionTimeout()
+
+ case 9:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeConnectionReadTimeout()
+
+ case 10:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeConnectionWriteTimeout()
+
+ case 11:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeConnectionLimitReached()
+
+ case 12:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeTlsProtocolError()
+
+ case 13:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeTlsCertificateError()
+
+ case 14:
+ var option1 witTypes.Option[uint8]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option1 = witTypes.None[uint8]()
+ case 1:
+
+ option1 = witTypes.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 17)))))
+ default:
+ panic("unreachable")
+ }
+ var option3 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) {
+ case 0:
+
+ option3 = witTypes.None[string]()
+ case 1:
+ value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4))))
+
+ option3 = witTypes.Some[string](value2)
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeTlsAlertReceived(wasi_http_0_3_0_types.TlsAlertReceivedPayload{option1, option3})
+
+ case 15:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpRequestDenied()
+
+ case 16:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpRequestLengthRequired()
+
+ case 17:
+ var option4 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option4 = witTypes.None[uint64]()
+ case 1:
+
+ option4 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpRequestBodySize(option4)
+
+ case 18:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpRequestMethodInvalid()
+
+ case 19:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpRequestUriInvalid()
+
+ case 20:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpRequestUriTooLong()
+
+ case 21:
+ var option5 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option5 = witTypes.None[uint32]()
+ case 1:
+
+ option5 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpRequestHeaderSectionSize(option5)
+
+ case 22:
+ var option9 witTypes.Option[wasi_http_0_3_0_types.FieldSizePayload]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option9 = witTypes.None[wasi_http_0_3_0_types.FieldSizePayload]()
+ case 1:
+ var option7 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) {
+ case 0:
+
+ option7 = witTypes.None[string]()
+ case 1:
+ value6 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4))))
+
+ option7 = witTypes.Some[string](value6)
+ default:
+ panic("unreachable")
+ }
+ var option8 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 4*4)))) {
+ case 0:
+
+ option8 = witTypes.None[uint32]()
+ case 1:
+
+ option8 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 4*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ option9 = witTypes.Some[wasi_http_0_3_0_types.FieldSizePayload](wasi_http_0_3_0_types.FieldSizePayload{option7, option8})
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpRequestHeaderSize(option9)
+
+ case 23:
+ var option10 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option10 = witTypes.None[uint32]()
+ case 1:
+
+ option10 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpRequestTrailerSectionSize(option10)
+
+ case 24:
+ var option12 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option12 = witTypes.None[string]()
+ case 1:
+ value11 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option12 = witTypes.Some[string](value11)
+ default:
+ panic("unreachable")
+ }
+ var option13 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option13 = witTypes.None[uint32]()
+ case 1:
+
+ option13 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpRequestTrailerSize(wasi_http_0_3_0_types.FieldSizePayload{option12, option13})
+
+ case 25:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpResponseIncomplete()
+
+ case 26:
+ var option14 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option14 = witTypes.None[uint32]()
+ case 1:
+
+ option14 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpResponseHeaderSectionSize(option14)
+
+ case 27:
+ var option16 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option16 = witTypes.None[string]()
+ case 1:
+ value15 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option16 = witTypes.Some[string](value15)
+ default:
+ panic("unreachable")
+ }
+ var option17 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option17 = witTypes.None[uint32]()
+ case 1:
+
+ option17 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpResponseHeaderSize(wasi_http_0_3_0_types.FieldSizePayload{option16, option17})
+
+ case 28:
+ var option18 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option18 = witTypes.None[uint64]()
+ case 1:
+
+ option18 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpResponseBodySize(option18)
+
+ case 29:
+ var option19 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option19 = witTypes.None[uint32]()
+ case 1:
+
+ option19 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpResponseTrailerSectionSize(option19)
+
+ case 30:
+ var option21 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option21 = witTypes.None[string]()
+ case 1:
+ value20 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option21 = witTypes.Some[string](value20)
+ default:
+ panic("unreachable")
+ }
+ var option22 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) {
+ case 0:
+
+ option22 = witTypes.None[uint32]()
+ case 1:
+
+ option22 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpResponseTrailerSize(wasi_http_0_3_0_types.FieldSizePayload{option21, option22})
+
+ case 31:
+ var option24 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option24 = witTypes.None[string]()
+ case 1:
+ value23 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option24 = witTypes.Some[string](value23)
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpResponseTransferCoding(option24)
+
+ case 32:
+ var option26 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option26 = witTypes.None[string]()
+ case 1:
+ value25 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option26 = witTypes.Some[string](value25)
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpResponseContentCoding(option26)
+
+ case 33:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpResponseTimeout()
+
+ case 34:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpUpgradeFailed()
+
+ case 35:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeHttpProtocolError()
+
+ case 36:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeLoopDetected()
+
+ case 37:
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeConfigurationError()
+
+ case 38:
+ var option28 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) {
+ case 0:
+
+ option28 = witTypes.None[string]()
+ case 1:
+ value27 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4))))
+
+ option28 = witTypes.Some[string](value27)
+ default:
+ panic("unreachable")
+ }
+
+ variant = wasi_http_0_3_0_types.MakeErrorCodeInternalError(option28)
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[*wasi_http_0_3_0_types.Response, wasi_http_0_3_0_types.ErrorCode](variant)
+ default:
+ panic("unreachable")
+ }
+
+ return result
+
+}
diff --git a/imports/wasi_http_0_3_0_handler/empty.s b/imports/wasi_http_0_3_0_handler/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_http_0_3_0_handler/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_http_0_3_0_handler/wit_bindings.go b/imports/wasi_http_0_3_0_handler/wit_bindings.go
new file mode 100644
index 0000000..81e0c2f
--- /dev/null
+++ b/imports/wasi_http_0_3_0_handler/wit_bindings.go
@@ -0,0 +1,30 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_http_0_3_0_handler
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_http_0_3_0_types"
+)
+
+type Request = wasi_http_0_3_0_types.Request
+type Response = wasi_http_0_3_0_types.Response
+type ErrorCode = wasi_http_0_3_0_types.ErrorCode
diff --git a/imports/wasi_http_0_3_0_types/empty.s b/imports/wasi_http_0_3_0_types/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_http_0_3_0_types/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_http_0_3_0_types/wit_bindings.go b/imports/wasi_http_0_3_0_types/wit_bindings.go
new file mode 100644
index 0000000..21ddcd2
--- /dev/null
+++ b/imports/wasi_http_0_3_0_types/wit_bindings.go
@@ -0,0 +1,4051 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_http_0_3_0_types
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+//go:wasmimport wasi:http/types@0.3.0 [stream-new-0][static]request.new
+func wasm_stream_new_u8() uint64
+
+//go:wasmimport wasi:http/types@0.3.0 [async-lower][stream-read-0][static]request.new
+func wasm_stream_read_u8(handle int32, item unsafe.Pointer, count uint32) uint32
+
+//go:wasmimport wasi:http/types@0.3.0 [async-lower][stream-write-0][static]request.new
+func wasm_stream_write_u8(handle int32, item unsafe.Pointer, count uint32) uint32
+
+//go:wasmimport wasi:http/types@0.3.0 [stream-drop-readable-0][static]request.new
+func wasm_stream_drop_readable_u8(handle int32)
+
+//go:wasmimport wasi:http/types@0.3.0 [stream-drop-writable-0][static]request.new
+func wasm_stream_drop_writable_u8(handle int32)
+
+var wasm_stream_vtable_u8 = witTypes.StreamVtable[uint8]{
+ 1,
+ 1,
+ wasm_stream_read_u8,
+ wasm_stream_write_u8,
+ nil,
+ nil,
+ wasm_stream_drop_readable_u8,
+ wasm_stream_drop_writable_u8,
+ nil,
+ nil,
+}
+
+func MakeStreamU8() (*witTypes.StreamWriter[uint8], *witTypes.StreamReader[uint8]) {
+ pair := wasm_stream_new_u8()
+ return witTypes.MakeStreamWriter[uint8](&wasm_stream_vtable_u8, int32(pair>>32)),
+ witTypes.MakeStreamReader[uint8](&wasm_stream_vtable_u8, int32(pair&0xFFFFFFFF))
+}
+
+func LiftStreamU8(handle int32) *witTypes.StreamReader[uint8] {
+ return witTypes.MakeStreamReader[uint8](&wasm_stream_vtable_u8, handle)
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [future-new-1][static]request.new
+func wasm_future_new_result_option_fields_error_code() uint64
+
+//go:wasmimport wasi:http/types@0.3.0 [async-lower][future-read-1][static]request.new
+func wasm_future_read_result_option_fields_error_code(handle int32, item unsafe.Pointer) uint32
+
+//go:wasmimport wasi:http/types@0.3.0 [async-lower][future-write-1][static]request.new
+func wasm_future_write_result_option_fields_error_code(handle int32, item unsafe.Pointer) uint32
+
+//go:wasmimport wasi:http/types@0.3.0 [future-drop-readable-1][static]request.new
+func wasm_future_drop_readable_result_option_fields_error_code(handle int32)
+
+//go:wasmimport wasi:http/types@0.3.0 [future-drop-writable-1][static]request.new
+func wasm_future_drop_writable_result_option_fields_error_code(handle int32)
+
+func wasm_future_lift_result_option_fields_error_code(src unsafe.Pointer) witTypes.Result[witTypes.Option[*Fields], ErrorCode] {
+ var result witTypes.Result[witTypes.Option[*Fields], ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 0))) {
+ case 0:
+ var option witTypes.Option[*Fields]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 8))) {
+ case 0:
+
+ option = witTypes.None[*Fields]()
+ case 1:
+
+ option = witTypes.Some[*Fields](FieldsFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(src), 12))))))
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Ok[witTypes.Option[*Fields], ErrorCode](option)
+ case 1:
+ var variant ErrorCode
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 8))) {
+ case 0:
+
+ variant = MakeErrorCodeDnsTimeout()
+
+ case 1:
+ var option0 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option0 = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4))))
+
+ option0 = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+ var option1 witTypes.Option[uint16]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 3*4)))) {
+ case 0:
+
+ option1 = witTypes.None[uint16]()
+ case 1:
+
+ option1 = witTypes.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (18 + 3*4))))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeDnsError(DnsErrorPayload{option0, option1})
+
+ case 2:
+
+ variant = MakeErrorCodeDestinationNotFound()
+
+ case 3:
+
+ variant = MakeErrorCodeDestinationUnavailable()
+
+ case 4:
+
+ variant = MakeErrorCodeDestinationIpProhibited()
+
+ case 5:
+
+ variant = MakeErrorCodeDestinationIpUnroutable()
+
+ case 6:
+
+ variant = MakeErrorCodeConnectionRefused()
+
+ case 7:
+
+ variant = MakeErrorCodeConnectionTerminated()
+
+ case 8:
+
+ variant = MakeErrorCodeConnectionTimeout()
+
+ case 9:
+
+ variant = MakeErrorCodeConnectionReadTimeout()
+
+ case 10:
+
+ variant = MakeErrorCodeConnectionWriteTimeout()
+
+ case 11:
+
+ variant = MakeErrorCodeConnectionLimitReached()
+
+ case 12:
+
+ variant = MakeErrorCodeTlsProtocolError()
+
+ case 13:
+
+ variant = MakeErrorCodeTlsCertificateError()
+
+ case 14:
+ var option2 witTypes.Option[uint8]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option2 = witTypes.None[uint8]()
+ case 1:
+
+ option2 = witTypes.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 17)))))
+ default:
+ panic("unreachable")
+ }
+ var option4 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))) {
+ case 0:
+
+ option4 = witTypes.None[string]()
+ case 1:
+ value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 3*4))))
+
+ option4 = witTypes.Some[string](value3)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeTlsAlertReceived(TlsAlertReceivedPayload{option2, option4})
+
+ case 15:
+
+ variant = MakeErrorCodeHttpRequestDenied()
+
+ case 16:
+
+ variant = MakeErrorCodeHttpRequestLengthRequired()
+
+ case 17:
+ var option5 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option5 = witTypes.None[uint64]()
+ case 1:
+
+ option5 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(src), 24))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestBodySize(option5)
+
+ case 18:
+
+ variant = MakeErrorCodeHttpRequestMethodInvalid()
+
+ case 19:
+
+ variant = MakeErrorCodeHttpRequestUriInvalid()
+
+ case 20:
+
+ variant = MakeErrorCodeHttpRequestUriTooLong()
+
+ case 21:
+ var option6 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option6 = witTypes.None[uint32]()
+ case 1:
+
+ option6 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestHeaderSectionSize(option6)
+
+ case 22:
+ var option10 witTypes.Option[FieldSizePayload]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option10 = witTypes.None[FieldSizePayload]()
+ case 1:
+ var option8 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))) {
+ case 0:
+
+ option8 = witTypes.None[string]()
+ case 1:
+ value7 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 3*4))))
+
+ option8 = witTypes.Some[string](value7)
+ default:
+ panic("unreachable")
+ }
+ var option9 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 4*4)))) {
+ case 0:
+
+ option9 = witTypes.None[uint32]()
+ case 1:
+
+ option9 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), (20 + 4*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ option10 = witTypes.Some[FieldSizePayload](FieldSizePayload{option8, option9})
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestHeaderSize(option10)
+
+ case 23:
+ var option11 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option11 = witTypes.None[uint32]()
+ case 1:
+
+ option11 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestTrailerSectionSize(option11)
+
+ case 24:
+ var option13 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option13 = witTypes.None[string]()
+ case 1:
+ value12 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4))))
+
+ option13 = witTypes.Some[string](value12)
+ default:
+ panic("unreachable")
+ }
+ var option14 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 3*4)))) {
+ case 0:
+
+ option14 = witTypes.None[uint32]()
+ case 1:
+
+ option14 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestTrailerSize(FieldSizePayload{option13, option14})
+
+ case 25:
+
+ variant = MakeErrorCodeHttpResponseIncomplete()
+
+ case 26:
+ var option15 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option15 = witTypes.None[uint32]()
+ case 1:
+
+ option15 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseHeaderSectionSize(option15)
+
+ case 27:
+ var option17 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option17 = witTypes.None[string]()
+ case 1:
+ value16 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4))))
+
+ option17 = witTypes.Some[string](value16)
+ default:
+ panic("unreachable")
+ }
+ var option18 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 3*4)))) {
+ case 0:
+
+ option18 = witTypes.None[uint32]()
+ case 1:
+
+ option18 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseHeaderSize(FieldSizePayload{option17, option18})
+
+ case 28:
+ var option19 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option19 = witTypes.None[uint64]()
+ case 1:
+
+ option19 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(src), 24))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseBodySize(option19)
+
+ case 29:
+ var option20 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option20 = witTypes.None[uint32]()
+ case 1:
+
+ option20 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTrailerSectionSize(option20)
+
+ case 30:
+ var option22 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option22 = witTypes.None[string]()
+ case 1:
+ value21 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4))))
+
+ option22 = witTypes.Some[string](value21)
+ default:
+ panic("unreachable")
+ }
+ var option23 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 3*4)))) {
+ case 0:
+
+ option23 = witTypes.None[uint32]()
+ case 1:
+
+ option23 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTrailerSize(FieldSizePayload{option22, option23})
+
+ case 31:
+ var option25 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option25 = witTypes.None[string]()
+ case 1:
+ value24 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4))))
+
+ option25 = witTypes.Some[string](value24)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTransferCoding(option25)
+
+ case 32:
+ var option27 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option27 = witTypes.None[string]()
+ case 1:
+ value26 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4))))
+
+ option27 = witTypes.Some[string](value26)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseContentCoding(option27)
+
+ case 33:
+
+ variant = MakeErrorCodeHttpResponseTimeout()
+
+ case 34:
+
+ variant = MakeErrorCodeHttpUpgradeFailed()
+
+ case 35:
+
+ variant = MakeErrorCodeHttpProtocolError()
+
+ case 36:
+
+ variant = MakeErrorCodeLoopDetected()
+
+ case 37:
+
+ variant = MakeErrorCodeConfigurationError()
+
+ case 38:
+ var option29 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option29 = witTypes.None[string]()
+ case 1:
+ value28 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4))))
+
+ option29 = witTypes.Some[string](value28)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeInternalError(option29)
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Option[*Fields], ErrorCode](variant)
+ default:
+ panic("unreachable")
+ }
+
+ return result
+}
+
+func wasm_future_lower_result_option_fields_error_code(
+ pinner *runtime.Pinner,
+ value witTypes.Result[witTypes.Option[*Fields], ErrorCode],
+ dst unsafe.Pointer,
+) func() {
+ lifters := make([]func(), 0, 1)
+
+ switch value.Tag() {
+ case witTypes.ResultOk:
+ payload := value.Ok()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 0)) = int8(int32(0))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(1))
+ resource := payload
+ handle := resource.TakeHandle()
+ lifters = append(lifters, func() {
+ resource.SetHandle(handle)
+ })
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), 12)) = handle
+
+ default:
+ panic("unreachable")
+ }
+
+ case witTypes.ResultErr:
+ payload := value.Err()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 0)) = int8(int32(1))
+
+ switch payload.Tag() {
+ case ErrorCodeDnsTimeout:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(0))
+
+ case ErrorCodeDnsError:
+ payload := payload.DnsError()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(1))
+
+ switch (payload).Rcode.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).Rcode.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ utf8 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf8)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = uint32(uintptr(uintptr(utf8)))
+
+ default:
+ panic("unreachable")
+ }
+
+ switch (payload).InfoCode.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).InfoCode.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(1))
+ *(*int16)(unsafe.Add(unsafe.Pointer(dst), (18 + 3*4))) = int16(int32(payload))
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeDestinationNotFound:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(2))
+
+ case ErrorCodeDestinationUnavailable:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(3))
+
+ case ErrorCodeDestinationIpProhibited:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(4))
+
+ case ErrorCodeDestinationIpUnroutable:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(5))
+
+ case ErrorCodeConnectionRefused:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(6))
+
+ case ErrorCodeConnectionTerminated:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(7))
+
+ case ErrorCodeConnectionTimeout:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(8))
+
+ case ErrorCodeConnectionReadTimeout:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(9))
+
+ case ErrorCodeConnectionWriteTimeout:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(10))
+
+ case ErrorCodeConnectionLimitReached:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(11))
+
+ case ErrorCodeTlsProtocolError:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(12))
+
+ case ErrorCodeTlsCertificateError:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(13))
+
+ case ErrorCodeTlsAlertReceived:
+ payload := payload.TlsAlertReceived()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(14))
+
+ switch (payload).AlertId.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).AlertId.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 17)) = int8(int32(payload))
+
+ default:
+ panic("unreachable")
+ }
+
+ switch (payload).AlertMessage.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).AlertMessage.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = int8(int32(1))
+ utf830 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf830)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uintptr(uintptr(utf830)))
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpRequestDenied:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(15))
+
+ case ErrorCodeHttpRequestLengthRequired:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(16))
+
+ case ErrorCodeHttpRequestBodySize:
+ payload := payload.HttpRequestBodySize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(17))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ *(*int64)(unsafe.Add(unsafe.Pointer(dst), 24)) = int64(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpRequestMethodInvalid:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(18))
+
+ case ErrorCodeHttpRequestUriInvalid:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(19))
+
+ case ErrorCodeHttpRequestUriTooLong:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(20))
+
+ case ErrorCodeHttpRequestHeaderSectionSize:
+ payload := payload.HttpRequestHeaderSectionSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(21))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), 20)) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpRequestHeaderSize:
+ payload := payload.HttpRequestHeaderSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(22))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+
+ switch (payload).FieldName.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldName.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = int8(int32(1))
+ utf831 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf831)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uintptr(uintptr(utf831)))
+
+ default:
+ panic("unreachable")
+ }
+
+ switch (payload).FieldSize.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 4*4))) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldSize.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 4*4))) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), (20 + 4*4))) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpRequestTrailerSectionSize:
+ payload := payload.HttpRequestTrailerSectionSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(23))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), 20)) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpRequestTrailerSize:
+ payload := payload.HttpRequestTrailerSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(24))
+
+ switch (payload).FieldName.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldName.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ utf832 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf832)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = uint32(uintptr(uintptr(utf832)))
+
+ default:
+ panic("unreachable")
+ }
+
+ switch (payload).FieldSize.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldSize.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), (20 + 3*4))) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseIncomplete:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(25))
+
+ case ErrorCodeHttpResponseHeaderSectionSize:
+ payload := payload.HttpResponseHeaderSectionSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(26))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), 20)) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseHeaderSize:
+ payload := payload.HttpResponseHeaderSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(27))
+
+ switch (payload).FieldName.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldName.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ utf833 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf833)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = uint32(uintptr(uintptr(utf833)))
+
+ default:
+ panic("unreachable")
+ }
+
+ switch (payload).FieldSize.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldSize.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), (20 + 3*4))) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseBodySize:
+ payload := payload.HttpResponseBodySize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(28))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ *(*int64)(unsafe.Add(unsafe.Pointer(dst), 24)) = int64(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseTrailerSectionSize:
+ payload := payload.HttpResponseTrailerSectionSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(29))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), 20)) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseTrailerSize:
+ payload := payload.HttpResponseTrailerSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(30))
+
+ switch (payload).FieldName.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldName.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ utf834 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf834)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = uint32(uintptr(uintptr(utf834)))
+
+ default:
+ panic("unreachable")
+ }
+
+ switch (payload).FieldSize.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldSize.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), (20 + 3*4))) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseTransferCoding:
+ payload := payload.HttpResponseTransferCoding()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(31))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ utf835 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf835)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = uint32(uintptr(uintptr(utf835)))
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseContentCoding:
+ payload := payload.HttpResponseContentCoding()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(32))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ utf836 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf836)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = uint32(uintptr(uintptr(utf836)))
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseTimeout:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(33))
+
+ case ErrorCodeHttpUpgradeFailed:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(34))
+
+ case ErrorCodeHttpProtocolError:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(35))
+
+ case ErrorCodeLoopDetected:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(36))
+
+ case ErrorCodeConfigurationError:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(37))
+
+ case ErrorCodeInternalError:
+ payload := payload.InternalError()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(38))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ utf837 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf837)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = uint32(uintptr(uintptr(utf837)))
+
+ default:
+ panic("unreachable")
+ }
+
+ default:
+ panic("unreachable")
+ }
+
+ default:
+ panic("unreachable")
+ }
+
+ return func() {
+ for _, lifter := range lifters {
+ lifter()
+ }
+ }
+}
+
+var wasm_future_vtable_result_option_fields_error_code = witTypes.FutureVtable[witTypes.Result[witTypes.Option[*Fields], ErrorCode]]{
+ (24 + 4*4),
+ 8,
+ wasm_future_read_result_option_fields_error_code,
+ wasm_future_write_result_option_fields_error_code,
+ nil,
+ nil,
+ wasm_future_drop_readable_result_option_fields_error_code,
+ wasm_future_drop_writable_result_option_fields_error_code,
+ wasm_future_lift_result_option_fields_error_code,
+ wasm_future_lower_result_option_fields_error_code,
+}
+
+func MakeFutureResultOptionFieldsErrorCode() (*witTypes.FutureWriter[witTypes.Result[witTypes.Option[*Fields], ErrorCode]], *witTypes.FutureReader[witTypes.Result[witTypes.Option[*Fields], ErrorCode]]) {
+ pair := wasm_future_new_result_option_fields_error_code()
+ return witTypes.MakeFutureWriter[witTypes.Result[witTypes.Option[*Fields], ErrorCode]](&wasm_future_vtable_result_option_fields_error_code, int32(pair>>32)),
+ witTypes.MakeFutureReader[witTypes.Result[witTypes.Option[*Fields], ErrorCode]](&wasm_future_vtable_result_option_fields_error_code, int32(pair&0xFFFFFFFF))
+}
+
+func LiftFutureResultOptionFieldsErrorCode(handle int32) *witTypes.FutureReader[witTypes.Result[witTypes.Option[*Fields], ErrorCode]] {
+ return witTypes.MakeFutureReader[witTypes.Result[witTypes.Option[*Fields], ErrorCode]](&wasm_future_vtable_result_option_fields_error_code, handle)
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [future-new-2][static]request.new
+func wasm_future_new_result_unit_error_code() uint64
+
+//go:wasmimport wasi:http/types@0.3.0 [async-lower][future-read-2][static]request.new
+func wasm_future_read_result_unit_error_code(handle int32, item unsafe.Pointer) uint32
+
+//go:wasmimport wasi:http/types@0.3.0 [async-lower][future-write-2][static]request.new
+func wasm_future_write_result_unit_error_code(handle int32, item unsafe.Pointer) uint32
+
+//go:wasmimport wasi:http/types@0.3.0 [future-drop-readable-2][static]request.new
+func wasm_future_drop_readable_result_unit_error_code(handle int32)
+
+//go:wasmimport wasi:http/types@0.3.0 [future-drop-writable-2][static]request.new
+func wasm_future_drop_writable_result_unit_error_code(handle int32)
+
+func wasm_future_lift_result_unit_error_code(src unsafe.Pointer) witTypes.Result[witTypes.Unit, ErrorCode] {
+ var result witTypes.Result[witTypes.Unit, ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{})
+ case 1:
+ var variant ErrorCode
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 8))) {
+ case 0:
+
+ variant = MakeErrorCodeDnsTimeout()
+
+ case 1:
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4))))
+
+ option = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+ var option0 witTypes.Option[uint16]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 3*4)))) {
+ case 0:
+
+ option0 = witTypes.None[uint16]()
+ case 1:
+
+ option0 = witTypes.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (18 + 3*4))))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeDnsError(DnsErrorPayload{option, option0})
+
+ case 2:
+
+ variant = MakeErrorCodeDestinationNotFound()
+
+ case 3:
+
+ variant = MakeErrorCodeDestinationUnavailable()
+
+ case 4:
+
+ variant = MakeErrorCodeDestinationIpProhibited()
+
+ case 5:
+
+ variant = MakeErrorCodeDestinationIpUnroutable()
+
+ case 6:
+
+ variant = MakeErrorCodeConnectionRefused()
+
+ case 7:
+
+ variant = MakeErrorCodeConnectionTerminated()
+
+ case 8:
+
+ variant = MakeErrorCodeConnectionTimeout()
+
+ case 9:
+
+ variant = MakeErrorCodeConnectionReadTimeout()
+
+ case 10:
+
+ variant = MakeErrorCodeConnectionWriteTimeout()
+
+ case 11:
+
+ variant = MakeErrorCodeConnectionLimitReached()
+
+ case 12:
+
+ variant = MakeErrorCodeTlsProtocolError()
+
+ case 13:
+
+ variant = MakeErrorCodeTlsCertificateError()
+
+ case 14:
+ var option1 witTypes.Option[uint8]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option1 = witTypes.None[uint8]()
+ case 1:
+
+ option1 = witTypes.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 17)))))
+ default:
+ panic("unreachable")
+ }
+ var option3 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))) {
+ case 0:
+
+ option3 = witTypes.None[string]()
+ case 1:
+ value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 3*4))))
+
+ option3 = witTypes.Some[string](value2)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeTlsAlertReceived(TlsAlertReceivedPayload{option1, option3})
+
+ case 15:
+
+ variant = MakeErrorCodeHttpRequestDenied()
+
+ case 16:
+
+ variant = MakeErrorCodeHttpRequestLengthRequired()
+
+ case 17:
+ var option4 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option4 = witTypes.None[uint64]()
+ case 1:
+
+ option4 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(src), 24))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestBodySize(option4)
+
+ case 18:
+
+ variant = MakeErrorCodeHttpRequestMethodInvalid()
+
+ case 19:
+
+ variant = MakeErrorCodeHttpRequestUriInvalid()
+
+ case 20:
+
+ variant = MakeErrorCodeHttpRequestUriTooLong()
+
+ case 21:
+ var option5 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option5 = witTypes.None[uint32]()
+ case 1:
+
+ option5 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestHeaderSectionSize(option5)
+
+ case 22:
+ var option9 witTypes.Option[FieldSizePayload]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option9 = witTypes.None[FieldSizePayload]()
+ case 1:
+ var option7 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))) {
+ case 0:
+
+ option7 = witTypes.None[string]()
+ case 1:
+ value6 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 3*4))))
+
+ option7 = witTypes.Some[string](value6)
+ default:
+ panic("unreachable")
+ }
+ var option8 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 4*4)))) {
+ case 0:
+
+ option8 = witTypes.None[uint32]()
+ case 1:
+
+ option8 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), (20 + 4*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ option9 = witTypes.Some[FieldSizePayload](FieldSizePayload{option7, option8})
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestHeaderSize(option9)
+
+ case 23:
+ var option10 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option10 = witTypes.None[uint32]()
+ case 1:
+
+ option10 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestTrailerSectionSize(option10)
+
+ case 24:
+ var option12 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option12 = witTypes.None[string]()
+ case 1:
+ value11 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4))))
+
+ option12 = witTypes.Some[string](value11)
+ default:
+ panic("unreachable")
+ }
+ var option13 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 3*4)))) {
+ case 0:
+
+ option13 = witTypes.None[uint32]()
+ case 1:
+
+ option13 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpRequestTrailerSize(FieldSizePayload{option12, option13})
+
+ case 25:
+
+ variant = MakeErrorCodeHttpResponseIncomplete()
+
+ case 26:
+ var option14 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option14 = witTypes.None[uint32]()
+ case 1:
+
+ option14 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseHeaderSectionSize(option14)
+
+ case 27:
+ var option16 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option16 = witTypes.None[string]()
+ case 1:
+ value15 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4))))
+
+ option16 = witTypes.Some[string](value15)
+ default:
+ panic("unreachable")
+ }
+ var option17 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 3*4)))) {
+ case 0:
+
+ option17 = witTypes.None[uint32]()
+ case 1:
+
+ option17 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseHeaderSize(FieldSizePayload{option16, option17})
+
+ case 28:
+ var option18 witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option18 = witTypes.None[uint64]()
+ case 1:
+
+ option18 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(src), 24))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseBodySize(option18)
+
+ case 29:
+ var option19 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option19 = witTypes.None[uint32]()
+ case 1:
+
+ option19 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), 20))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTrailerSectionSize(option19)
+
+ case 30:
+ var option21 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option21 = witTypes.None[string]()
+ case 1:
+ value20 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4))))
+
+ option21 = witTypes.Some[string](value20)
+ default:
+ panic("unreachable")
+ }
+ var option22 witTypes.Option[uint32]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 3*4)))) {
+ case 0:
+
+ option22 = witTypes.None[uint32]()
+ case 1:
+
+ option22 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(src), (20 + 3*4)))))
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTrailerSize(FieldSizePayload{option21, option22})
+
+ case 31:
+ var option24 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option24 = witTypes.None[string]()
+ case 1:
+ value23 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4))))
+
+ option24 = witTypes.Some[string](value23)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseTransferCoding(option24)
+
+ case 32:
+ var option26 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option26 = witTypes.None[string]()
+ case 1:
+ value25 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4))))
+
+ option26 = witTypes.Some[string](value25)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeHttpResponseContentCoding(option26)
+
+ case 33:
+
+ variant = MakeErrorCodeHttpResponseTimeout()
+
+ case 34:
+
+ variant = MakeErrorCodeHttpUpgradeFailed()
+
+ case 35:
+
+ variant = MakeErrorCodeHttpProtocolError()
+
+ case 36:
+
+ variant = MakeErrorCodeLoopDetected()
+
+ case 37:
+
+ variant = MakeErrorCodeConfigurationError()
+
+ case 38:
+ var option28 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(src), 16))) {
+ case 0:
+
+ option28 = witTypes.None[string]()
+ case 1:
+ value27 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(src), (16 + 2*4))))
+
+ option28 = witTypes.Some[string](value27)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeErrorCodeInternalError(option28)
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Unit, ErrorCode](variant)
+ default:
+ panic("unreachable")
+ }
+
+ return result
+}
+
+func wasm_future_lower_result_unit_error_code(
+ pinner *runtime.Pinner,
+ value witTypes.Result[witTypes.Unit, ErrorCode],
+ dst unsafe.Pointer,
+) func() {
+
+ switch value.Tag() {
+ case witTypes.ResultOk:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 0)) = int8(int32(0))
+
+ case witTypes.ResultErr:
+ payload := value.Err()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 0)) = int8(int32(1))
+
+ switch payload.Tag() {
+ case ErrorCodeDnsTimeout:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(0))
+
+ case ErrorCodeDnsError:
+ payload := payload.DnsError()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(1))
+
+ switch (payload).Rcode.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).Rcode.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ utf8 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf8)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = uint32(uintptr(uintptr(utf8)))
+
+ default:
+ panic("unreachable")
+ }
+
+ switch (payload).InfoCode.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).InfoCode.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(1))
+ *(*int16)(unsafe.Add(unsafe.Pointer(dst), (18 + 3*4))) = int16(int32(payload))
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeDestinationNotFound:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(2))
+
+ case ErrorCodeDestinationUnavailable:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(3))
+
+ case ErrorCodeDestinationIpProhibited:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(4))
+
+ case ErrorCodeDestinationIpUnroutable:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(5))
+
+ case ErrorCodeConnectionRefused:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(6))
+
+ case ErrorCodeConnectionTerminated:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(7))
+
+ case ErrorCodeConnectionTimeout:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(8))
+
+ case ErrorCodeConnectionReadTimeout:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(9))
+
+ case ErrorCodeConnectionWriteTimeout:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(10))
+
+ case ErrorCodeConnectionLimitReached:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(11))
+
+ case ErrorCodeTlsProtocolError:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(12))
+
+ case ErrorCodeTlsCertificateError:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(13))
+
+ case ErrorCodeTlsAlertReceived:
+ payload := payload.TlsAlertReceived()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(14))
+
+ switch (payload).AlertId.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).AlertId.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 17)) = int8(int32(payload))
+
+ default:
+ panic("unreachable")
+ }
+
+ switch (payload).AlertMessage.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).AlertMessage.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = int8(int32(1))
+ utf829 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf829)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uintptr(uintptr(utf829)))
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpRequestDenied:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(15))
+
+ case ErrorCodeHttpRequestLengthRequired:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(16))
+
+ case ErrorCodeHttpRequestBodySize:
+ payload := payload.HttpRequestBodySize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(17))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ *(*int64)(unsafe.Add(unsafe.Pointer(dst), 24)) = int64(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpRequestMethodInvalid:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(18))
+
+ case ErrorCodeHttpRequestUriInvalid:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(19))
+
+ case ErrorCodeHttpRequestUriTooLong:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(20))
+
+ case ErrorCodeHttpRequestHeaderSectionSize:
+ payload := payload.HttpRequestHeaderSectionSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(21))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), 20)) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpRequestHeaderSize:
+ payload := payload.HttpRequestHeaderSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(22))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+
+ switch (payload).FieldName.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldName.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = int8(int32(1))
+ utf830 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf830)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uintptr(uintptr(utf830)))
+
+ default:
+ panic("unreachable")
+ }
+
+ switch (payload).FieldSize.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 4*4))) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldSize.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 4*4))) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), (20 + 4*4))) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpRequestTrailerSectionSize:
+ payload := payload.HttpRequestTrailerSectionSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(23))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), 20)) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpRequestTrailerSize:
+ payload := payload.HttpRequestTrailerSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(24))
+
+ switch (payload).FieldName.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldName.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ utf831 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf831)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = uint32(uintptr(uintptr(utf831)))
+
+ default:
+ panic("unreachable")
+ }
+
+ switch (payload).FieldSize.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldSize.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), (20 + 3*4))) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseIncomplete:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(25))
+
+ case ErrorCodeHttpResponseHeaderSectionSize:
+ payload := payload.HttpResponseHeaderSectionSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(26))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), 20)) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseHeaderSize:
+ payload := payload.HttpResponseHeaderSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(27))
+
+ switch (payload).FieldName.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldName.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ utf832 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf832)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = uint32(uintptr(uintptr(utf832)))
+
+ default:
+ panic("unreachable")
+ }
+
+ switch (payload).FieldSize.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldSize.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), (20 + 3*4))) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseBodySize:
+ payload := payload.HttpResponseBodySize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(28))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ *(*int64)(unsafe.Add(unsafe.Pointer(dst), 24)) = int64(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseTrailerSectionSize:
+ payload := payload.HttpResponseTrailerSectionSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(29))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), 20)) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseTrailerSize:
+ payload := payload.HttpResponseTrailerSize()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(30))
+
+ switch (payload).FieldName.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldName.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ utf833 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf833)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = uint32(uintptr(uintptr(utf833)))
+
+ default:
+ panic("unreachable")
+ }
+
+ switch (payload).FieldSize.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (payload).FieldSize.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), (16 + 3*4))) = int8(int32(1))
+ *(*int32)(unsafe.Add(unsafe.Pointer(dst), (20 + 3*4))) = int32(payload)
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseTransferCoding:
+ payload := payload.HttpResponseTransferCoding()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(31))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ utf834 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf834)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = uint32(uintptr(uintptr(utf834)))
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseContentCoding:
+ payload := payload.HttpResponseContentCoding()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(32))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ utf835 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf835)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = uint32(uintptr(uintptr(utf835)))
+
+ default:
+ panic("unreachable")
+ }
+
+ case ErrorCodeHttpResponseTimeout:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(33))
+
+ case ErrorCodeHttpUpgradeFailed:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(34))
+
+ case ErrorCodeHttpProtocolError:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(35))
+
+ case ErrorCodeLoopDetected:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(36))
+
+ case ErrorCodeConfigurationError:
+
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(37))
+
+ case ErrorCodeInternalError:
+ payload := payload.InternalError()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 8)) = int8(int32(38))
+
+ switch payload.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := payload.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(dst), 16)) = int8(int32(1))
+ utf836 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf836)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 2*4))) = uint32(uint32(len(payload)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(dst), (16 + 1*4))) = uint32(uintptr(uintptr(utf836)))
+
+ default:
+ panic("unreachable")
+ }
+
+ default:
+ panic("unreachable")
+ }
+
+ default:
+ panic("unreachable")
+ }
+
+ return func() {}
+}
+
+var wasm_future_vtable_result_unit_error_code = witTypes.FutureVtable[witTypes.Result[witTypes.Unit, ErrorCode]]{
+ (24 + 4*4),
+ 8,
+ wasm_future_read_result_unit_error_code,
+ wasm_future_write_result_unit_error_code,
+ nil,
+ nil,
+ wasm_future_drop_readable_result_unit_error_code,
+ wasm_future_drop_writable_result_unit_error_code,
+ wasm_future_lift_result_unit_error_code,
+ wasm_future_lower_result_unit_error_code,
+}
+
+func MakeFutureResultUnitErrorCode() (*witTypes.FutureWriter[witTypes.Result[witTypes.Unit, ErrorCode]], *witTypes.FutureReader[witTypes.Result[witTypes.Unit, ErrorCode]]) {
+ pair := wasm_future_new_result_unit_error_code()
+ return witTypes.MakeFutureWriter[witTypes.Result[witTypes.Unit, ErrorCode]](&wasm_future_vtable_result_unit_error_code, int32(pair>>32)),
+ witTypes.MakeFutureReader[witTypes.Result[witTypes.Unit, ErrorCode]](&wasm_future_vtable_result_unit_error_code, int32(pair&0xFFFFFFFF))
+}
+
+func LiftFutureResultUnitErrorCode(handle int32) *witTypes.FutureReader[witTypes.Result[witTypes.Unit, ErrorCode]] {
+ return witTypes.MakeFutureReader[witTypes.Result[witTypes.Unit, ErrorCode]](&wasm_future_vtable_result_unit_error_code, handle)
+}
+
+type Duration = uint64
+
+const (
+ MethodGet uint8 = 0
+ MethodHead uint8 = 1
+ MethodPost uint8 = 2
+ MethodPut uint8 = 3
+ MethodDelete uint8 = 4
+ MethodConnect uint8 = 5
+ MethodOptions uint8 = 6
+ MethodTrace uint8 = 7
+ MethodPatch uint8 = 8
+ MethodOther uint8 = 9
+)
+
+// This type corresponds to HTTP standard Methods.
+type Method struct {
+ tag uint8
+ value any
+}
+
+func (self Method) Tag() uint8 {
+ return self.tag
+}
+
+func (self Method) Other() string {
+ if self.tag != MethodOther {
+ panic("tag mismatch")
+ }
+ return self.value.(string)
+}
+
+func MakeMethodGet() Method {
+ return Method{MethodGet, nil}
+}
+func MakeMethodHead() Method {
+ return Method{MethodHead, nil}
+}
+func MakeMethodPost() Method {
+ return Method{MethodPost, nil}
+}
+func MakeMethodPut() Method {
+ return Method{MethodPut, nil}
+}
+func MakeMethodDelete() Method {
+ return Method{MethodDelete, nil}
+}
+func MakeMethodConnect() Method {
+ return Method{MethodConnect, nil}
+}
+func MakeMethodOptions() Method {
+ return Method{MethodOptions, nil}
+}
+func MakeMethodTrace() Method {
+ return Method{MethodTrace, nil}
+}
+func MakeMethodPatch() Method {
+ return Method{MethodPatch, nil}
+}
+func MakeMethodOther(value string) Method {
+ return Method{MethodOther, value}
+}
+
+const (
+ SchemeHttp uint8 = 0
+ SchemeHttps uint8 = 1
+ SchemeOther uint8 = 2
+)
+
+// This type corresponds to HTTP standard Related Schemes.
+type Scheme struct {
+ tag uint8
+ value any
+}
+
+func (self Scheme) Tag() uint8 {
+ return self.tag
+}
+
+func (self Scheme) Other() string {
+ if self.tag != SchemeOther {
+ panic("tag mismatch")
+ }
+ return self.value.(string)
+}
+
+func MakeSchemeHttp() Scheme {
+ return Scheme{SchemeHttp, nil}
+}
+func MakeSchemeHttps() Scheme {
+ return Scheme{SchemeHttps, nil}
+}
+func MakeSchemeOther(value string) Scheme {
+ return Scheme{SchemeOther, value}
+}
+
+// Defines the case payload type for `DNS-error` above:
+type DnsErrorPayload struct {
+ Rcode witTypes.Option[string]
+ InfoCode witTypes.Option[uint16]
+}
+
+// Defines the case payload type for `TLS-alert-received` above:
+type TlsAlertReceivedPayload struct {
+ AlertId witTypes.Option[uint8]
+ AlertMessage witTypes.Option[string]
+}
+
+// Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
+type FieldSizePayload struct {
+ FieldName witTypes.Option[string]
+ FieldSize witTypes.Option[uint32]
+}
+
+const (
+ ErrorCodeDnsTimeout uint8 = 0
+ ErrorCodeDnsError uint8 = 1
+ ErrorCodeDestinationNotFound uint8 = 2
+ ErrorCodeDestinationUnavailable uint8 = 3
+ ErrorCodeDestinationIpProhibited uint8 = 4
+ ErrorCodeDestinationIpUnroutable uint8 = 5
+ ErrorCodeConnectionRefused uint8 = 6
+ ErrorCodeConnectionTerminated uint8 = 7
+ ErrorCodeConnectionTimeout uint8 = 8
+ ErrorCodeConnectionReadTimeout uint8 = 9
+ ErrorCodeConnectionWriteTimeout uint8 = 10
+ ErrorCodeConnectionLimitReached uint8 = 11
+ ErrorCodeTlsProtocolError uint8 = 12
+ ErrorCodeTlsCertificateError uint8 = 13
+ ErrorCodeTlsAlertReceived uint8 = 14
+ ErrorCodeHttpRequestDenied uint8 = 15
+ ErrorCodeHttpRequestLengthRequired uint8 = 16
+ ErrorCodeHttpRequestBodySize uint8 = 17
+ ErrorCodeHttpRequestMethodInvalid uint8 = 18
+ ErrorCodeHttpRequestUriInvalid uint8 = 19
+ ErrorCodeHttpRequestUriTooLong uint8 = 20
+ ErrorCodeHttpRequestHeaderSectionSize uint8 = 21
+ ErrorCodeHttpRequestHeaderSize uint8 = 22
+ ErrorCodeHttpRequestTrailerSectionSize uint8 = 23
+ ErrorCodeHttpRequestTrailerSize uint8 = 24
+ ErrorCodeHttpResponseIncomplete uint8 = 25
+ ErrorCodeHttpResponseHeaderSectionSize uint8 = 26
+ ErrorCodeHttpResponseHeaderSize uint8 = 27
+ ErrorCodeHttpResponseBodySize uint8 = 28
+ ErrorCodeHttpResponseTrailerSectionSize uint8 = 29
+ ErrorCodeHttpResponseTrailerSize uint8 = 30
+ ErrorCodeHttpResponseTransferCoding uint8 = 31
+ ErrorCodeHttpResponseContentCoding uint8 = 32
+ ErrorCodeHttpResponseTimeout uint8 = 33
+ ErrorCodeHttpUpgradeFailed uint8 = 34
+ ErrorCodeHttpProtocolError uint8 = 35
+ ErrorCodeLoopDetected uint8 = 36
+ ErrorCodeConfigurationError uint8 = 37
+ // This is a catch-all error for anything that doesn't fit cleanly into a
+ // more specific case. It also includes an optional string for an
+ // unstructured description of the error. Users should not depend on the
+ // string for diagnosing errors, as it's not required to be consistent
+ // between implementations.
+ ErrorCodeInternalError uint8 = 38
+)
+
+// These cases are inspired by the IANA HTTP Proxy Error Types:
+//
+//
+type ErrorCode struct {
+ tag uint8
+ value any
+}
+
+func (self ErrorCode) Tag() uint8 {
+ return self.tag
+}
+
+func (self ErrorCode) DnsError() DnsErrorPayload {
+ if self.tag != ErrorCodeDnsError {
+ panic("tag mismatch")
+ }
+ return self.value.(DnsErrorPayload)
+}
+func (self ErrorCode) TlsAlertReceived() TlsAlertReceivedPayload {
+ if self.tag != ErrorCodeTlsAlertReceived {
+ panic("tag mismatch")
+ }
+ return self.value.(TlsAlertReceivedPayload)
+}
+func (self ErrorCode) HttpRequestBodySize() witTypes.Option[uint64] {
+ if self.tag != ErrorCodeHttpRequestBodySize {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[uint64])
+}
+func (self ErrorCode) HttpRequestHeaderSectionSize() witTypes.Option[uint32] {
+ if self.tag != ErrorCodeHttpRequestHeaderSectionSize {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[uint32])
+}
+func (self ErrorCode) HttpRequestHeaderSize() witTypes.Option[FieldSizePayload] {
+ if self.tag != ErrorCodeHttpRequestHeaderSize {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[FieldSizePayload])
+}
+func (self ErrorCode) HttpRequestTrailerSectionSize() witTypes.Option[uint32] {
+ if self.tag != ErrorCodeHttpRequestTrailerSectionSize {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[uint32])
+}
+func (self ErrorCode) HttpRequestTrailerSize() FieldSizePayload {
+ if self.tag != ErrorCodeHttpRequestTrailerSize {
+ panic("tag mismatch")
+ }
+ return self.value.(FieldSizePayload)
+}
+func (self ErrorCode) HttpResponseHeaderSectionSize() witTypes.Option[uint32] {
+ if self.tag != ErrorCodeHttpResponseHeaderSectionSize {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[uint32])
+}
+func (self ErrorCode) HttpResponseHeaderSize() FieldSizePayload {
+ if self.tag != ErrorCodeHttpResponseHeaderSize {
+ panic("tag mismatch")
+ }
+ return self.value.(FieldSizePayload)
+}
+func (self ErrorCode) HttpResponseBodySize() witTypes.Option[uint64] {
+ if self.tag != ErrorCodeHttpResponseBodySize {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[uint64])
+}
+func (self ErrorCode) HttpResponseTrailerSectionSize() witTypes.Option[uint32] {
+ if self.tag != ErrorCodeHttpResponseTrailerSectionSize {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[uint32])
+}
+func (self ErrorCode) HttpResponseTrailerSize() FieldSizePayload {
+ if self.tag != ErrorCodeHttpResponseTrailerSize {
+ panic("tag mismatch")
+ }
+ return self.value.(FieldSizePayload)
+}
+func (self ErrorCode) HttpResponseTransferCoding() witTypes.Option[string] {
+ if self.tag != ErrorCodeHttpResponseTransferCoding {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[string])
+}
+func (self ErrorCode) HttpResponseContentCoding() witTypes.Option[string] {
+ if self.tag != ErrorCodeHttpResponseContentCoding {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[string])
+}
+func (self ErrorCode) InternalError() witTypes.Option[string] {
+ if self.tag != ErrorCodeInternalError {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[string])
+}
+
+func MakeErrorCodeDnsTimeout() ErrorCode {
+ return ErrorCode{ErrorCodeDnsTimeout, nil}
+}
+func MakeErrorCodeDnsError(value DnsErrorPayload) ErrorCode {
+ return ErrorCode{ErrorCodeDnsError, value}
+}
+func MakeErrorCodeDestinationNotFound() ErrorCode {
+ return ErrorCode{ErrorCodeDestinationNotFound, nil}
+}
+func MakeErrorCodeDestinationUnavailable() ErrorCode {
+ return ErrorCode{ErrorCodeDestinationUnavailable, nil}
+}
+func MakeErrorCodeDestinationIpProhibited() ErrorCode {
+ return ErrorCode{ErrorCodeDestinationIpProhibited, nil}
+}
+func MakeErrorCodeDestinationIpUnroutable() ErrorCode {
+ return ErrorCode{ErrorCodeDestinationIpUnroutable, nil}
+}
+func MakeErrorCodeConnectionRefused() ErrorCode {
+ return ErrorCode{ErrorCodeConnectionRefused, nil}
+}
+func MakeErrorCodeConnectionTerminated() ErrorCode {
+ return ErrorCode{ErrorCodeConnectionTerminated, nil}
+}
+func MakeErrorCodeConnectionTimeout() ErrorCode {
+ return ErrorCode{ErrorCodeConnectionTimeout, nil}
+}
+func MakeErrorCodeConnectionReadTimeout() ErrorCode {
+ return ErrorCode{ErrorCodeConnectionReadTimeout, nil}
+}
+func MakeErrorCodeConnectionWriteTimeout() ErrorCode {
+ return ErrorCode{ErrorCodeConnectionWriteTimeout, nil}
+}
+func MakeErrorCodeConnectionLimitReached() ErrorCode {
+ return ErrorCode{ErrorCodeConnectionLimitReached, nil}
+}
+func MakeErrorCodeTlsProtocolError() ErrorCode {
+ return ErrorCode{ErrorCodeTlsProtocolError, nil}
+}
+func MakeErrorCodeTlsCertificateError() ErrorCode {
+ return ErrorCode{ErrorCodeTlsCertificateError, nil}
+}
+func MakeErrorCodeTlsAlertReceived(value TlsAlertReceivedPayload) ErrorCode {
+ return ErrorCode{ErrorCodeTlsAlertReceived, value}
+}
+func MakeErrorCodeHttpRequestDenied() ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestDenied, nil}
+}
+func MakeErrorCodeHttpRequestLengthRequired() ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestLengthRequired, nil}
+}
+func MakeErrorCodeHttpRequestBodySize(value witTypes.Option[uint64]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestBodySize, value}
+}
+func MakeErrorCodeHttpRequestMethodInvalid() ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestMethodInvalid, nil}
+}
+func MakeErrorCodeHttpRequestUriInvalid() ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestUriInvalid, nil}
+}
+func MakeErrorCodeHttpRequestUriTooLong() ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestUriTooLong, nil}
+}
+func MakeErrorCodeHttpRequestHeaderSectionSize(value witTypes.Option[uint32]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestHeaderSectionSize, value}
+}
+func MakeErrorCodeHttpRequestHeaderSize(value witTypes.Option[FieldSizePayload]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestHeaderSize, value}
+}
+func MakeErrorCodeHttpRequestTrailerSectionSize(value witTypes.Option[uint32]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestTrailerSectionSize, value}
+}
+func MakeErrorCodeHttpRequestTrailerSize(value FieldSizePayload) ErrorCode {
+ return ErrorCode{ErrorCodeHttpRequestTrailerSize, value}
+}
+func MakeErrorCodeHttpResponseIncomplete() ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseIncomplete, nil}
+}
+func MakeErrorCodeHttpResponseHeaderSectionSize(value witTypes.Option[uint32]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseHeaderSectionSize, value}
+}
+func MakeErrorCodeHttpResponseHeaderSize(value FieldSizePayload) ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseHeaderSize, value}
+}
+func MakeErrorCodeHttpResponseBodySize(value witTypes.Option[uint64]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseBodySize, value}
+}
+func MakeErrorCodeHttpResponseTrailerSectionSize(value witTypes.Option[uint32]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseTrailerSectionSize, value}
+}
+func MakeErrorCodeHttpResponseTrailerSize(value FieldSizePayload) ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseTrailerSize, value}
+}
+func MakeErrorCodeHttpResponseTransferCoding(value witTypes.Option[string]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseTransferCoding, value}
+}
+func MakeErrorCodeHttpResponseContentCoding(value witTypes.Option[string]) ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseContentCoding, value}
+}
+func MakeErrorCodeHttpResponseTimeout() ErrorCode {
+ return ErrorCode{ErrorCodeHttpResponseTimeout, nil}
+}
+func MakeErrorCodeHttpUpgradeFailed() ErrorCode {
+ return ErrorCode{ErrorCodeHttpUpgradeFailed, nil}
+}
+func MakeErrorCodeHttpProtocolError() ErrorCode {
+ return ErrorCode{ErrorCodeHttpProtocolError, nil}
+}
+func MakeErrorCodeLoopDetected() ErrorCode {
+ return ErrorCode{ErrorCodeLoopDetected, nil}
+}
+func MakeErrorCodeConfigurationError() ErrorCode {
+ return ErrorCode{ErrorCodeConfigurationError, nil}
+}
+func MakeErrorCodeInternalError(value witTypes.Option[string]) ErrorCode {
+ return ErrorCode{ErrorCodeInternalError, value}
+}
+
+const (
+ // This error indicates that a `field-name` or `field-value` was
+ // syntactically invalid when used with an operation that sets headers in a
+ // `fields`.
+ HeaderErrorInvalidSyntax uint8 = 0
+ // This error indicates that a forbidden `field-name` was used when trying
+ // to set a header in a `fields`.
+ HeaderErrorForbidden uint8 = 1
+ // This error indicates that the operation on the `fields` was not
+ // permitted because the fields are immutable.
+ HeaderErrorImmutable uint8 = 2
+ // This error indicates that the operation would exceed an
+ // implementation-defined limit on field sizes. This may apply to
+ // an individual `field-value`, a single `field-name` plus all its
+ // values, or the total aggregate size of all fields.
+ HeaderErrorSizeExceeded uint8 = 3
+ // This is a catch-all error for anything that doesn't fit cleanly into a
+ // more specific case. Implementations can use this to extend the error
+ // type without breaking existing code. It also includes an optional
+ // string for an unstructured description of the error. Users should not
+ // depend on the string for diagnosing errors, as it's not required to be
+ // consistent between implementations.
+ HeaderErrorOther uint8 = 4
+)
+
+// This type enumerates the different kinds of errors that may occur when
+// setting or appending to a `fields` resource.
+type HeaderError struct {
+ tag uint8
+ value any
+}
+
+func (self HeaderError) Tag() uint8 {
+ return self.tag
+}
+
+func (self HeaderError) Other() witTypes.Option[string] {
+ if self.tag != HeaderErrorOther {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[string])
+}
+
+func MakeHeaderErrorInvalidSyntax() HeaderError {
+ return HeaderError{HeaderErrorInvalidSyntax, nil}
+}
+func MakeHeaderErrorForbidden() HeaderError {
+ return HeaderError{HeaderErrorForbidden, nil}
+}
+func MakeHeaderErrorImmutable() HeaderError {
+ return HeaderError{HeaderErrorImmutable, nil}
+}
+func MakeHeaderErrorSizeExceeded() HeaderError {
+ return HeaderError{HeaderErrorSizeExceeded, nil}
+}
+func MakeHeaderErrorOther(value witTypes.Option[string]) HeaderError {
+ return HeaderError{HeaderErrorOther, value}
+}
+
+const (
+ // Indicates the specified field is not supported by this implementation.
+ RequestOptionsErrorNotSupported uint8 = 0
+ // Indicates that the operation on the `request-options` was not permitted
+ // because it is immutable.
+ RequestOptionsErrorImmutable uint8 = 1
+ // This is a catch-all error for anything that doesn't fit cleanly into a
+ // more specific case. Implementations can use this to extend the error
+ // type without breaking existing code. It also includes an optional
+ // string for an unstructured description of the error. Users should not
+ // depend on the string for diagnosing errors, as it's not required to be
+ // consistent between implementations.
+ RequestOptionsErrorOther uint8 = 2
+)
+
+// This type enumerates the different kinds of errors that may occur when
+// setting fields of a `request-options` resource.
+type RequestOptionsError struct {
+ tag uint8
+ value any
+}
+
+func (self RequestOptionsError) Tag() uint8 {
+ return self.tag
+}
+
+func (self RequestOptionsError) Other() witTypes.Option[string] {
+ if self.tag != RequestOptionsErrorOther {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Option[string])
+}
+
+func MakeRequestOptionsErrorNotSupported() RequestOptionsError {
+ return RequestOptionsError{RequestOptionsErrorNotSupported, nil}
+}
+func MakeRequestOptionsErrorImmutable() RequestOptionsError {
+ return RequestOptionsError{RequestOptionsErrorImmutable, nil}
+}
+func MakeRequestOptionsErrorOther(value witTypes.Option[string]) RequestOptionsError {
+ return RequestOptionsError{RequestOptionsErrorOther, value}
+}
+
+// Field names are always strings.
+//
+// Field names should always be treated as case insensitive by the `fields`
+// resource for the purposes of equality checking.
+type FieldName = string
+
+// Field values should always be ASCII strings. However, in
+// reality, HTTP implementations often have to interpret malformed values,
+// so they are provided as a list of bytes.
+type FieldValue = []uint8
+
+//go:wasmimport wasi:http/types@0.3.0 [resource-drop]fields
+func resourceDropFields(handle int32)
+
+// This following block defines the `fields` resource which corresponds to
+// HTTP standard Fields. Fields are a common representation used for both
+// Headers and Trailers.
+//
+// A `fields` may be mutable or immutable. A `fields` created using the
+// constructor, `from-list`, or `clone` will be mutable, but a `fields`
+// resource given by other means (including, but not limited to,
+// `request.headers`) might be be immutable. In an immutable fields, the
+// `set`, `append`, and `delete` operations will fail with
+// `header-error.immutable`.
+//
+// A `fields` resource should store `field-name`s and `field-value`s in their
+// original casing used to construct or mutate the `fields` resource. The `fields`
+// resource should use that original casing when serializing the fields for
+// transport or when returning them from a method.
+//
+// Implementations may impose limits on individual field values and on total
+// aggregate field section size. Operations that would exceed these limits
+// fail with `header-error.size-exceeded`
+type Fields struct {
+ handle *witRuntime.Handle
+}
+
+func (self *Fields) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *Fields) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *Fields) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *Fields) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropFields(handle)
+ }
+}
+
+func FieldsFromOwnHandle(handleValue int32) *Fields {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &Fields{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropFields(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func FieldsFromBorrowHandle(handleValue int32) *Fields {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &Fields{handle}
+}
+
+// Headers is an alias for Fields.
+type Headers = Fields
+
+// Trailers is an alias for Fields.
+type Trailers = Fields
+
+//go:wasmimport wasi:http/types@0.3.0 [resource-drop]request
+func resourceDropRequest(handle int32)
+
+// Represents an HTTP Request.
+type Request struct {
+ handle *witRuntime.Handle
+}
+
+func (self *Request) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *Request) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *Request) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *Request) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropRequest(handle)
+ }
+}
+
+func RequestFromOwnHandle(handleValue int32) *Request {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &Request{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropRequest(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func RequestFromBorrowHandle(handleValue int32) *Request {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &Request{handle}
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [resource-drop]request-options
+func resourceDropRequestOptions(handle int32)
+
+// Parameters for making an HTTP Request. Each of these parameters is
+// currently an optional timeout applicable to the transport layer of the
+// HTTP protocol.
+//
+// These timeouts are separate from any the user may use to bound an
+// asynchronous call.
+type RequestOptions struct {
+ handle *witRuntime.Handle
+}
+
+func (self *RequestOptions) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *RequestOptions) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *RequestOptions) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *RequestOptions) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropRequestOptions(handle)
+ }
+}
+
+func RequestOptionsFromOwnHandle(handleValue int32) *RequestOptions {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &RequestOptions{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropRequestOptions(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func RequestOptionsFromBorrowHandle(handleValue int32) *RequestOptions {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &RequestOptions{handle}
+}
+
+// This type corresponds to the HTTP standard Status Code.
+type StatusCode = uint16
+
+//go:wasmimport wasi:http/types@0.3.0 [resource-drop]response
+func resourceDropResponse(handle int32)
+
+// Represents an HTTP Response.
+type Response struct {
+ handle *witRuntime.Handle
+}
+
+func (self *Response) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *Response) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *Response) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *Response) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropResponse(handle)
+ }
+}
+
+func ResponseFromOwnHandle(handleValue int32) *Response {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &Response{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropResponse(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func ResponseFromBorrowHandle(handleValue int32) *Response {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &Response{handle}
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [constructor]fields
+func wasm_import_constructor_fields() int32
+
+func MakeFields() *Fields {
+
+ result := wasm_import_constructor_fields()
+ return FieldsFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [static]fields.from-list
+func wasm_import_static_fields_from_list(arg0 uintptr, arg1 uint32, arg2 uintptr)
+
+func FieldsFromList(entries []witTypes.Tuple2[string, []uint8]) witTypes.Result[*Fields, HeaderError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4))
+ slice := entries
+ length := uint32(len(slice))
+ result := witRuntime.Allocate(pinner, uintptr(length*(4*4)), 4)
+ for index, element := range slice {
+ base := unsafe.Add(result, index*(4*4))
+ utf8 := unsafe.Pointer(unsafe.StringData((element).F0))
+ pinner.Pin(utf8)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len((element).F0)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf8)))
+ data := unsafe.Pointer(unsafe.SliceData((element).F1))
+ pinner.Pin(data)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4))) = uint32(uint32(len((element).F1)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = uint32(uintptr(uintptr(data)))
+
+ }
+
+ wasm_import_static_fields_from_list(uintptr(result), length, returnArea)
+ var result0 witTypes.Result[*Fields, HeaderError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result0 = witTypes.Ok[*Fields, HeaderError](FieldsFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+ var variant HeaderError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeHeaderErrorInvalidSyntax()
+
+ case 1:
+
+ variant = MakeHeaderErrorForbidden()
+
+ case 2:
+
+ variant = MakeHeaderErrorImmutable()
+
+ case 3:
+
+ variant = MakeHeaderErrorSizeExceeded()
+
+ case 4:
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4))))
+
+ option = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeHeaderErrorOther(option)
+
+ default:
+ panic("unreachable")
+ }
+
+ result0 = witTypes.Err[*Fields, HeaderError](variant)
+ default:
+ panic("unreachable")
+ }
+ result1 := result0
+ return result1
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]fields.get
+func wasm_import_method_fields_get(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr)
+
+func (self *Fields) Get(name string) [][]uint8 {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4))
+ utf8 := unsafe.Pointer(unsafe.StringData(name))
+ pinner.Pin(utf8)
+ wasm_import_method_fields_get((self).Handle(), uintptr(utf8), uint32(len(name)), returnArea)
+ result := make([][]uint8, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
+ for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ {
+ base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0)))), index*(2*4))
+ value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)))
+
+ result = append(result, value)
+ }
+
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]fields.has
+func wasm_import_method_fields_has(arg0 int32, arg1 uintptr, arg2 uint32) int32
+
+func (self *Fields) Has(name string) bool {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ utf8 := unsafe.Pointer(unsafe.StringData(name))
+ pinner.Pin(utf8)
+ result := wasm_import_method_fields_has((self).Handle(), uintptr(utf8), uint32(len(name)))
+ return (result != 0)
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]fields.set
+func wasm_import_method_fields_set(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr)
+
+func (self *Fields) Set(name string, value [][]uint8) witTypes.Result[witTypes.Unit, HeaderError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4))
+ utf8 := unsafe.Pointer(unsafe.StringData(name))
+ pinner.Pin(utf8)
+ slice := value
+ length := uint32(len(slice))
+ result := witRuntime.Allocate(pinner, uintptr(length*(2*4)), 4)
+ for index, element := range slice {
+ base := unsafe.Add(result, index*(2*4))
+ data := unsafe.Pointer(unsafe.SliceData(element))
+ pinner.Pin(data)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len(element)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(data)))
+
+ }
+
+ wasm_import_method_fields_set((self).Handle(), uintptr(utf8), uint32(len(name)), uintptr(result), length, returnArea)
+ var result1 witTypes.Result[witTypes.Unit, HeaderError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result1 = witTypes.Ok[witTypes.Unit, HeaderError](witTypes.Unit{})
+ case 1:
+ var variant HeaderError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeHeaderErrorInvalidSyntax()
+
+ case 1:
+
+ variant = MakeHeaderErrorForbidden()
+
+ case 2:
+
+ variant = MakeHeaderErrorImmutable()
+
+ case 3:
+
+ variant = MakeHeaderErrorSizeExceeded()
+
+ case 4:
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4))))
+
+ option = witTypes.Some[string](value0)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeHeaderErrorOther(option)
+
+ default:
+ panic("unreachable")
+ }
+
+ result1 = witTypes.Err[witTypes.Unit, HeaderError](variant)
+ default:
+ panic("unreachable")
+ }
+ result2 := result1
+ return result2
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]fields.delete
+func wasm_import_method_fields_delete(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr)
+
+func (self *Fields) Delete(name string) witTypes.Result[witTypes.Unit, HeaderError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4))
+ utf8 := unsafe.Pointer(unsafe.StringData(name))
+ pinner.Pin(utf8)
+ wasm_import_method_fields_delete((self).Handle(), uintptr(utf8), uint32(len(name)), returnArea)
+ var result witTypes.Result[witTypes.Unit, HeaderError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, HeaderError](witTypes.Unit{})
+ case 1:
+ var variant HeaderError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeHeaderErrorInvalidSyntax()
+
+ case 1:
+
+ variant = MakeHeaderErrorForbidden()
+
+ case 2:
+
+ variant = MakeHeaderErrorImmutable()
+
+ case 3:
+
+ variant = MakeHeaderErrorSizeExceeded()
+
+ case 4:
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4))))
+
+ option = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeHeaderErrorOther(option)
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Unit, HeaderError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]fields.get-and-delete
+func wasm_import_method_fields_get_and_delete(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr)
+
+func (self *Fields) GetAndDelete(name string) witTypes.Result[[][]uint8, HeaderError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4))
+ utf8 := unsafe.Pointer(unsafe.StringData(name))
+ pinner.Pin(utf8)
+ wasm_import_method_fields_get_and_delete((self).Handle(), uintptr(utf8), uint32(len(name)), returnArea)
+ var result1 witTypes.Result[[][]uint8, HeaderError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ result := make([][]uint8, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+ for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ {
+ base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(2*4))
+ value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)))
+
+ result = append(result, value)
+ }
+
+ result1 = witTypes.Ok[[][]uint8, HeaderError](result)
+ case 1:
+ var variant HeaderError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeHeaderErrorInvalidSyntax()
+
+ case 1:
+
+ variant = MakeHeaderErrorForbidden()
+
+ case 2:
+
+ variant = MakeHeaderErrorImmutable()
+
+ case 3:
+
+ variant = MakeHeaderErrorSizeExceeded()
+
+ case 4:
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4))))
+
+ option = witTypes.Some[string](value0)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeHeaderErrorOther(option)
+
+ default:
+ panic("unreachable")
+ }
+
+ result1 = witTypes.Err[[][]uint8, HeaderError](variant)
+ default:
+ panic("unreachable")
+ }
+ result2 := result1
+ return result2
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]fields.append
+func wasm_import_method_fields_append(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr)
+
+func (self *Fields) Append(name string, value []uint8) witTypes.Result[witTypes.Unit, HeaderError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4))
+ utf8 := unsafe.Pointer(unsafe.StringData(name))
+ pinner.Pin(utf8)
+ data := unsafe.Pointer(unsafe.SliceData(value))
+ pinner.Pin(data)
+ wasm_import_method_fields_append((self).Handle(), uintptr(utf8), uint32(len(name)), uintptr(data), uint32(len(value)), returnArea)
+ var result witTypes.Result[witTypes.Unit, HeaderError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, HeaderError](witTypes.Unit{})
+ case 1:
+ var variant HeaderError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeHeaderErrorInvalidSyntax()
+
+ case 1:
+
+ variant = MakeHeaderErrorForbidden()
+
+ case 2:
+
+ variant = MakeHeaderErrorImmutable()
+
+ case 3:
+
+ variant = MakeHeaderErrorSizeExceeded()
+
+ case 4:
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4))))
+
+ option = witTypes.Some[string](value0)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeHeaderErrorOther(option)
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Unit, HeaderError](variant)
+ default:
+ panic("unreachable")
+ }
+ result1 := result
+ return result1
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]fields.copy-all
+func wasm_import_method_fields_copy_all(arg0 int32, arg1 uintptr)
+
+func (self *Fields) CopyAll() []witTypes.Tuple2[string, []uint8] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4))
+ wasm_import_method_fields_copy_all((self).Handle(), returnArea)
+ result := make([]witTypes.Tuple2[string, []uint8], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
+ for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ {
+ base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0)))), index*(4*4))
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)))
+ value0 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4))))
+
+ result = append(result, witTypes.Tuple2[string, []uint8]{value, value0})
+ }
+
+ result1 := result
+ return result1
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]fields.clone
+func wasm_import_method_fields_clone(arg0 int32) int32
+
+func (self *Fields) Clone() *Fields {
+
+ result := wasm_import_method_fields_clone((self).Handle())
+ return FieldsFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [static]request.new
+func wasm_import_static_request_new(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int32, arg5 int32, arg6 uintptr)
+
+func RequestNew(headers *Fields, contents witTypes.Option[*witTypes.StreamReader[uint8]], trailers *witTypes.FutureReader[witTypes.Result[witTypes.Option[*Fields], ErrorCode]], options witTypes.Option[*RequestOptions]) (*Request, *witTypes.FutureReader[witTypes.Result[witTypes.Unit, ErrorCode]]) {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ var option int32
+ var option0 int32
+ switch contents.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option0 = 0
+ case witTypes.OptionSome:
+ payload := contents.Some()
+
+ option = int32(1)
+ option0 = (payload).TakeHandle()
+ default:
+ panic("unreachable")
+ }
+ var option1 int32
+ var option2 int32
+ switch options.Tag() {
+ case witTypes.OptionNone:
+
+ option1 = int32(0)
+ option2 = 0
+ case witTypes.OptionSome:
+ payload := options.Some()
+
+ option1 = int32(1)
+ option2 = (payload).TakeHandle()
+ default:
+ panic("unreachable")
+ }
+ wasm_import_static_request_new((headers).TakeHandle(), option, option0, (trailers).TakeHandle(), option1, option2, returnArea)
+ result := witTypes.Tuple2[*Request, *witTypes.FutureReader[witTypes.Result[witTypes.Unit, ErrorCode]]]{RequestFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), LiftFutureResultUnitErrorCode(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))}
+ tuple := result
+ return tuple.F0, tuple.F1
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request.get-method
+func wasm_import_method_request_get_method(arg0 int32, arg1 uintptr)
+
+func (self *Request) GetMethod() Method {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4))
+ wasm_import_method_request_get_method((self).Handle(), returnArea)
+ var variant Method
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ variant = MakeMethodGet()
+
+ case 1:
+
+ variant = MakeMethodHead()
+
+ case 2:
+
+ variant = MakeMethodPost()
+
+ case 3:
+
+ variant = MakeMethodPut()
+
+ case 4:
+
+ variant = MakeMethodDelete()
+
+ case 5:
+
+ variant = MakeMethodConnect()
+
+ case 6:
+
+ variant = MakeMethodOptions()
+
+ case 7:
+
+ variant = MakeMethodTrace()
+
+ case 8:
+
+ variant = MakeMethodPatch()
+
+ case 9:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+
+ variant = MakeMethodOther(value)
+
+ default:
+ panic("unreachable")
+ }
+ result := variant
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request.set-method
+func wasm_import_method_request_set_method(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32) int32
+
+func (self *Request) SetMethod(method Method) witTypes.Result[witTypes.Unit, witTypes.Unit] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ var variant int32
+ var variant0 uintptr
+ var variant1 uint32
+ switch method.Tag() {
+ case MethodGet:
+
+ variant = int32(0)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodHead:
+
+ variant = int32(1)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodPost:
+
+ variant = int32(2)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodPut:
+
+ variant = int32(3)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodDelete:
+
+ variant = int32(4)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodConnect:
+
+ variant = int32(5)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodOptions:
+
+ variant = int32(6)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodTrace:
+
+ variant = int32(7)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodPatch:
+
+ variant = int32(8)
+ variant0 = 0
+ variant1 = 0
+
+ case MethodOther:
+ payload := method.Other()
+ utf8 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf8)
+
+ variant = int32(9)
+ variant0 = uintptr(utf8)
+ variant1 = uint32(len(payload))
+
+ default:
+ panic("unreachable")
+ }
+ result := wasm_import_method_request_set_method((self).Handle(), variant, variant0, variant1)
+ var result2 witTypes.Result[witTypes.Unit, witTypes.Unit]
+ switch result {
+ case 0:
+
+ result2 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ case 1:
+
+ result2 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ return result2
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request.get-path-with-query
+func wasm_import_method_request_get_path_with_query(arg0 int32, arg1 uintptr)
+
+func (self *Request) GetPathWithQuery() witTypes.Option[string] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4))
+ wasm_import_method_request_get_path_with_query((self).Handle(), returnArea)
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+
+ option = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request.set-path-with-query
+func wasm_import_method_request_set_path_with_query(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32) int32
+
+func (self *Request) SetPathWithQuery(pathWithQuery witTypes.Option[string]) witTypes.Result[witTypes.Unit, witTypes.Unit] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ var option int32
+ var option0 uintptr
+ var option1 uint32
+ switch pathWithQuery.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option0 = 0
+ option1 = 0
+ case witTypes.OptionSome:
+ payload := pathWithQuery.Some()
+ utf8 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf8)
+
+ option = int32(1)
+ option0 = uintptr(utf8)
+ option1 = uint32(len(payload))
+ default:
+ panic("unreachable")
+ }
+ result := wasm_import_method_request_set_path_with_query((self).Handle(), option, option0, option1)
+ var result2 witTypes.Result[witTypes.Unit, witTypes.Unit]
+ switch result {
+ case 0:
+
+ result2 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ case 1:
+
+ result2 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ return result2
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request.get-scheme
+func wasm_import_method_request_get_scheme(arg0 int32, arg1 uintptr)
+
+func (self *Request) GetScheme() witTypes.Option[Scheme] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4))
+ wasm_import_method_request_get_scheme((self).Handle(), returnArea)
+ var option witTypes.Option[Scheme]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[Scheme]()
+ case 1:
+ var variant Scheme
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeSchemeHttp()
+
+ case 1:
+
+ variant = MakeSchemeHttps()
+
+ case 2:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))
+
+ variant = MakeSchemeOther(value)
+
+ default:
+ panic("unreachable")
+ }
+
+ option = witTypes.Some[Scheme](variant)
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request.set-scheme
+func wasm_import_method_request_set_scheme(arg0 int32, arg1 int32, arg2 int32, arg3 uintptr, arg4 uint32) int32
+
+func (self *Request) SetScheme(scheme witTypes.Option[Scheme]) witTypes.Result[witTypes.Unit, witTypes.Unit] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ var option int32
+ var option2 int32
+ var option3 uintptr
+ var option4 uint32
+ switch scheme.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option2 = 0
+ option3 = 0
+ option4 = 0
+ case witTypes.OptionSome:
+ payload := scheme.Some()
+ var variant int32
+ var variant0 uintptr
+ var variant1 uint32
+ switch payload.Tag() {
+ case SchemeHttp:
+
+ variant = int32(0)
+ variant0 = 0
+ variant1 = 0
+
+ case SchemeHttps:
+
+ variant = int32(1)
+ variant0 = 0
+ variant1 = 0
+
+ case SchemeOther:
+ payload := payload.Other()
+ utf8 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf8)
+
+ variant = int32(2)
+ variant0 = uintptr(utf8)
+ variant1 = uint32(len(payload))
+
+ default:
+ panic("unreachable")
+ }
+
+ option = int32(1)
+ option2 = variant
+ option3 = variant0
+ option4 = variant1
+ default:
+ panic("unreachable")
+ }
+ result := wasm_import_method_request_set_scheme((self).Handle(), option, option2, option3, option4)
+ var result5 witTypes.Result[witTypes.Unit, witTypes.Unit]
+ switch result {
+ case 0:
+
+ result5 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ case 1:
+
+ result5 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ return result5
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request.get-authority
+func wasm_import_method_request_get_authority(arg0 int32, arg1 uintptr)
+
+func (self *Request) GetAuthority() witTypes.Option[string] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4))
+ wasm_import_method_request_get_authority((self).Handle(), returnArea)
+ var option witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+
+ option = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request.set-authority
+func wasm_import_method_request_set_authority(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32) int32
+
+func (self *Request) SetAuthority(authority witTypes.Option[string]) witTypes.Result[witTypes.Unit, witTypes.Unit] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ var option int32
+ var option0 uintptr
+ var option1 uint32
+ switch authority.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option0 = 0
+ option1 = 0
+ case witTypes.OptionSome:
+ payload := authority.Some()
+ utf8 := unsafe.Pointer(unsafe.StringData(payload))
+ pinner.Pin(utf8)
+
+ option = int32(1)
+ option0 = uintptr(utf8)
+ option1 = uint32(len(payload))
+ default:
+ panic("unreachable")
+ }
+ result := wasm_import_method_request_set_authority((self).Handle(), option, option0, option1)
+ var result2 witTypes.Result[witTypes.Unit, witTypes.Unit]
+ switch result {
+ case 0:
+
+ result2 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ case 1:
+
+ result2 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ return result2
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request.get-options
+func wasm_import_method_request_get_options(arg0 int32, arg1 uintptr)
+
+func (self *Request) GetOptions() witTypes.Option[*RequestOptions] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_method_request_get_options((self).Handle(), returnArea)
+ var option witTypes.Option[*RequestOptions]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[*RequestOptions]()
+ case 1:
+
+ option = witTypes.Some[*RequestOptions](RequestOptionsFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request.get-headers
+func wasm_import_method_request_get_headers(arg0 int32) int32
+
+func (self *Request) GetHeaders() *Fields {
+
+ result := wasm_import_method_request_get_headers((self).Handle())
+ return FieldsFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [static]request.consume-body
+func wasm_import_static_request_consume_body(arg0 int32, arg1 int32, arg2 uintptr)
+
+func RequestConsumeBody(this *Request, res *witTypes.FutureReader[witTypes.Result[witTypes.Unit, ErrorCode]]) (*witTypes.StreamReader[uint8], *witTypes.FutureReader[witTypes.Result[witTypes.Option[*Fields], ErrorCode]]) {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_static_request_consume_body((this).TakeHandle(), (res).TakeHandle(), returnArea)
+ result := witTypes.Tuple2[*witTypes.StreamReader[uint8], *witTypes.FutureReader[witTypes.Result[witTypes.Option[*Fields], ErrorCode]]]{LiftStreamU8(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 0))), LiftFutureResultOptionFieldsErrorCode(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))}
+ tuple := result
+ return tuple.F0, tuple.F1
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [constructor]request-options
+func wasm_import_constructor_request_options() int32
+
+func MakeRequestOptions() *RequestOptions {
+
+ result := wasm_import_constructor_request_options()
+ return RequestOptionsFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request-options.get-connect-timeout
+func wasm_import_method_request_options_get_connect_timeout(arg0 int32, arg1 uintptr)
+
+func (self *RequestOptions) GetConnectTimeout() witTypes.Option[uint64] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_request_options_get_connect_timeout((self).Handle(), returnArea)
+ var option witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[uint64]()
+ case 1:
+
+ option = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request-options.set-connect-timeout
+func wasm_import_method_request_options_set_connect_timeout(arg0 int32, arg1 int32, arg2 int64, arg3 uintptr)
+
+func (self *RequestOptions) SetConnectTimeout(duration witTypes.Option[uint64]) witTypes.Result[witTypes.Unit, RequestOptionsError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4))
+ var option int32
+ var option0 int64
+ switch duration.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option0 = 0
+ case witTypes.OptionSome:
+ payload := duration.Some()
+
+ option = int32(1)
+ option0 = int64(payload)
+ default:
+ panic("unreachable")
+ }
+ wasm_import_method_request_options_set_connect_timeout((self).Handle(), option, option0, returnArea)
+ var result witTypes.Result[witTypes.Unit, RequestOptionsError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, RequestOptionsError](witTypes.Unit{})
+ case 1:
+ var variant RequestOptionsError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeRequestOptionsErrorNotSupported()
+
+ case 1:
+
+ variant = MakeRequestOptionsErrorImmutable()
+
+ case 2:
+ var option1 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) {
+ case 0:
+
+ option1 = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4))))
+
+ option1 = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeRequestOptionsErrorOther(option1)
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Unit, RequestOptionsError](variant)
+ default:
+ panic("unreachable")
+ }
+ result2 := result
+ return result2
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request-options.get-first-byte-timeout
+func wasm_import_method_request_options_get_first_byte_timeout(arg0 int32, arg1 uintptr)
+
+func (self *RequestOptions) GetFirstByteTimeout() witTypes.Option[uint64] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_request_options_get_first_byte_timeout((self).Handle(), returnArea)
+ var option witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[uint64]()
+ case 1:
+
+ option = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request-options.set-first-byte-timeout
+func wasm_import_method_request_options_set_first_byte_timeout(arg0 int32, arg1 int32, arg2 int64, arg3 uintptr)
+
+func (self *RequestOptions) SetFirstByteTimeout(duration witTypes.Option[uint64]) witTypes.Result[witTypes.Unit, RequestOptionsError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4))
+ var option int32
+ var option0 int64
+ switch duration.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option0 = 0
+ case witTypes.OptionSome:
+ payload := duration.Some()
+
+ option = int32(1)
+ option0 = int64(payload)
+ default:
+ panic("unreachable")
+ }
+ wasm_import_method_request_options_set_first_byte_timeout((self).Handle(), option, option0, returnArea)
+ var result witTypes.Result[witTypes.Unit, RequestOptionsError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, RequestOptionsError](witTypes.Unit{})
+ case 1:
+ var variant RequestOptionsError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeRequestOptionsErrorNotSupported()
+
+ case 1:
+
+ variant = MakeRequestOptionsErrorImmutable()
+
+ case 2:
+ var option1 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) {
+ case 0:
+
+ option1 = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4))))
+
+ option1 = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeRequestOptionsErrorOther(option1)
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Unit, RequestOptionsError](variant)
+ default:
+ panic("unreachable")
+ }
+ result2 := result
+ return result2
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request-options.get-between-bytes-timeout
+func wasm_import_method_request_options_get_between_bytes_timeout(arg0 int32, arg1 uintptr)
+
+func (self *RequestOptions) GetBetweenBytesTimeout() witTypes.Option[uint64] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_request_options_get_between_bytes_timeout((self).Handle(), returnArea)
+ var option witTypes.Option[uint64]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ option = witTypes.None[uint64]()
+ case 1:
+
+ option = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ default:
+ panic("unreachable")
+ }
+ result := option
+ return result
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request-options.set-between-bytes-timeout
+func wasm_import_method_request_options_set_between_bytes_timeout(arg0 int32, arg1 int32, arg2 int64, arg3 uintptr)
+
+func (self *RequestOptions) SetBetweenBytesTimeout(duration witTypes.Option[uint64]) witTypes.Result[witTypes.Unit, RequestOptionsError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4))
+ var option int32
+ var option0 int64
+ switch duration.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option0 = 0
+ case witTypes.OptionSome:
+ payload := duration.Some()
+
+ option = int32(1)
+ option0 = int64(payload)
+ default:
+ panic("unreachable")
+ }
+ wasm_import_method_request_options_set_between_bytes_timeout((self).Handle(), option, option0, returnArea)
+ var result witTypes.Result[witTypes.Unit, RequestOptionsError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, RequestOptionsError](witTypes.Unit{})
+ case 1:
+ var variant RequestOptionsError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeRequestOptionsErrorNotSupported()
+
+ case 1:
+
+ variant = MakeRequestOptionsErrorImmutable()
+
+ case 2:
+ var option1 witTypes.Option[string]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) {
+ case 0:
+
+ option1 = witTypes.None[string]()
+ case 1:
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4))))
+
+ option1 = witTypes.Some[string](value)
+ default:
+ panic("unreachable")
+ }
+
+ variant = MakeRequestOptionsErrorOther(option1)
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Unit, RequestOptionsError](variant)
+ default:
+ panic("unreachable")
+ }
+ result2 := result
+ return result2
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]request-options.clone
+func wasm_import_method_request_options_clone(arg0 int32) int32
+
+func (self *RequestOptions) Clone() *RequestOptions {
+
+ result := wasm_import_method_request_options_clone((self).Handle())
+ return RequestOptionsFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [static]response.new
+func wasm_import_static_response_new(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 uintptr)
+
+func ResponseNew(headers *Fields, contents witTypes.Option[*witTypes.StreamReader[uint8]], trailers *witTypes.FutureReader[witTypes.Result[witTypes.Option[*Fields], ErrorCode]]) (*Response, *witTypes.FutureReader[witTypes.Result[witTypes.Unit, ErrorCode]]) {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ var option int32
+ var option0 int32
+ switch contents.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option0 = 0
+ case witTypes.OptionSome:
+ payload := contents.Some()
+
+ option = int32(1)
+ option0 = (payload).TakeHandle()
+ default:
+ panic("unreachable")
+ }
+ wasm_import_static_response_new((headers).TakeHandle(), option, option0, (trailers).TakeHandle(), returnArea)
+ result := witTypes.Tuple2[*Response, *witTypes.FutureReader[witTypes.Result[witTypes.Unit, ErrorCode]]]{ResponseFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), LiftFutureResultUnitErrorCode(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))}
+ tuple := result
+ return tuple.F0, tuple.F1
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]response.get-status-code
+func wasm_import_method_response_get_status_code(arg0 int32) int32
+
+func (self *Response) GetStatusCode() uint16 {
+
+ result := wasm_import_method_response_get_status_code((self).Handle())
+ return uint16(result)
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]response.set-status-code
+func wasm_import_method_response_set_status_code(arg0 int32, arg1 int32) int32
+
+func (self *Response) SetStatusCode(statusCode uint16) witTypes.Result[witTypes.Unit, witTypes.Unit] {
+
+ result := wasm_import_method_response_set_status_code((self).Handle(), int32(statusCode))
+ var result0 witTypes.Result[witTypes.Unit, witTypes.Unit]
+ switch result {
+ case 0:
+
+ result0 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ case 1:
+
+ result0 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{})
+ default:
+ panic("unreachable")
+ }
+ return result0
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [method]response.get-headers
+func wasm_import_method_response_get_headers(arg0 int32) int32
+
+func (self *Response) GetHeaders() *Fields {
+
+ result := wasm_import_method_response_get_headers((self).Handle())
+ return FieldsFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:http/types@0.3.0 [static]response.consume-body
+func wasm_import_static_response_consume_body(arg0 int32, arg1 int32, arg2 uintptr)
+
+func ResponseConsumeBody(this *Response, res *witTypes.FutureReader[witTypes.Result[witTypes.Unit, ErrorCode]]) (*witTypes.StreamReader[uint8], *witTypes.FutureReader[witTypes.Result[witTypes.Option[*Fields], ErrorCode]]) {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_static_response_consume_body((this).TakeHandle(), (res).TakeHandle(), returnArea)
+ result := witTypes.Tuple2[*witTypes.StreamReader[uint8], *witTypes.FutureReader[witTypes.Result[witTypes.Option[*Fields], ErrorCode]]]{LiftStreamU8(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 0))), LiftFutureResultOptionFieldsErrorCode(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))}
+ tuple := result
+ return tuple.F0, tuple.F1
+
+}
diff --git a/imports/wasi_io_0_2_8_error/empty.s b/imports/wasi_io_0_2_8_error/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_io_0_2_8_error/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_io_0_2_8_error/wit_bindings.go b/imports/wasi_io_0_2_8_error/wit_bindings.go
new file mode 100644
index 0000000..23d4b05
--- /dev/null
+++ b/imports/wasi_io_0_2_8_error/wit_bindings.go
@@ -0,0 +1,103 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_io_0_2_8_error
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ "runtime"
+ "unsafe"
+)
+
+//go:wasmimport wasi:io/error@0.2.8 [resource-drop]error
+func resourceDropError(handle int32)
+
+// A resource which represents some error information.
+//
+// The only method provided by this resource is `to-debug-string`,
+// which provides some human-readable information about the error.
+//
+// In the `wasi:io` package, this resource is returned through the
+// `wasi:io/streams/stream-error` type.
+//
+// To provide more specific error information, other interfaces may
+// offer functions to "downcast" this error into more specific types. For example,
+// errors returned from streams derived from filesystem types can be described using
+// the filesystem's own error-code type. This is done using the function
+// `wasi:filesystem/types/filesystem-error-code`, which takes a `borrow`
+// parameter and returns an `option`.
+//
+// The set of functions which can "downcast" an `error` into a more
+// concrete type is open.
+type Error struct {
+ handle *witRuntime.Handle
+}
+
+func (self *Error) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *Error) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *Error) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *Error) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropError(handle)
+ }
+}
+
+func ErrorFromOwnHandle(handleValue int32) *Error {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &Error{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropError(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func ErrorFromBorrowHandle(handleValue int32) *Error {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &Error{handle}
+}
+
+//go:wasmimport wasi:io/error@0.2.8 [method]error.to-debug-string
+func wasm_import_method_error_to_debug_string(arg0 int32, arg1 uintptr)
+
+func (self *Error) ToDebugString() string {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4))
+ wasm_import_method_error_to_debug_string((self).Handle(), returnArea)
+ value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
+ result := value
+ return result
+
+}
diff --git a/imports/wasi_io_0_2_8_poll/empty.s b/imports/wasi_io_0_2_8_poll/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_io_0_2_8_poll/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_io_0_2_8_poll/wit_bindings.go b/imports/wasi_io_0_2_8_poll/wit_bindings.go
new file mode 100644
index 0000000..8245ac6
--- /dev/null
+++ b/imports/wasi_io_0_2_8_poll/wit_bindings.go
@@ -0,0 +1,115 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_io_0_2_8_poll
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ "runtime"
+ "unsafe"
+)
+
+//go:wasmimport wasi:io/poll@0.2.8 [resource-drop]pollable
+func resourceDropPollable(handle int32)
+
+// `pollable` represents a single I/O event which may be ready, or not.
+type Pollable struct {
+ handle *witRuntime.Handle
+}
+
+func (self *Pollable) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *Pollable) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *Pollable) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *Pollable) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropPollable(handle)
+ }
+}
+
+func PollableFromOwnHandle(handleValue int32) *Pollable {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &Pollable{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropPollable(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func PollableFromBorrowHandle(handleValue int32) *Pollable {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &Pollable{handle}
+}
+
+//go:wasmimport wasi:io/poll@0.2.8 [method]pollable.ready
+func wasm_import_method_pollable_ready(arg0 int32) int32
+
+func (self *Pollable) Ready() bool {
+
+ result := wasm_import_method_pollable_ready((self).Handle())
+ return (result != 0)
+
+}
+
+//go:wasmimport wasi:io/poll@0.2.8 [method]pollable.block
+func wasm_import_method_pollable_block(arg0 int32)
+
+func (self *Pollable) Block() {
+
+ wasm_import_method_pollable_block((self).Handle())
+
+}
+
+//go:wasmimport wasi:io/poll@0.2.8 poll
+func wasm_import_poll(arg0 uintptr, arg1 uint32, arg2 uintptr)
+
+func Poll(in []*Pollable) []uint32 {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4))
+ slice := in
+ length := uint32(len(slice))
+ result := witRuntime.Allocate(pinner, uintptr(length*4), 4)
+ for index, element := range slice {
+ base := unsafe.Add(result, index*4)
+ *(*int32)(unsafe.Add(unsafe.Pointer(base), 0)) = (element).Handle()
+
+ }
+
+ wasm_import_poll(uintptr(result), length, returnArea)
+ value := unsafe.Slice((*uint32)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
+ result0 := value
+ return result0
+
+}
diff --git a/imports/wasi_io_0_2_8_streams/empty.s b/imports/wasi_io_0_2_8_streams/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_io_0_2_8_streams/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_io_0_2_8_streams/wit_bindings.go b/imports/wasi_io_0_2_8_streams/wit_bindings.go
new file mode 100644
index 0000000..3a4c652
--- /dev/null
+++ b/imports/wasi_io_0_2_8_streams/wit_bindings.go
@@ -0,0 +1,698 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_io_0_2_8_streams
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_error"
+ "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_poll"
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+type Error = wasi_io_0_2_8_error.Error
+type Pollable = wasi_io_0_2_8_poll.Pollable
+
+const (
+ // The last operation (a write or flush) failed before completion.
+ //
+ // More information is available in the `error` payload.
+ //
+ // After this, the stream will be closed. All future operations return
+ // `stream-error::closed`.
+ StreamErrorLastOperationFailed uint8 = 0
+ // The stream is closed: no more input will be accepted by the
+ // stream. A closed output-stream will return this error on all
+ // future operations.
+ StreamErrorClosed uint8 = 1
+)
+
+// An error for input-stream and output-stream operations.
+type StreamError struct {
+ tag uint8
+ value any
+}
+
+func (self StreamError) Tag() uint8 {
+ return self.tag
+}
+
+func (self StreamError) LastOperationFailed() *wasi_io_0_2_8_error.Error {
+ if self.tag != StreamErrorLastOperationFailed {
+ panic("tag mismatch")
+ }
+ return self.value.(*wasi_io_0_2_8_error.Error)
+}
+
+func MakeStreamErrorLastOperationFailed(value *wasi_io_0_2_8_error.Error) StreamError {
+ return StreamError{StreamErrorLastOperationFailed, value}
+}
+func MakeStreamErrorClosed() StreamError {
+ return StreamError{StreamErrorClosed, nil}
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [resource-drop]input-stream
+func resourceDropInputStream(handle int32)
+
+// An input bytestream.
+//
+// `input-stream`s are *non-blocking* to the extent practical on underlying
+// platforms. I/O operations always return promptly; if fewer bytes are
+// promptly available than requested, they return the number of bytes promptly
+// available, which could even be zero. To wait for data to be available,
+// use the `subscribe` function to obtain a `pollable` which can be polled
+// for using `wasi:io/poll`.
+type InputStream struct {
+ handle *witRuntime.Handle
+}
+
+func (self *InputStream) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *InputStream) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *InputStream) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *InputStream) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropInputStream(handle)
+ }
+}
+
+func InputStreamFromOwnHandle(handleValue int32) *InputStream {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &InputStream{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropInputStream(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func InputStreamFromBorrowHandle(handleValue int32) *InputStream {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &InputStream{handle}
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [resource-drop]output-stream
+func resourceDropOutputStream(handle int32)
+
+// An output bytestream.
+//
+// `output-stream`s are *non-blocking* to the extent practical on
+// underlying platforms. Except where specified otherwise, I/O operations also
+// always return promptly, after the number of bytes that can be written
+// promptly, which could even be zero. To wait for the stream to be ready to
+// accept data, the `subscribe` function to obtain a `pollable` which can be
+// polled for using `wasi:io/poll`.
+//
+// Dropping an `output-stream` while there's still an active write in
+// progress may result in the data being lost. Before dropping the stream,
+// be sure to fully flush your writes.
+type OutputStream struct {
+ handle *witRuntime.Handle
+}
+
+func (self *OutputStream) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *OutputStream) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *OutputStream) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *OutputStream) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropOutputStream(handle)
+ }
+}
+
+func OutputStreamFromOwnHandle(handleValue int32) *OutputStream {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &OutputStream{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropOutputStream(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func OutputStreamFromBorrowHandle(handleValue int32) *OutputStream {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &OutputStream{handle}
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [method]input-stream.read
+func wasm_import_method_input_stream_read(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *InputStream) Read(len uint64) witTypes.Result[[]uint8, StreamError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4))
+ wasm_import_method_input_stream_read((self).Handle(), int64(len), returnArea)
+ var result witTypes.Result[[]uint8, StreamError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+
+ result = witTypes.Ok[[]uint8, StreamError](value)
+ case 1:
+ var variant StreamError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_8_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (4 + 1*4)))))))
+
+ case 1:
+
+ variant = MakeStreamErrorClosed()
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[[]uint8, StreamError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [method]input-stream.blocking-read
+func wasm_import_method_input_stream_blocking_read(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *InputStream) BlockingRead(len uint64) witTypes.Result[[]uint8, StreamError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4))
+ wasm_import_method_input_stream_blocking_read((self).Handle(), int64(len), returnArea)
+ var result witTypes.Result[[]uint8, StreamError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+
+ result = witTypes.Ok[[]uint8, StreamError](value)
+ case 1:
+ var variant StreamError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_8_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (4 + 1*4)))))))
+
+ case 1:
+
+ variant = MakeStreamErrorClosed()
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[[]uint8, StreamError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [method]input-stream.skip
+func wasm_import_method_input_stream_skip(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *InputStream) Skip(len uint64) witTypes.Result[uint64, StreamError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_input_stream_skip((self).Handle(), int64(len), returnArea)
+ var result witTypes.Result[uint64, StreamError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ case 1:
+ var variant StreamError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) {
+ case 0:
+
+ variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_8_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))))))
+
+ case 1:
+
+ variant = MakeStreamErrorClosed()
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[uint64, StreamError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [method]input-stream.blocking-skip
+func wasm_import_method_input_stream_blocking_skip(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *InputStream) BlockingSkip(len uint64) witTypes.Result[uint64, StreamError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_input_stream_blocking_skip((self).Handle(), int64(len), returnArea)
+ var result witTypes.Result[uint64, StreamError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ case 1:
+ var variant StreamError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) {
+ case 0:
+
+ variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_8_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))))))
+
+ case 1:
+
+ variant = MakeStreamErrorClosed()
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[uint64, StreamError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [method]input-stream.subscribe
+func wasm_import_method_input_stream_subscribe(arg0 int32) int32
+
+func (self *InputStream) Subscribe() *wasi_io_0_2_8_poll.Pollable {
+
+ result := wasm_import_method_input_stream_subscribe((self).Handle())
+ return wasi_io_0_2_8_poll.PollableFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [method]output-stream.check-write
+func wasm_import_method_output_stream_check_write(arg0 int32, arg1 uintptr)
+
+func (self *OutputStream) CheckWrite() witTypes.Result[uint64, StreamError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_output_stream_check_write((self).Handle(), returnArea)
+ var result witTypes.Result[uint64, StreamError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ case 1:
+ var variant StreamError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) {
+ case 0:
+
+ variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_8_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))))))
+
+ case 1:
+
+ variant = MakeStreamErrorClosed()
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[uint64, StreamError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [method]output-stream.write
+func wasm_import_method_output_stream_write(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr)
+
+func (self *OutputStream) Write(contents []uint8) witTypes.Result[witTypes.Unit, StreamError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4))
+ data := unsafe.Pointer(unsafe.SliceData(contents))
+ pinner.Pin(data)
+ wasm_import_method_output_stream_write((self).Handle(), uintptr(data), uint32(len(contents)), returnArea)
+ var result witTypes.Result[witTypes.Unit, StreamError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, StreamError](witTypes.Unit{})
+ case 1:
+ var variant StreamError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_8_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))))
+
+ case 1:
+
+ variant = MakeStreamErrorClosed()
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Unit, StreamError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [method]output-stream.blocking-write-and-flush
+func wasm_import_method_output_stream_blocking_write_and_flush(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr)
+
+func (self *OutputStream) BlockingWriteAndFlush(contents []uint8) witTypes.Result[witTypes.Unit, StreamError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4))
+ data := unsafe.Pointer(unsafe.SliceData(contents))
+ pinner.Pin(data)
+ wasm_import_method_output_stream_blocking_write_and_flush((self).Handle(), uintptr(data), uint32(len(contents)), returnArea)
+ var result witTypes.Result[witTypes.Unit, StreamError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, StreamError](witTypes.Unit{})
+ case 1:
+ var variant StreamError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_8_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))))
+
+ case 1:
+
+ variant = MakeStreamErrorClosed()
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Unit, StreamError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [method]output-stream.flush
+func wasm_import_method_output_stream_flush(arg0 int32, arg1 uintptr)
+
+func (self *OutputStream) Flush() witTypes.Result[witTypes.Unit, StreamError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4))
+ wasm_import_method_output_stream_flush((self).Handle(), returnArea)
+ var result witTypes.Result[witTypes.Unit, StreamError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, StreamError](witTypes.Unit{})
+ case 1:
+ var variant StreamError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_8_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))))
+
+ case 1:
+
+ variant = MakeStreamErrorClosed()
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Unit, StreamError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [method]output-stream.blocking-flush
+func wasm_import_method_output_stream_blocking_flush(arg0 int32, arg1 uintptr)
+
+func (self *OutputStream) BlockingFlush() witTypes.Result[witTypes.Unit, StreamError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4))
+ wasm_import_method_output_stream_blocking_flush((self).Handle(), returnArea)
+ var result witTypes.Result[witTypes.Unit, StreamError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, StreamError](witTypes.Unit{})
+ case 1:
+ var variant StreamError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_8_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))))
+
+ case 1:
+
+ variant = MakeStreamErrorClosed()
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Unit, StreamError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [method]output-stream.subscribe
+func wasm_import_method_output_stream_subscribe(arg0 int32) int32
+
+func (self *OutputStream) Subscribe() *wasi_io_0_2_8_poll.Pollable {
+
+ result := wasm_import_method_output_stream_subscribe((self).Handle())
+ return wasi_io_0_2_8_poll.PollableFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [method]output-stream.write-zeroes
+func wasm_import_method_output_stream_write_zeroes(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *OutputStream) WriteZeroes(len uint64) witTypes.Result[witTypes.Unit, StreamError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4))
+ wasm_import_method_output_stream_write_zeroes((self).Handle(), int64(len), returnArea)
+ var result witTypes.Result[witTypes.Unit, StreamError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, StreamError](witTypes.Unit{})
+ case 1:
+ var variant StreamError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_8_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))))
+
+ case 1:
+
+ variant = MakeStreamErrorClosed()
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Unit, StreamError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [method]output-stream.blocking-write-zeroes-and-flush
+func wasm_import_method_output_stream_blocking_write_zeroes_and_flush(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *OutputStream) BlockingWriteZeroesAndFlush(len uint64) witTypes.Result[witTypes.Unit, StreamError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4))
+ wasm_import_method_output_stream_blocking_write_zeroes_and_flush((self).Handle(), int64(len), returnArea)
+ var result witTypes.Result[witTypes.Unit, StreamError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, StreamError](witTypes.Unit{})
+ case 1:
+ var variant StreamError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_8_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))))
+
+ case 1:
+
+ variant = MakeStreamErrorClosed()
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[witTypes.Unit, StreamError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [method]output-stream.splice
+func wasm_import_method_output_stream_splice(arg0 int32, arg1 int32, arg2 int64, arg3 uintptr)
+
+func (self *OutputStream) Splice(src *InputStream, len uint64) witTypes.Result[uint64, StreamError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_output_stream_splice((self).Handle(), (src).Handle(), int64(len), returnArea)
+ var result witTypes.Result[uint64, StreamError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ case 1:
+ var variant StreamError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) {
+ case 0:
+
+ variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_8_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))))))
+
+ case 1:
+
+ variant = MakeStreamErrorClosed()
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[uint64, StreamError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:io/streams@0.2.8 [method]output-stream.blocking-splice
+func wasm_import_method_output_stream_blocking_splice(arg0 int32, arg1 int32, arg2 int64, arg3 uintptr)
+
+func (self *OutputStream) BlockingSplice(src *InputStream, len uint64) witTypes.Result[uint64, StreamError] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_output_stream_blocking_splice((self).Handle(), (src).Handle(), int64(len), returnArea)
+ var result witTypes.Result[uint64, StreamError]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ case 1:
+ var variant StreamError
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) {
+ case 0:
+
+ variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_8_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))))))
+
+ case 1:
+
+ variant = MakeStreamErrorClosed()
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Err[uint64, StreamError](variant)
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
diff --git a/imports/wasi_logging_0_1_0_draft_logging/empty.s b/imports/wasi_logging_0_1_0_draft_logging/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_logging_0_1_0_draft_logging/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_logging_0_1_0_draft_logging/wit_bindings.go b/imports/wasi_logging_0_1_0_draft_logging/wit_bindings.go
new file mode 100644
index 0000000..2653406
--- /dev/null
+++ b/imports/wasi_logging_0_1_0_draft_logging/wit_bindings.go
@@ -0,0 +1,63 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_logging_0_1_0_draft_logging
+
+import (
+ "runtime"
+ "unsafe"
+)
+
+const (
+ // Describes messages about the values of variables and the flow of
+ // control within a program.
+ LevelTrace uint8 = 0
+ // Describes messages likely to be of interest to someone debugging a
+ // program.
+ LevelDebug uint8 = 1
+ // Describes messages likely to be of interest to someone monitoring a
+ // program.
+ LevelInfo uint8 = 2
+ // Describes messages indicating hazardous situations.
+ LevelWarn uint8 = 3
+ // Describes messages indicating serious errors.
+ LevelError uint8 = 4
+ // Describes messages indicating fatal errors.
+ LevelCritical uint8 = 5
+)
+
+// A log level, describing a kind of message.
+type Level = uint8
+
+//go:wasmimport wasi:logging/logging@0.1.0-draft log
+func wasm_import_log(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32)
+
+func Log(level Level, context string, message string) {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ utf8 := unsafe.Pointer(unsafe.StringData(context))
+ pinner.Pin(utf8)
+ utf80 := unsafe.Pointer(unsafe.StringData(message))
+ pinner.Pin(utf80)
+ wasm_import_log(int32(level), uintptr(utf8), uint32(len(context)), uintptr(utf80), uint32(len(message)))
+
+}
diff --git a/imports/wasi_random_0_2_8_insecure/empty.s b/imports/wasi_random_0_2_8_insecure/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_random_0_2_8_insecure/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_random_0_2_8_insecure/wit_bindings.go b/imports/wasi_random_0_2_8_insecure/wit_bindings.go
new file mode 100644
index 0000000..ee2869a
--- /dev/null
+++ b/imports/wasi_random_0_2_8_insecure/wit_bindings.go
@@ -0,0 +1,53 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_random_0_2_8_insecure
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ "runtime"
+ "unsafe"
+)
+
+//go:wasmimport wasi:random/insecure@0.2.8 get-insecure-random-bytes
+func wasm_import_get_insecure_random_bytes(arg0 int64, arg1 uintptr)
+
+func GetInsecureRandomBytes(len uint64) []uint8 {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4))
+ wasm_import_get_insecure_random_bytes(int64(len), returnArea)
+ value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
+ result := value
+ return result
+
+}
+
+//go:wasmimport wasi:random/insecure@0.2.8 get-insecure-random-u64
+func wasm_import_get_insecure_random_u64() int64
+
+func GetInsecureRandomU64() uint64 {
+
+ result := wasm_import_get_insecure_random_u64()
+ return uint64(result)
+
+}
diff --git a/imports/wasi_random_0_2_8_insecure_seed/empty.s b/imports/wasi_random_0_2_8_insecure_seed/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_random_0_2_8_insecure_seed/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_random_0_2_8_insecure_seed/wit_bindings.go b/imports/wasi_random_0_2_8_insecure_seed/wit_bindings.go
new file mode 100644
index 0000000..43010b3
--- /dev/null
+++ b/imports/wasi_random_0_2_8_insecure_seed/wit_bindings.go
@@ -0,0 +1,44 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_random_0_2_8_insecure_seed
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+//go:wasmimport wasi:random/insecure-seed@0.2.8 insecure-seed
+func wasm_import_insecure_seed(arg0 uintptr)
+
+func InsecureSeed() (uint64, uint64) {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_insecure_seed(returnArea)
+ result := witTypes.Tuple2[uint64, uint64]{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 0))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))}
+ tuple := result
+ return tuple.F0, tuple.F1
+
+}
diff --git a/imports/wasi_random_0_2_8_random/empty.s b/imports/wasi_random_0_2_8_random/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_random_0_2_8_random/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_random_0_2_8_random/wit_bindings.go b/imports/wasi_random_0_2_8_random/wit_bindings.go
new file mode 100644
index 0000000..c8b0f49
--- /dev/null
+++ b/imports/wasi_random_0_2_8_random/wit_bindings.go
@@ -0,0 +1,53 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_random_0_2_8_random
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ "runtime"
+ "unsafe"
+)
+
+//go:wasmimport wasi:random/random@0.2.8 get-random-bytes
+func wasm_import_get_random_bytes(arg0 int64, arg1 uintptr)
+
+func GetRandomBytes(len uint64) []uint8 {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4))
+ wasm_import_get_random_bytes(int64(len), returnArea)
+ value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
+ result := value
+ return result
+
+}
+
+//go:wasmimport wasi:random/random@0.2.8 get-random-u64
+func wasm_import_get_random_u64() int64
+
+func GetRandomU64() uint64 {
+
+ result := wasm_import_get_random_u64()
+ return uint64(result)
+
+}
diff --git a/imports/wasi_random_0_3_0_insecure/empty.s b/imports/wasi_random_0_3_0_insecure/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_random_0_3_0_insecure/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_random_0_3_0_insecure/wit_bindings.go b/imports/wasi_random_0_3_0_insecure/wit_bindings.go
new file mode 100644
index 0000000..0afa567
--- /dev/null
+++ b/imports/wasi_random_0_3_0_insecure/wit_bindings.go
@@ -0,0 +1,53 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_random_0_3_0_insecure
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ "runtime"
+ "unsafe"
+)
+
+//go:wasmimport wasi:random/insecure@0.3.0 get-insecure-random-bytes
+func wasm_import_get_insecure_random_bytes(arg0 int64, arg1 uintptr)
+
+func GetInsecureRandomBytes(maxLen uint64) []uint8 {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4))
+ wasm_import_get_insecure_random_bytes(int64(maxLen), returnArea)
+ value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
+ result := value
+ return result
+
+}
+
+//go:wasmimport wasi:random/insecure@0.3.0 get-insecure-random-u64
+func wasm_import_get_insecure_random_u64() int64
+
+func GetInsecureRandomU64() uint64 {
+
+ result := wasm_import_get_insecure_random_u64()
+ return uint64(result)
+
+}
diff --git a/imports/wasi_random_0_3_0_insecure_seed/empty.s b/imports/wasi_random_0_3_0_insecure_seed/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_random_0_3_0_insecure_seed/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_random_0_3_0_insecure_seed/wit_bindings.go b/imports/wasi_random_0_3_0_insecure_seed/wit_bindings.go
new file mode 100644
index 0000000..75658d7
--- /dev/null
+++ b/imports/wasi_random_0_3_0_insecure_seed/wit_bindings.go
@@ -0,0 +1,44 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_random_0_3_0_insecure_seed
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+//go:wasmimport wasi:random/insecure-seed@0.3.0 get-insecure-seed
+func wasm_import_get_insecure_seed(arg0 uintptr)
+
+func GetInsecureSeed() (uint64, uint64) {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_get_insecure_seed(returnArea)
+ result := witTypes.Tuple2[uint64, uint64]{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 0))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))}
+ tuple := result
+ return tuple.F0, tuple.F1
+
+}
diff --git a/imports/wasi_random_0_3_0_random/empty.s b/imports/wasi_random_0_3_0_random/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_random_0_3_0_random/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_random_0_3_0_random/wit_bindings.go b/imports/wasi_random_0_3_0_random/wit_bindings.go
new file mode 100644
index 0000000..af4d668
--- /dev/null
+++ b/imports/wasi_random_0_3_0_random/wit_bindings.go
@@ -0,0 +1,53 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_random_0_3_0_random
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ "runtime"
+ "unsafe"
+)
+
+//go:wasmimport wasi:random/random@0.3.0 get-random-bytes
+func wasm_import_get_random_bytes(arg0 int64, arg1 uintptr)
+
+func GetRandomBytes(maxLen uint64) []uint8 {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4))
+ wasm_import_get_random_bytes(int64(maxLen), returnArea)
+ value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
+ result := value
+ return result
+
+}
+
+//go:wasmimport wasi:random/random@0.3.0 get-random-u64
+func wasm_import_get_random_u64() int64
+
+func GetRandomU64() uint64 {
+
+ result := wasm_import_get_random_u64()
+ return uint64(result)
+
+}
diff --git a/imports/wasi_sockets_0_2_8_instance_network/empty.s b/imports/wasi_sockets_0_2_8_instance_network/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_sockets_0_2_8_instance_network/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_sockets_0_2_8_instance_network/wit_bindings.go b/imports/wasi_sockets_0_2_8_instance_network/wit_bindings.go
new file mode 100644
index 0000000..9a21c39
--- /dev/null
+++ b/imports/wasi_sockets_0_2_8_instance_network/wit_bindings.go
@@ -0,0 +1,38 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_sockets_0_2_8_instance_network
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_sockets_0_2_8_network"
+)
+
+type Network = wasi_sockets_0_2_8_network.Network
+
+//go:wasmimport wasi:sockets/instance-network@0.2.8 instance-network
+func wasm_import_instance_network() int32
+
+func InstanceNetwork() *wasi_sockets_0_2_8_network.Network {
+
+ result := wasm_import_instance_network()
+ return wasi_sockets_0_2_8_network.NetworkFromOwnHandle(int32(uintptr(result)))
+
+}
diff --git a/imports/wasi_sockets_0_2_8_ip_name_lookup/empty.s b/imports/wasi_sockets_0_2_8_ip_name_lookup/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_sockets_0_2_8_ip_name_lookup/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_sockets_0_2_8_ip_name_lookup/wit_bindings.go b/imports/wasi_sockets_0_2_8_ip_name_lookup/wit_bindings.go
new file mode 100644
index 0000000..137bf69
--- /dev/null
+++ b/imports/wasi_sockets_0_2_8_ip_name_lookup/wit_bindings.go
@@ -0,0 +1,165 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_sockets_0_2_8_ip_name_lookup
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_poll"
+ "go.bytecodealliance.org/pkg/imports/wasi_sockets_0_2_8_network"
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+type Pollable = wasi_io_0_2_8_poll.Pollable
+type Network = wasi_sockets_0_2_8_network.Network
+type ErrorCode = wasi_sockets_0_2_8_network.ErrorCode
+type IpAddress = wasi_sockets_0_2_8_network.IpAddress
+
+//go:wasmimport wasi:sockets/ip-name-lookup@0.2.8 [resource-drop]resolve-address-stream
+func resourceDropResolveAddressStream(handle int32)
+
+type ResolveAddressStream struct {
+ handle *witRuntime.Handle
+}
+
+func (self *ResolveAddressStream) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *ResolveAddressStream) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *ResolveAddressStream) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *ResolveAddressStream) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropResolveAddressStream(handle)
+ }
+}
+
+func ResolveAddressStreamFromOwnHandle(handleValue int32) *ResolveAddressStream {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &ResolveAddressStream{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropResolveAddressStream(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func ResolveAddressStreamFromBorrowHandle(handleValue int32) *ResolveAddressStream {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &ResolveAddressStream{handle}
+}
+
+//go:wasmimport wasi:sockets/ip-name-lookup@0.2.8 [method]resolve-address-stream.resolve-next-address
+func wasm_import_method_resolve_address_stream_resolve_next_address(arg0 int32, arg1 uintptr)
+
+func (self *ResolveAddressStream) ResolveNextAddress() witTypes.Result[witTypes.Option[wasi_sockets_0_2_8_network.IpAddress], wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 22, 2))
+ wasm_import_method_resolve_address_stream_resolve_next_address((self).Handle(), returnArea)
+ var result witTypes.Result[witTypes.Option[wasi_sockets_0_2_8_network.IpAddress], wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ var option witTypes.Option[wasi_sockets_0_2_8_network.IpAddress]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 2))) {
+ case 0:
+
+ option = witTypes.None[wasi_sockets_0_2_8_network.IpAddress]()
+ case 1:
+ var variant wasi_sockets_0_2_8_network.IpAddress
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = wasi_sockets_0_2_8_network.MakeIpAddressIpv4(witTypes.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 6)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 7)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 9))))})
+
+ case 1:
+
+ variant = wasi_sockets_0_2_8_network.MakeIpAddressIpv6(witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 6)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 14)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))})
+
+ default:
+ panic("unreachable")
+ }
+
+ option = witTypes.Some[wasi_sockets_0_2_8_network.IpAddress](variant)
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Ok[witTypes.Option[wasi_sockets_0_2_8_network.IpAddress], wasi_sockets_0_2_8_network.ErrorCode](option)
+ case 1:
+
+ result = witTypes.Err[witTypes.Option[wasi_sockets_0_2_8_network.IpAddress], wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 2)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/ip-name-lookup@0.2.8 [method]resolve-address-stream.subscribe
+func wasm_import_method_resolve_address_stream_subscribe(arg0 int32) int32
+
+func (self *ResolveAddressStream) Subscribe() *wasi_io_0_2_8_poll.Pollable {
+
+ result := wasm_import_method_resolve_address_stream_subscribe((self).Handle())
+ return wasi_io_0_2_8_poll.PollableFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:sockets/ip-name-lookup@0.2.8 resolve-addresses
+func wasm_import_resolve_addresses(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr)
+
+func ResolveAddresses(network *wasi_sockets_0_2_8_network.Network, name string) witTypes.Result[*ResolveAddressStream, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ utf8 := unsafe.Pointer(unsafe.StringData(name))
+ pinner.Pin(utf8)
+ wasm_import_resolve_addresses((network).Handle(), uintptr(utf8), uint32(len(name)), returnArea)
+ var result witTypes.Result[*ResolveAddressStream, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*ResolveAddressStream, wasi_sockets_0_2_8_network.ErrorCode](ResolveAddressStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+
+ result = witTypes.Err[*ResolveAddressStream, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
diff --git a/imports/wasi_sockets_0_2_8_network/empty.s b/imports/wasi_sockets_0_2_8_network/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_sockets_0_2_8_network/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_sockets_0_2_8_network/wit_bindings.go b/imports/wasi_sockets_0_2_8_network/wit_bindings.go
new file mode 100644
index 0000000..ab4faa3
--- /dev/null
+++ b/imports/wasi_sockets_0_2_8_network/wit_bindings.go
@@ -0,0 +1,247 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_sockets_0_2_8_network
+
+import (
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+)
+
+//go:wasmimport wasi:sockets/network@0.2.8 [resource-drop]network
+func resourceDropNetwork(handle int32)
+
+// An opaque resource that represents access to (a subset of) the network.
+// This enables context-based security for networking.
+// There is no need for this to map 1:1 to a physical network interface.
+type Network struct {
+ handle *witRuntime.Handle
+}
+
+func (self *Network) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *Network) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *Network) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *Network) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropNetwork(handle)
+ }
+}
+
+func NetworkFromOwnHandle(handleValue int32) *Network {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &Network{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropNetwork(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func NetworkFromBorrowHandle(handleValue int32) *Network {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &Network{handle}
+}
+
+const (
+ // Unknown error
+ ErrorCodeUnknown uint8 = 0
+ // Access denied.
+ //
+ // POSIX equivalent: EACCES, EPERM
+ ErrorCodeAccessDenied uint8 = 1
+ // The operation is not supported.
+ //
+ // POSIX equivalent: EOPNOTSUPP
+ ErrorCodeNotSupported uint8 = 2
+ // One of the arguments is invalid.
+ //
+ // POSIX equivalent: EINVAL
+ ErrorCodeInvalidArgument uint8 = 3
+ // Not enough memory to complete the operation.
+ //
+ // POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY
+ ErrorCodeOutOfMemory uint8 = 4
+ // The operation timed out before it could finish completely.
+ ErrorCodeTimeout uint8 = 5
+ // This operation is incompatible with another asynchronous operation that is already in progress.
+ //
+ // POSIX equivalent: EALREADY
+ ErrorCodeConcurrencyConflict uint8 = 6
+ // Trying to finish an asynchronous operation that:
+ // - has not been started yet, or:
+ // - was already finished by a previous `finish-*` call.
+ //
+ // Note: this is scheduled to be removed when `future`s are natively supported.
+ ErrorCodeNotInProgress uint8 = 7
+ // The operation has been aborted because it could not be completed immediately.
+ //
+ // Note: this is scheduled to be removed when `future`s are natively supported.
+ ErrorCodeWouldBlock uint8 = 8
+ // The operation is not valid in the socket's current state.
+ ErrorCodeInvalidState uint8 = 9
+ // A new socket resource could not be created because of a system limit.
+ ErrorCodeNewSocketLimit uint8 = 10
+ // A bind operation failed because the provided address is not an address that the `network` can bind to.
+ ErrorCodeAddressNotBindable uint8 = 11
+ // A bind operation failed because the provided address is already in use or because there are no ephemeral ports available.
+ ErrorCodeAddressInUse uint8 = 12
+ // The remote address is not reachable
+ ErrorCodeRemoteUnreachable uint8 = 13
+ // The TCP connection was forcefully rejected
+ ErrorCodeConnectionRefused uint8 = 14
+ // The TCP connection was reset.
+ ErrorCodeConnectionReset uint8 = 15
+ // A TCP connection was aborted.
+ ErrorCodeConnectionAborted uint8 = 16
+ // The size of a datagram sent to a UDP socket exceeded the maximum
+ // supported size.
+ ErrorCodeDatagramTooLarge uint8 = 17
+ // Name does not exist or has no suitable associated IP addresses.
+ ErrorCodeNameUnresolvable uint8 = 18
+ // A temporary failure in name resolution occurred.
+ ErrorCodeTemporaryResolverFailure uint8 = 19
+ // A permanent failure in name resolution occurred.
+ ErrorCodePermanentResolverFailure uint8 = 20
+)
+
+// Error codes.
+//
+// In theory, every API can return any error code.
+// In practice, API's typically only return the errors documented per API
+// combined with a couple of errors that are always possible:
+// - `unknown`
+// - `access-denied`
+// - `not-supported`
+// - `out-of-memory`
+// - `concurrency-conflict`
+//
+// See each individual API for what the POSIX equivalents are. They sometimes differ per API.
+type ErrorCode = uint8
+
+const (
+ // Similar to `AF_INET` in POSIX.
+ IpAddressFamilyIpv4 uint8 = 0
+ // Similar to `AF_INET6` in POSIX.
+ IpAddressFamilyIpv6 uint8 = 1
+)
+
+type IpAddressFamily = uint8
+type Ipv4Address = witTypes.Tuple4[uint8, uint8, uint8, uint8]
+type Ipv6Address = witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]
+
+const (
+ IpAddressIpv4 uint8 = 0
+ IpAddressIpv6 uint8 = 1
+)
+
+type IpAddress struct {
+ tag uint8
+ value any
+}
+
+func (self IpAddress) Tag() uint8 {
+ return self.tag
+}
+
+func (self IpAddress) Ipv4() witTypes.Tuple4[uint8, uint8, uint8, uint8] {
+ if self.tag != IpAddressIpv4 {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Tuple4[uint8, uint8, uint8, uint8])
+}
+func (self IpAddress) Ipv6() witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16] {
+ if self.tag != IpAddressIpv6 {
+ panic("tag mismatch")
+ }
+ return self.value.(witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16])
+}
+
+func MakeIpAddressIpv4(value witTypes.Tuple4[uint8, uint8, uint8, uint8]) IpAddress {
+ return IpAddress{IpAddressIpv4, value}
+}
+func MakeIpAddressIpv6(value witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]) IpAddress {
+ return IpAddress{IpAddressIpv6, value}
+}
+
+type Ipv4SocketAddress struct {
+ // sin_port
+ Port uint16
+ // sin_addr
+ Address witTypes.Tuple4[uint8, uint8, uint8, uint8]
+}
+
+type Ipv6SocketAddress struct {
+ // sin6_port
+ Port uint16
+ // sin6_flowinfo
+ FlowInfo uint32
+ // sin6_addr
+ Address witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]
+ // sin6_scope_id
+ ScopeId uint32
+}
+
+const (
+ IpSocketAddressIpv4 uint8 = 0
+ IpSocketAddressIpv6 uint8 = 1
+)
+
+type IpSocketAddress struct {
+ tag uint8
+ value any
+}
+
+func (self IpSocketAddress) Tag() uint8 {
+ return self.tag
+}
+
+func (self IpSocketAddress) Ipv4() Ipv4SocketAddress {
+ if self.tag != IpSocketAddressIpv4 {
+ panic("tag mismatch")
+ }
+ return self.value.(Ipv4SocketAddress)
+}
+func (self IpSocketAddress) Ipv6() Ipv6SocketAddress {
+ if self.tag != IpSocketAddressIpv6 {
+ panic("tag mismatch")
+ }
+ return self.value.(Ipv6SocketAddress)
+}
+
+func MakeIpSocketAddressIpv4(value Ipv4SocketAddress) IpSocketAddress {
+ return IpSocketAddress{IpSocketAddressIpv4, value}
+}
+func MakeIpSocketAddressIpv6(value Ipv6SocketAddress) IpSocketAddress {
+ return IpSocketAddress{IpSocketAddressIpv6, value}
+}
diff --git a/imports/wasi_sockets_0_2_8_tcp/empty.s b/imports/wasi_sockets_0_2_8_tcp/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_sockets_0_2_8_tcp/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_sockets_0_2_8_tcp/wit_bindings.go b/imports/wasi_sockets_0_2_8_tcp/wit_bindings.go
new file mode 100644
index 0000000..e802d1b
--- /dev/null
+++ b/imports/wasi_sockets_0_2_8_tcp/wit_bindings.go
@@ -0,0 +1,899 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_sockets_0_2_8_tcp
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_poll"
+ "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_streams"
+ "go.bytecodealliance.org/pkg/imports/wasi_sockets_0_2_8_network"
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+type InputStream = wasi_io_0_2_8_streams.InputStream
+type OutputStream = wasi_io_0_2_8_streams.OutputStream
+type Pollable = wasi_io_0_2_8_poll.Pollable
+type Duration = uint64
+type Network = wasi_sockets_0_2_8_network.Network
+type ErrorCode = wasi_sockets_0_2_8_network.ErrorCode
+type IpSocketAddress = wasi_sockets_0_2_8_network.IpSocketAddress
+type IpAddressFamily = wasi_sockets_0_2_8_network.IpAddressFamily
+
+const (
+ // Similar to `SHUT_RD` in POSIX.
+ ShutdownTypeReceive uint8 = 0
+ // Similar to `SHUT_WR` in POSIX.
+ ShutdownTypeSend uint8 = 1
+ // Similar to `SHUT_RDWR` in POSIX.
+ ShutdownTypeBoth uint8 = 2
+)
+
+type ShutdownType = uint8
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [resource-drop]tcp-socket
+func resourceDropTcpSocket(handle int32)
+
+// A TCP socket resource.
+//
+// The socket can be in one of the following states:
+// - `unbound`
+// - `bind-in-progress`
+// - `bound` (See note below)
+// - `listen-in-progress`
+// - `listening`
+// - `connect-in-progress`
+// - `connected`
+// - `closed`
+// See
+// for more information.
+//
+// Note: Except where explicitly mentioned, whenever this documentation uses
+// the term "bound" without backticks it actually means: in the `bound` state *or higher*.
+// (i.e. `bound`, `listen-in-progress`, `listening`, `connect-in-progress` or `connected`)
+//
+// In addition to the general error codes documented on the
+// `network::error-code` type, TCP socket methods may always return
+// `error(invalid-state)` when in the `closed` state.
+type TcpSocket struct {
+ handle *witRuntime.Handle
+}
+
+func (self *TcpSocket) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *TcpSocket) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *TcpSocket) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *TcpSocket) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropTcpSocket(handle)
+ }
+}
+
+func TcpSocketFromOwnHandle(handleValue int32) *TcpSocket {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &TcpSocket{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropTcpSocket(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func TcpSocketFromBorrowHandle(handleValue int32) *TcpSocket {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &TcpSocket{handle}
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.start-bind
+func wasm_import_method_tcp_socket_start_bind(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int32, arg5 int32, arg6 int32, arg7 int32, arg8 int32, arg9 int32, arg10 int32, arg11 int32, arg12 int32, arg13 int32, arg14 uintptr)
+
+func (self *TcpSocket) StartBind(network *wasi_sockets_0_2_8_network.Network, localAddress wasi_sockets_0_2_8_network.IpSocketAddress) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ var variant int32
+ var variant0 int32
+ var variant1 int32
+ var variant2 int32
+ var variant3 int32
+ var variant4 int32
+ var variant5 int32
+ var variant6 int32
+ var variant7 int32
+ var variant8 int32
+ var variant9 int32
+ var variant10 int32
+ switch localAddress.Tag() {
+ case wasi_sockets_0_2_8_network.IpSocketAddressIpv4:
+ payload := localAddress.Ipv4()
+
+ variant = int32(0)
+ variant0 = int32((payload).Port)
+ variant1 = int32(((payload).Address).F0)
+ variant2 = int32(((payload).Address).F1)
+ variant3 = int32(((payload).Address).F2)
+ variant4 = int32(((payload).Address).F3)
+ variant5 = 0
+ variant6 = 0
+ variant7 = 0
+ variant8 = 0
+ variant9 = 0
+ variant10 = 0
+
+ case wasi_sockets_0_2_8_network.IpSocketAddressIpv6:
+ payload := localAddress.Ipv6()
+
+ variant = int32(1)
+ variant0 = int32((payload).Port)
+ variant1 = int32((payload).FlowInfo)
+ variant2 = int32(((payload).Address).F0)
+ variant3 = int32(((payload).Address).F1)
+ variant4 = int32(((payload).Address).F2)
+ variant5 = int32(((payload).Address).F3)
+ variant6 = int32(((payload).Address).F4)
+ variant7 = int32(((payload).Address).F5)
+ variant8 = int32(((payload).Address).F6)
+ variant9 = int32(((payload).Address).F7)
+ variant10 = int32((payload).ScopeId)
+
+ default:
+ panic("unreachable")
+ }
+ wasm_import_method_tcp_socket_start_bind((self).Handle(), (network).Handle(), variant, variant0, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result11 := result
+ return result11
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.finish-bind
+func wasm_import_method_tcp_socket_finish_bind(arg0 int32, arg1 uintptr)
+
+func (self *TcpSocket) FinishBind() witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_tcp_socket_finish_bind((self).Handle(), returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.start-connect
+func wasm_import_method_tcp_socket_start_connect(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int32, arg5 int32, arg6 int32, arg7 int32, arg8 int32, arg9 int32, arg10 int32, arg11 int32, arg12 int32, arg13 int32, arg14 uintptr)
+
+func (self *TcpSocket) StartConnect(network *wasi_sockets_0_2_8_network.Network, remoteAddress wasi_sockets_0_2_8_network.IpSocketAddress) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ var variant int32
+ var variant0 int32
+ var variant1 int32
+ var variant2 int32
+ var variant3 int32
+ var variant4 int32
+ var variant5 int32
+ var variant6 int32
+ var variant7 int32
+ var variant8 int32
+ var variant9 int32
+ var variant10 int32
+ switch remoteAddress.Tag() {
+ case wasi_sockets_0_2_8_network.IpSocketAddressIpv4:
+ payload := remoteAddress.Ipv4()
+
+ variant = int32(0)
+ variant0 = int32((payload).Port)
+ variant1 = int32(((payload).Address).F0)
+ variant2 = int32(((payload).Address).F1)
+ variant3 = int32(((payload).Address).F2)
+ variant4 = int32(((payload).Address).F3)
+ variant5 = 0
+ variant6 = 0
+ variant7 = 0
+ variant8 = 0
+ variant9 = 0
+ variant10 = 0
+
+ case wasi_sockets_0_2_8_network.IpSocketAddressIpv6:
+ payload := remoteAddress.Ipv6()
+
+ variant = int32(1)
+ variant0 = int32((payload).Port)
+ variant1 = int32((payload).FlowInfo)
+ variant2 = int32(((payload).Address).F0)
+ variant3 = int32(((payload).Address).F1)
+ variant4 = int32(((payload).Address).F2)
+ variant5 = int32(((payload).Address).F3)
+ variant6 = int32(((payload).Address).F4)
+ variant7 = int32(((payload).Address).F5)
+ variant8 = int32(((payload).Address).F6)
+ variant9 = int32(((payload).Address).F7)
+ variant10 = int32((payload).ScopeId)
+
+ default:
+ panic("unreachable")
+ }
+ wasm_import_method_tcp_socket_start_connect((self).Handle(), (network).Handle(), variant, variant0, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result11 := result
+ return result11
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.finish-connect
+func wasm_import_method_tcp_socket_finish_connect(arg0 int32, arg1 uintptr)
+
+func (self *TcpSocket) FinishConnect() witTypes.Result[witTypes.Tuple2[*wasi_io_0_2_8_streams.InputStream, *wasi_io_0_2_8_streams.OutputStream], wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4))
+ wasm_import_method_tcp_socket_finish_connect((self).Handle(), returnArea)
+ var result witTypes.Result[witTypes.Tuple2[*wasi_io_0_2_8_streams.InputStream, *wasi_io_0_2_8_streams.OutputStream], wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Tuple2[*wasi_io_0_2_8_streams.InputStream, *wasi_io_0_2_8_streams.OutputStream], wasi_sockets_0_2_8_network.ErrorCode](witTypes.Tuple2[*wasi_io_0_2_8_streams.InputStream, *wasi_io_0_2_8_streams.OutputStream]{wasi_io_0_2_8_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), wasi_io_0_2_8_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))})
+ case 1:
+
+ result = witTypes.Err[witTypes.Tuple2[*wasi_io_0_2_8_streams.InputStream, *wasi_io_0_2_8_streams.OutputStream], wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.start-listen
+func wasm_import_method_tcp_socket_start_listen(arg0 int32, arg1 uintptr)
+
+func (self *TcpSocket) StartListen() witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_tcp_socket_start_listen((self).Handle(), returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.finish-listen
+func wasm_import_method_tcp_socket_finish_listen(arg0 int32, arg1 uintptr)
+
+func (self *TcpSocket) FinishListen() witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_tcp_socket_finish_listen((self).Handle(), returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.accept
+func wasm_import_method_tcp_socket_accept(arg0 int32, arg1 uintptr)
+
+func (self *TcpSocket) Accept() witTypes.Result[witTypes.Tuple3[*TcpSocket, *wasi_io_0_2_8_streams.InputStream, *wasi_io_0_2_8_streams.OutputStream], wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 4))
+ wasm_import_method_tcp_socket_accept((self).Handle(), returnArea)
+ var result witTypes.Result[witTypes.Tuple3[*TcpSocket, *wasi_io_0_2_8_streams.InputStream, *wasi_io_0_2_8_streams.OutputStream], wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Tuple3[*TcpSocket, *wasi_io_0_2_8_streams.InputStream, *wasi_io_0_2_8_streams.OutputStream], wasi_sockets_0_2_8_network.ErrorCode](witTypes.Tuple3[*TcpSocket, *wasi_io_0_2_8_streams.InputStream, *wasi_io_0_2_8_streams.OutputStream]{TcpSocketFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), wasi_io_0_2_8_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))), wasi_io_0_2_8_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))))})
+ case 1:
+
+ result = witTypes.Err[witTypes.Tuple3[*TcpSocket, *wasi_io_0_2_8_streams.InputStream, *wasi_io_0_2_8_streams.OutputStream], wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.local-address
+func wasm_import_method_tcp_socket_local_address(arg0 int32, arg1 uintptr)
+
+func (self *TcpSocket) LocalAddress() witTypes.Result[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 36, 4))
+ wasm_import_method_tcp_socket_local_address((self).Handle(), returnArea)
+ var result witTypes.Result[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ var variant wasi_sockets_0_2_8_network.IpSocketAddress
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = wasi_sockets_0_2_8_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_8_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), witTypes.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}})
+
+ case 1:
+
+ variant = wasi_sockets_0_2_8_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_8_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))})
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Ok[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode](variant)
+ case 1:
+
+ result = witTypes.Err[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.remote-address
+func wasm_import_method_tcp_socket_remote_address(arg0 int32, arg1 uintptr)
+
+func (self *TcpSocket) RemoteAddress() witTypes.Result[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 36, 4))
+ wasm_import_method_tcp_socket_remote_address((self).Handle(), returnArea)
+ var result witTypes.Result[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ var variant wasi_sockets_0_2_8_network.IpSocketAddress
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = wasi_sockets_0_2_8_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_8_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), witTypes.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}})
+
+ case 1:
+
+ variant = wasi_sockets_0_2_8_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_8_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))})
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Ok[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode](variant)
+ case 1:
+
+ result = witTypes.Err[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.is-listening
+func wasm_import_method_tcp_socket_is_listening(arg0 int32) int32
+
+func (self *TcpSocket) IsListening() bool {
+
+ result := wasm_import_method_tcp_socket_is_listening((self).Handle())
+ return (result != 0)
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.address-family
+func wasm_import_method_tcp_socket_address_family(arg0 int32) int32
+
+func (self *TcpSocket) AddressFamily() wasi_sockets_0_2_8_network.IpAddressFamily {
+
+ result := wasm_import_method_tcp_socket_address_family((self).Handle())
+ return uint8(result)
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.set-listen-backlog-size
+func wasm_import_method_tcp_socket_set_listen_backlog_size(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *TcpSocket) SetListenBacklogSize(value uint64) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_tcp_socket_set_listen_backlog_size((self).Handle(), int64(value), returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.keep-alive-enabled
+func wasm_import_method_tcp_socket_keep_alive_enabled(arg0 int32, arg1 uintptr)
+
+func (self *TcpSocket) KeepAliveEnabled() witTypes.Result[bool, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_tcp_socket_keep_alive_enabled((self).Handle(), returnArea)
+ var result witTypes.Result[bool, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[bool, wasi_sockets_0_2_8_network.ErrorCode]((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))) != 0))
+ case 1:
+
+ result = witTypes.Err[bool, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.set-keep-alive-enabled
+func wasm_import_method_tcp_socket_set_keep_alive_enabled(arg0 int32, arg1 int32, arg2 uintptr)
+
+func (self *TcpSocket) SetKeepAliveEnabled(value bool) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ var result int32
+ if value {
+ result = 1
+ } else {
+ result = 0
+ }
+ wasm_import_method_tcp_socket_set_keep_alive_enabled((self).Handle(), result, returnArea)
+ var result0 witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result0 = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result0 = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result1 := result0
+ return result1
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.keep-alive-idle-time
+func wasm_import_method_tcp_socket_keep_alive_idle_time(arg0 int32, arg1 uintptr)
+
+func (self *TcpSocket) KeepAliveIdleTime() witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_tcp_socket_keep_alive_idle_time((self).Handle(), returnArea)
+ var result witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ case 1:
+
+ result = witTypes.Err[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.set-keep-alive-idle-time
+func wasm_import_method_tcp_socket_set_keep_alive_idle_time(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *TcpSocket) SetKeepAliveIdleTime(value uint64) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_tcp_socket_set_keep_alive_idle_time((self).Handle(), int64(value), returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.keep-alive-interval
+func wasm_import_method_tcp_socket_keep_alive_interval(arg0 int32, arg1 uintptr)
+
+func (self *TcpSocket) KeepAliveInterval() witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_tcp_socket_keep_alive_interval((self).Handle(), returnArea)
+ var result witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ case 1:
+
+ result = witTypes.Err[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.set-keep-alive-interval
+func wasm_import_method_tcp_socket_set_keep_alive_interval(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *TcpSocket) SetKeepAliveInterval(value uint64) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_tcp_socket_set_keep_alive_interval((self).Handle(), int64(value), returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.keep-alive-count
+func wasm_import_method_tcp_socket_keep_alive_count(arg0 int32, arg1 uintptr)
+
+func (self *TcpSocket) KeepAliveCount() witTypes.Result[uint32, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_method_tcp_socket_keep_alive_count((self).Handle(), returnArea)
+ var result witTypes.Result[uint32, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint32, wasi_sockets_0_2_8_network.ErrorCode](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))
+ case 1:
+
+ result = witTypes.Err[uint32, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.set-keep-alive-count
+func wasm_import_method_tcp_socket_set_keep_alive_count(arg0 int32, arg1 int32, arg2 uintptr)
+
+func (self *TcpSocket) SetKeepAliveCount(value uint32) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_tcp_socket_set_keep_alive_count((self).Handle(), int32(value), returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.hop-limit
+func wasm_import_method_tcp_socket_hop_limit(arg0 int32, arg1 uintptr)
+
+func (self *TcpSocket) HopLimit() witTypes.Result[uint8, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_tcp_socket_hop_limit((self).Handle(), returnArea)
+ var result witTypes.Result[uint8, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint8, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ case 1:
+
+ result = witTypes.Err[uint8, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.set-hop-limit
+func wasm_import_method_tcp_socket_set_hop_limit(arg0 int32, arg1 int32, arg2 uintptr)
+
+func (self *TcpSocket) SetHopLimit(value uint8) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_tcp_socket_set_hop_limit((self).Handle(), int32(value), returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.receive-buffer-size
+func wasm_import_method_tcp_socket_receive_buffer_size(arg0 int32, arg1 uintptr)
+
+func (self *TcpSocket) ReceiveBufferSize() witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_tcp_socket_receive_buffer_size((self).Handle(), returnArea)
+ var result witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ case 1:
+
+ result = witTypes.Err[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.set-receive-buffer-size
+func wasm_import_method_tcp_socket_set_receive_buffer_size(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *TcpSocket) SetReceiveBufferSize(value uint64) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_tcp_socket_set_receive_buffer_size((self).Handle(), int64(value), returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.send-buffer-size
+func wasm_import_method_tcp_socket_send_buffer_size(arg0 int32, arg1 uintptr)
+
+func (self *TcpSocket) SendBufferSize() witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_tcp_socket_send_buffer_size((self).Handle(), returnArea)
+ var result witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ case 1:
+
+ result = witTypes.Err[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.set-send-buffer-size
+func wasm_import_method_tcp_socket_set_send_buffer_size(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *TcpSocket) SetSendBufferSize(value uint64) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_tcp_socket_set_send_buffer_size((self).Handle(), int64(value), returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.subscribe
+func wasm_import_method_tcp_socket_subscribe(arg0 int32) int32
+
+func (self *TcpSocket) Subscribe() *wasi_io_0_2_8_poll.Pollable {
+
+ result := wasm_import_method_tcp_socket_subscribe((self).Handle())
+ return wasi_io_0_2_8_poll.PollableFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:sockets/tcp@0.2.8 [method]tcp-socket.shutdown
+func wasm_import_method_tcp_socket_shutdown(arg0 int32, arg1 int32, arg2 uintptr)
+
+func (self *TcpSocket) Shutdown(shutdownType ShutdownType) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_tcp_socket_shutdown((self).Handle(), int32(shutdownType), returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
diff --git a/imports/wasi_sockets_0_2_8_tcp_create_socket/empty.s b/imports/wasi_sockets_0_2_8_tcp_create_socket/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_sockets_0_2_8_tcp_create_socket/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_sockets_0_2_8_tcp_create_socket/wit_bindings.go b/imports/wasi_sockets_0_2_8_tcp_create_socket/wit_bindings.go
new file mode 100644
index 0000000..9f6ea38
--- /dev/null
+++ b/imports/wasi_sockets_0_2_8_tcp_create_socket/wit_bindings.go
@@ -0,0 +1,61 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_sockets_0_2_8_tcp_create_socket
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_sockets_0_2_8_network"
+ "go.bytecodealliance.org/pkg/imports/wasi_sockets_0_2_8_tcp"
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+type Network = wasi_sockets_0_2_8_network.Network
+type ErrorCode = wasi_sockets_0_2_8_network.ErrorCode
+type IpAddressFamily = wasi_sockets_0_2_8_network.IpAddressFamily
+type TcpSocket = wasi_sockets_0_2_8_tcp.TcpSocket
+
+//go:wasmimport wasi:sockets/tcp-create-socket@0.2.8 create-tcp-socket
+func wasm_import_create_tcp_socket(arg0 int32, arg1 uintptr)
+
+func CreateTcpSocket(addressFamily wasi_sockets_0_2_8_network.IpAddressFamily) witTypes.Result[*wasi_sockets_0_2_8_tcp.TcpSocket, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_create_tcp_socket(int32(addressFamily), returnArea)
+ var result witTypes.Result[*wasi_sockets_0_2_8_tcp.TcpSocket, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*wasi_sockets_0_2_8_tcp.TcpSocket, wasi_sockets_0_2_8_network.ErrorCode](wasi_sockets_0_2_8_tcp.TcpSocketFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+
+ result = witTypes.Err[*wasi_sockets_0_2_8_tcp.TcpSocket, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
diff --git a/imports/wasi_sockets_0_2_8_udp/empty.s b/imports/wasi_sockets_0_2_8_udp/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_sockets_0_2_8_udp/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_sockets_0_2_8_udp/wit_bindings.go b/imports/wasi_sockets_0_2_8_udp/wit_bindings.go
new file mode 100644
index 0000000..96338bd
--- /dev/null
+++ b/imports/wasi_sockets_0_2_8_udp/wit_bindings.go
@@ -0,0 +1,828 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_sockets_0_2_8_udp
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_poll"
+ "go.bytecodealliance.org/pkg/imports/wasi_sockets_0_2_8_network"
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+type Pollable = wasi_io_0_2_8_poll.Pollable
+type Network = wasi_sockets_0_2_8_network.Network
+type ErrorCode = wasi_sockets_0_2_8_network.ErrorCode
+type IpSocketAddress = wasi_sockets_0_2_8_network.IpSocketAddress
+type IpAddressFamily = wasi_sockets_0_2_8_network.IpAddressFamily
+
+// A received datagram.
+type IncomingDatagram struct {
+ // The payload.
+ //
+ // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes.
+ Data []uint8
+ // The source address.
+ //
+ // This field is guaranteed to match the remote address the stream was initialized with, if any.
+ //
+ // Equivalent to the `src_addr` out parameter of `recvfrom`.
+ RemoteAddress wasi_sockets_0_2_8_network.IpSocketAddress
+}
+
+// A datagram to be sent out.
+type OutgoingDatagram struct {
+ // The payload.
+ Data []uint8
+ // The destination address.
+ //
+ // The requirements on this field depend on how the stream was initialized:
+ // - with a remote address: this field must be None or match the stream's remote address exactly.
+ // - without a remote address: this field is required.
+ //
+ // If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise it is equivalent to `sendto`.
+ RemoteAddress witTypes.Option[wasi_sockets_0_2_8_network.IpSocketAddress]
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [resource-drop]udp-socket
+func resourceDropUdpSocket(handle int32)
+
+// A UDP socket handle.
+type UdpSocket struct {
+ handle *witRuntime.Handle
+}
+
+func (self *UdpSocket) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *UdpSocket) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *UdpSocket) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *UdpSocket) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropUdpSocket(handle)
+ }
+}
+
+func UdpSocketFromOwnHandle(handleValue int32) *UdpSocket {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &UdpSocket{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropUdpSocket(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func UdpSocketFromBorrowHandle(handleValue int32) *UdpSocket {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &UdpSocket{handle}
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [resource-drop]incoming-datagram-stream
+func resourceDropIncomingDatagramStream(handle int32)
+
+type IncomingDatagramStream struct {
+ handle *witRuntime.Handle
+}
+
+func (self *IncomingDatagramStream) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *IncomingDatagramStream) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *IncomingDatagramStream) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *IncomingDatagramStream) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropIncomingDatagramStream(handle)
+ }
+}
+
+func IncomingDatagramStreamFromOwnHandle(handleValue int32) *IncomingDatagramStream {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &IncomingDatagramStream{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropIncomingDatagramStream(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func IncomingDatagramStreamFromBorrowHandle(handleValue int32) *IncomingDatagramStream {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &IncomingDatagramStream{handle}
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [resource-drop]outgoing-datagram-stream
+func resourceDropOutgoingDatagramStream(handle int32)
+
+type OutgoingDatagramStream struct {
+ handle *witRuntime.Handle
+}
+
+func (self *OutgoingDatagramStream) TakeHandle() int32 {
+ return self.handle.Take()
+}
+
+func (self *OutgoingDatagramStream) SetHandle(handle int32) {
+ self.handle.Set(handle)
+}
+
+func (self *OutgoingDatagramStream) Handle() int32 {
+ return self.handle.Use()
+}
+
+func (self *OutgoingDatagramStream) Drop() {
+ handle := self.handle.TakeOrNil()
+ if handle != 0 {
+ resourceDropOutgoingDatagramStream(handle)
+ }
+}
+
+func OutgoingDatagramStreamFromOwnHandle(handleValue int32) *OutgoingDatagramStream {
+ handle := witRuntime.MakeHandle(handleValue)
+ value := &OutgoingDatagramStream{handle}
+ runtime.AddCleanup(value, func(_ int) {
+ handleValue := handle.TakeOrNil()
+ if handleValue != 0 {
+ resourceDropOutgoingDatagramStream(handleValue)
+ }
+ }, 0)
+ return value
+}
+
+func OutgoingDatagramStreamFromBorrowHandle(handleValue int32) *OutgoingDatagramStream {
+ handle := witRuntime.MakeHandle(handleValue)
+ return &OutgoingDatagramStream{handle}
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]udp-socket.start-bind
+func wasm_import_method_udp_socket_start_bind(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int32, arg5 int32, arg6 int32, arg7 int32, arg8 int32, arg9 int32, arg10 int32, arg11 int32, arg12 int32, arg13 int32, arg14 uintptr)
+
+func (self *UdpSocket) StartBind(network *wasi_sockets_0_2_8_network.Network, localAddress wasi_sockets_0_2_8_network.IpSocketAddress) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ var variant int32
+ var variant0 int32
+ var variant1 int32
+ var variant2 int32
+ var variant3 int32
+ var variant4 int32
+ var variant5 int32
+ var variant6 int32
+ var variant7 int32
+ var variant8 int32
+ var variant9 int32
+ var variant10 int32
+ switch localAddress.Tag() {
+ case wasi_sockets_0_2_8_network.IpSocketAddressIpv4:
+ payload := localAddress.Ipv4()
+
+ variant = int32(0)
+ variant0 = int32((payload).Port)
+ variant1 = int32(((payload).Address).F0)
+ variant2 = int32(((payload).Address).F1)
+ variant3 = int32(((payload).Address).F2)
+ variant4 = int32(((payload).Address).F3)
+ variant5 = 0
+ variant6 = 0
+ variant7 = 0
+ variant8 = 0
+ variant9 = 0
+ variant10 = 0
+
+ case wasi_sockets_0_2_8_network.IpSocketAddressIpv6:
+ payload := localAddress.Ipv6()
+
+ variant = int32(1)
+ variant0 = int32((payload).Port)
+ variant1 = int32((payload).FlowInfo)
+ variant2 = int32(((payload).Address).F0)
+ variant3 = int32(((payload).Address).F1)
+ variant4 = int32(((payload).Address).F2)
+ variant5 = int32(((payload).Address).F3)
+ variant6 = int32(((payload).Address).F4)
+ variant7 = int32(((payload).Address).F5)
+ variant8 = int32(((payload).Address).F6)
+ variant9 = int32(((payload).Address).F7)
+ variant10 = int32((payload).ScopeId)
+
+ default:
+ panic("unreachable")
+ }
+ wasm_import_method_udp_socket_start_bind((self).Handle(), (network).Handle(), variant, variant0, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result11 := result
+ return result11
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]udp-socket.finish-bind
+func wasm_import_method_udp_socket_finish_bind(arg0 int32, arg1 uintptr)
+
+func (self *UdpSocket) FinishBind() witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_udp_socket_finish_bind((self).Handle(), returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]udp-socket.stream
+func wasm_import_method_udp_socket_stream(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int32, arg5 int32, arg6 int32, arg7 int32, arg8 int32, arg9 int32, arg10 int32, arg11 int32, arg12 int32, arg13 int32, arg14 uintptr)
+
+func (self *UdpSocket) Stream(remoteAddress witTypes.Option[wasi_sockets_0_2_8_network.IpSocketAddress]) witTypes.Result[witTypes.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4))
+ var option int32
+ var option11 int32
+ var option12 int32
+ var option13 int32
+ var option14 int32
+ var option15 int32
+ var option16 int32
+ var option17 int32
+ var option18 int32
+ var option19 int32
+ var option20 int32
+ var option21 int32
+ var option22 int32
+ switch remoteAddress.Tag() {
+ case witTypes.OptionNone:
+
+ option = int32(0)
+ option11 = 0
+ option12 = 0
+ option13 = 0
+ option14 = 0
+ option15 = 0
+ option16 = 0
+ option17 = 0
+ option18 = 0
+ option19 = 0
+ option20 = 0
+ option21 = 0
+ option22 = 0
+ case witTypes.OptionSome:
+ payload := remoteAddress.Some()
+ var variant int32
+ var variant0 int32
+ var variant1 int32
+ var variant2 int32
+ var variant3 int32
+ var variant4 int32
+ var variant5 int32
+ var variant6 int32
+ var variant7 int32
+ var variant8 int32
+ var variant9 int32
+ var variant10 int32
+ switch payload.Tag() {
+ case wasi_sockets_0_2_8_network.IpSocketAddressIpv4:
+ payload := payload.Ipv4()
+
+ variant = int32(0)
+ variant0 = int32((payload).Port)
+ variant1 = int32(((payload).Address).F0)
+ variant2 = int32(((payload).Address).F1)
+ variant3 = int32(((payload).Address).F2)
+ variant4 = int32(((payload).Address).F3)
+ variant5 = 0
+ variant6 = 0
+ variant7 = 0
+ variant8 = 0
+ variant9 = 0
+ variant10 = 0
+
+ case wasi_sockets_0_2_8_network.IpSocketAddressIpv6:
+ payload := payload.Ipv6()
+
+ variant = int32(1)
+ variant0 = int32((payload).Port)
+ variant1 = int32((payload).FlowInfo)
+ variant2 = int32(((payload).Address).F0)
+ variant3 = int32(((payload).Address).F1)
+ variant4 = int32(((payload).Address).F2)
+ variant5 = int32(((payload).Address).F3)
+ variant6 = int32(((payload).Address).F4)
+ variant7 = int32(((payload).Address).F5)
+ variant8 = int32(((payload).Address).F6)
+ variant9 = int32(((payload).Address).F7)
+ variant10 = int32((payload).ScopeId)
+
+ default:
+ panic("unreachable")
+ }
+
+ option = int32(1)
+ option11 = variant
+ option12 = variant0
+ option13 = variant1
+ option14 = variant2
+ option15 = variant3
+ option16 = variant4
+ option17 = variant5
+ option18 = variant6
+ option19 = variant7
+ option20 = variant8
+ option21 = variant9
+ option22 = variant10
+ default:
+ panic("unreachable")
+ }
+ wasm_import_method_udp_socket_stream((self).Handle(), option, option11, option12, option13, option14, option15, option16, option17, option18, option19, option20, option21, option22, returnArea)
+ var result witTypes.Result[witTypes.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_8_network.ErrorCode](witTypes.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream]{IncomingDatagramStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), OutgoingDatagramStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))})
+ case 1:
+
+ result = witTypes.Err[witTypes.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result23 := result
+ return result23
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]udp-socket.local-address
+func wasm_import_method_udp_socket_local_address(arg0 int32, arg1 uintptr)
+
+func (self *UdpSocket) LocalAddress() witTypes.Result[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 36, 4))
+ wasm_import_method_udp_socket_local_address((self).Handle(), returnArea)
+ var result witTypes.Result[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ var variant wasi_sockets_0_2_8_network.IpSocketAddress
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = wasi_sockets_0_2_8_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_8_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), witTypes.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}})
+
+ case 1:
+
+ variant = wasi_sockets_0_2_8_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_8_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))})
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Ok[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode](variant)
+ case 1:
+
+ result = witTypes.Err[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]udp-socket.remote-address
+func wasm_import_method_udp_socket_remote_address(arg0 int32, arg1 uintptr)
+
+func (self *UdpSocket) RemoteAddress() witTypes.Result[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 36, 4))
+ wasm_import_method_udp_socket_remote_address((self).Handle(), returnArea)
+ var result witTypes.Result[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ var variant wasi_sockets_0_2_8_network.IpSocketAddress
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) {
+ case 0:
+
+ variant = wasi_sockets_0_2_8_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_8_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), witTypes.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}})
+
+ case 1:
+
+ variant = wasi_sockets_0_2_8_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_8_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))})
+
+ default:
+ panic("unreachable")
+ }
+
+ result = witTypes.Ok[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode](variant)
+ case 1:
+
+ result = witTypes.Err[wasi_sockets_0_2_8_network.IpSocketAddress, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]udp-socket.address-family
+func wasm_import_method_udp_socket_address_family(arg0 int32) int32
+
+func (self *UdpSocket) AddressFamily() wasi_sockets_0_2_8_network.IpAddressFamily {
+
+ result := wasm_import_method_udp_socket_address_family((self).Handle())
+ return uint8(result)
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]udp-socket.unicast-hop-limit
+func wasm_import_method_udp_socket_unicast_hop_limit(arg0 int32, arg1 uintptr)
+
+func (self *UdpSocket) UnicastHopLimit() witTypes.Result[uint8, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_udp_socket_unicast_hop_limit((self).Handle(), returnArea)
+ var result witTypes.Result[uint8, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint8, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ case 1:
+
+ result = witTypes.Err[uint8, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]udp-socket.set-unicast-hop-limit
+func wasm_import_method_udp_socket_set_unicast_hop_limit(arg0 int32, arg1 int32, arg2 uintptr)
+
+func (self *UdpSocket) SetUnicastHopLimit(value uint8) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_udp_socket_set_unicast_hop_limit((self).Handle(), int32(value), returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]udp-socket.receive-buffer-size
+func wasm_import_method_udp_socket_receive_buffer_size(arg0 int32, arg1 uintptr)
+
+func (self *UdpSocket) ReceiveBufferSize() witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_udp_socket_receive_buffer_size((self).Handle(), returnArea)
+ var result witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ case 1:
+
+ result = witTypes.Err[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]udp-socket.set-receive-buffer-size
+func wasm_import_method_udp_socket_set_receive_buffer_size(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *UdpSocket) SetReceiveBufferSize(value uint64) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_udp_socket_set_receive_buffer_size((self).Handle(), int64(value), returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]udp-socket.send-buffer-size
+func wasm_import_method_udp_socket_send_buffer_size(arg0 int32, arg1 uintptr)
+
+func (self *UdpSocket) SendBufferSize() witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_udp_socket_send_buffer_size((self).Handle(), returnArea)
+ var result witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ case 1:
+
+ result = witTypes.Err[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]udp-socket.set-send-buffer-size
+func wasm_import_method_udp_socket_set_send_buffer_size(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *UdpSocket) SetSendBufferSize(value uint64) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1))
+ wasm_import_method_udp_socket_set_send_buffer_size((self).Handle(), int64(value), returnArea)
+ var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](witTypes.Unit{})
+ case 1:
+
+ result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]udp-socket.subscribe
+func wasm_import_method_udp_socket_subscribe(arg0 int32) int32
+
+func (self *UdpSocket) Subscribe() *wasi_io_0_2_8_poll.Pollable {
+
+ result := wasm_import_method_udp_socket_subscribe((self).Handle())
+ return wasi_io_0_2_8_poll.PollableFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]incoming-datagram-stream.receive
+func wasm_import_method_incoming_datagram_stream_receive(arg0 int32, arg1 int64, arg2 uintptr)
+
+func (self *IncomingDatagramStream) Receive(maxResults uint64) witTypes.Result[[]IncomingDatagram, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4))
+ wasm_import_method_incoming_datagram_stream_receive((self).Handle(), int64(maxResults), returnArea)
+ var result0 witTypes.Result[[]IncomingDatagram, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+ result := make([]IncomingDatagram, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))
+ for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ {
+ base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(32+2*4))
+ value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)))
+ var variant wasi_sockets_0_2_8_network.IpSocketAddress
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))) {
+ case 0:
+
+ variant = wasi_sockets_0_2_8_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_8_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (4 + 2*4))))), witTypes.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (6 + 2*4))))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (7 + 2*4))))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 2*4))))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (9 + 2*4)))))}})
+
+ case 1:
+
+ variant = wasi_sockets_0_2_8_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_8_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (4 + 2*4))))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), (8 + 2*4)))), witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (12 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (14 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (16 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (18 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (20 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (22 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (24 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (26 + 2*4)))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), (28 + 2*4))))})
+
+ default:
+ panic("unreachable")
+ }
+
+ result = append(result, IncomingDatagram{value, variant})
+ }
+
+ result0 = witTypes.Ok[[]IncomingDatagram, wasi_sockets_0_2_8_network.ErrorCode](result)
+ case 1:
+
+ result0 = witTypes.Err[[]IncomingDatagram, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result1 := result0
+ return result1
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]incoming-datagram-stream.subscribe
+func wasm_import_method_incoming_datagram_stream_subscribe(arg0 int32) int32
+
+func (self *IncomingDatagramStream) Subscribe() *wasi_io_0_2_8_poll.Pollable {
+
+ result := wasm_import_method_incoming_datagram_stream_subscribe((self).Handle())
+ return wasi_io_0_2_8_poll.PollableFromOwnHandle(int32(uintptr(result)))
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]outgoing-datagram-stream.check-send
+func wasm_import_method_outgoing_datagram_stream_check_send(arg0 int32, arg1 uintptr)
+
+func (self *OutgoingDatagramStream) CheckSend() witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ wasm_import_method_outgoing_datagram_stream_check_send((self).Handle(), returnArea)
+ var result witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ case 1:
+
+ result = witTypes.Err[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]outgoing-datagram-stream.send
+func wasm_import_method_outgoing_datagram_stream_send(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr)
+
+func (self *OutgoingDatagramStream) Send(datagrams []OutgoingDatagram) witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8))
+ slice := datagrams
+ length := uint32(len(slice))
+ result := witRuntime.Allocate(pinner, uintptr(length*(32+3*4)), 4)
+ for index, element := range slice {
+ base := unsafe.Add(result, index*(32+3*4))
+ data := unsafe.Pointer(unsafe.SliceData((element).Data))
+ pinner.Pin(data)
+ *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len((element).Data)))
+ *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(data)))
+
+ switch (element).RemoteAddress.Tag() {
+ case witTypes.OptionNone:
+ *(*int8)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = int8(int32(0))
+
+ case witTypes.OptionSome:
+ payload := (element).RemoteAddress.Some()
+ *(*int8)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = int8(int32(1))
+
+ switch payload.Tag() {
+ case wasi_sockets_0_2_8_network.IpSocketAddressIpv4:
+ payload := payload.Ipv4()
+ *(*int8)(unsafe.Add(unsafe.Pointer(base), (4 + 2*4))) = int8(int32(0))
+ *(*int16)(unsafe.Add(unsafe.Pointer(base), (8 + 2*4))) = int16(int32((payload).Port))
+ *(*int8)(unsafe.Add(unsafe.Pointer(base), (10 + 2*4))) = int8(int32(((payload).Address).F0))
+ *(*int8)(unsafe.Add(unsafe.Pointer(base), (11 + 2*4))) = int8(int32(((payload).Address).F1))
+ *(*int8)(unsafe.Add(unsafe.Pointer(base), (12 + 2*4))) = int8(int32(((payload).Address).F2))
+ *(*int8)(unsafe.Add(unsafe.Pointer(base), (13 + 2*4))) = int8(int32(((payload).Address).F3))
+
+ case wasi_sockets_0_2_8_network.IpSocketAddressIpv6:
+ payload := payload.Ipv6()
+ *(*int8)(unsafe.Add(unsafe.Pointer(base), (4 + 2*4))) = int8(int32(1))
+ *(*int16)(unsafe.Add(unsafe.Pointer(base), (8 + 2*4))) = int16(int32((payload).Port))
+ *(*int32)(unsafe.Add(unsafe.Pointer(base), (12 + 2*4))) = int32((payload).FlowInfo)
+ *(*int16)(unsafe.Add(unsafe.Pointer(base), (16 + 2*4))) = int16(int32(((payload).Address).F0))
+ *(*int16)(unsafe.Add(unsafe.Pointer(base), (18 + 2*4))) = int16(int32(((payload).Address).F1))
+ *(*int16)(unsafe.Add(unsafe.Pointer(base), (20 + 2*4))) = int16(int32(((payload).Address).F2))
+ *(*int16)(unsafe.Add(unsafe.Pointer(base), (22 + 2*4))) = int16(int32(((payload).Address).F3))
+ *(*int16)(unsafe.Add(unsafe.Pointer(base), (24 + 2*4))) = int16(int32(((payload).Address).F4))
+ *(*int16)(unsafe.Add(unsafe.Pointer(base), (26 + 2*4))) = int16(int32(((payload).Address).F5))
+ *(*int16)(unsafe.Add(unsafe.Pointer(base), (28 + 2*4))) = int16(int32(((payload).Address).F6))
+ *(*int16)(unsafe.Add(unsafe.Pointer(base), (30 + 2*4))) = int16(int32(((payload).Address).F7))
+ *(*int32)(unsafe.Add(unsafe.Pointer(base), (32 + 2*4))) = int32((payload).ScopeId)
+
+ default:
+ panic("unreachable")
+ }
+
+ default:
+ panic("unreachable")
+ }
+
+ }
+
+ wasm_import_method_outgoing_datagram_stream_send((self).Handle(), uintptr(result), length, returnArea)
+ var result0 witTypes.Result[uint64, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result0 = witTypes.Ok[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))))
+ case 1:
+
+ result0 = witTypes.Err[uint64, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))
+ default:
+ panic("unreachable")
+ }
+ result1 := result0
+ return result1
+
+}
+
+//go:wasmimport wasi:sockets/udp@0.2.8 [method]outgoing-datagram-stream.subscribe
+func wasm_import_method_outgoing_datagram_stream_subscribe(arg0 int32) int32
+
+func (self *OutgoingDatagramStream) Subscribe() *wasi_io_0_2_8_poll.Pollable {
+
+ result := wasm_import_method_outgoing_datagram_stream_subscribe((self).Handle())
+ return wasi_io_0_2_8_poll.PollableFromOwnHandle(int32(uintptr(result)))
+
+}
diff --git a/imports/wasi_sockets_0_2_8_udp_create_socket/empty.s b/imports/wasi_sockets_0_2_8_udp_create_socket/empty.s
new file mode 100644
index 0000000..308ab60
--- /dev/null
+++ b/imports/wasi_sockets_0_2_8_udp_create_socket/empty.s
@@ -0,0 +1,3 @@
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
\ No newline at end of file
diff --git a/imports/wasi_sockets_0_2_8_udp_create_socket/wit_bindings.go b/imports/wasi_sockets_0_2_8_udp_create_socket/wit_bindings.go
new file mode 100644
index 0000000..df18821
--- /dev/null
+++ b/imports/wasi_sockets_0_2_8_udp_create_socket/wit_bindings.go
@@ -0,0 +1,61 @@
+// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
+//
+// This code was generated from the following packages:
+// wasi:io@0.2.8
+// wasi:clocks@0.2.8
+// wasi:filesystem@0.2.8
+// wasi:sockets@0.2.8
+// wasi:random@0.2.8
+// wasi:cli@0.2.8
+// wasi:config@0.2.0-rc.1
+// wasi:logging@0.1.0-draft
+// wasi:http@0.2.8
+// wasi:clocks@0.3.0
+// wasi:filesystem@0.3.0
+// wasi:sockets@0.3.0
+// wasi:random@0.3.0
+// wasi:cli@0.3.0
+// wasi:http@0.3.0
+// bytecodealliance:pkg@0.1.0
+// componentize-go:union
+
+package wasi_sockets_0_2_8_udp_create_socket
+
+import (
+ "go.bytecodealliance.org/pkg/imports/wasi_sockets_0_2_8_network"
+ "go.bytecodealliance.org/pkg/imports/wasi_sockets_0_2_8_udp"
+ witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+ "runtime"
+ "unsafe"
+)
+
+type Network = wasi_sockets_0_2_8_network.Network
+type ErrorCode = wasi_sockets_0_2_8_network.ErrorCode
+type IpAddressFamily = wasi_sockets_0_2_8_network.IpAddressFamily
+type UdpSocket = wasi_sockets_0_2_8_udp.UdpSocket
+
+//go:wasmimport wasi:sockets/udp-create-socket@0.2.8 create-udp-socket
+func wasm_import_create_udp_socket(arg0 int32, arg1 uintptr)
+
+func CreateUdpSocket(addressFamily wasi_sockets_0_2_8_network.IpAddressFamily) witTypes.Result[*wasi_sockets_0_2_8_udp.UdpSocket, wasi_sockets_0_2_8_network.ErrorCode] {
+ pinner := &runtime.Pinner{}
+ defer pinner.Unpin()
+
+ returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
+ wasm_import_create_udp_socket(int32(addressFamily), returnArea)
+ var result witTypes.Result[*wasi_sockets_0_2_8_udp.UdpSocket, wasi_sockets_0_2_8_network.ErrorCode]
+ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
+ case 0:
+
+ result = witTypes.Ok[*wasi_sockets_0_2_8_udp.UdpSocket, wasi_sockets_0_2_8_network.ErrorCode](wasi_sockets_0_2_8_udp.UdpSocketFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
+ case 1:
+
+ result = witTypes.Err[*wasi_sockets_0_2_8_udp.UdpSocket, wasi_sockets_0_2_8_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))
+ default:
+ panic("unreachable")
+ }
+ result0 := result
+ return result0
+
+}
diff --git a/internal/httpconv/httpconv.go b/internal/httpconv/httpconv.go
new file mode 100644
index 0000000..ac3afa7
--- /dev/null
+++ b/internal/httpconv/httpconv.go
@@ -0,0 +1,29 @@
+// Package httpconv contains the pure-Go conversion logic shared by both the
+// sync (WASI P2) and async (WASI P3) implementations of the wasihttp
+// package. It has no dependency on generated wasm bindings, so it compiles,
+// tests, and benchmarks on the host.
+package httpconv
+
+import (
+ "net/http"
+
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+)
+
+// FieldValues converts a list of HTTP header values into the [][]uint8 shape
+// required by wasi:http `fields.set`.
+func FieldValues(vals []string) [][]uint8 {
+ fieldVals := make([][]uint8, 0, len(vals))
+ for _, val := range vals {
+ fieldVals = append(fieldVals, []uint8(val))
+ }
+ return fieldVals
+}
+
+// AddEntries copies wasi:http field entries (as returned by `fields.entries`
+// / `fields.copy-all`) into a [net/http.Header] map.
+func AddEntries(dest http.Header, entries []witTypes.Tuple2[string, []uint8]) {
+ for _, pair := range entries {
+ dest.Add(pair.F0, string(pair.F1))
+ }
+}
diff --git a/internal/httpconv/httpconv_test.go b/internal/httpconv/httpconv_test.go
new file mode 100644
index 0000000..9c0a6ed
--- /dev/null
+++ b/internal/httpconv/httpconv_test.go
@@ -0,0 +1,96 @@
+package httpconv
+
+import (
+ "fmt"
+ "net/http"
+ "reflect"
+ "testing"
+
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+)
+
+func TestFieldValues(t *testing.T) {
+ got := FieldValues([]string{"text/html", "application/json"})
+ want := [][]uint8{[]uint8("text/html"), []uint8("application/json")}
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("FieldValues: got %v, want %v", got, want)
+ }
+
+ if got := FieldValues(nil); len(got) != 0 {
+ t.Errorf("FieldValues(nil): got %v, want empty", got)
+ }
+}
+
+func TestAddEntries(t *testing.T) {
+ entries := []witTypes.Tuple2[string, []uint8]{
+ {F0: "content-type", F1: []uint8("text/html")},
+ {F0: "set-cookie", F1: []uint8("a=1")},
+ {F0: "set-cookie", F1: []uint8("b=2")},
+ }
+
+ dest := http.Header{}
+ AddEntries(dest, entries)
+
+ want := http.Header{
+ "Content-Type": {"text/html"},
+ "Set-Cookie": {"a=1", "b=2"},
+ }
+ if !reflect.DeepEqual(dest, want) {
+ t.Errorf("AddEntries: got %v, want %v", dest, want)
+ }
+}
+
+// benchmarkEntries builds a realistic set of wasi:http field entries.
+func benchmarkEntries(n int) []witTypes.Tuple2[string, []uint8] {
+ entries := make([]witTypes.Tuple2[string, []uint8], 0, n)
+ for i := range n {
+ entries = append(entries, witTypes.Tuple2[string, []uint8]{
+ F0: fmt.Sprintf("x-custom-header-%d", i),
+ F1: []uint8(fmt.Sprintf("value-%d-abcdefghijklmnopqrstuvwxyz", i)),
+ })
+ }
+ return entries
+}
+
+// benchmarkHeader builds a realistic net/http.Header.
+func benchmarkHeader(n int) http.Header {
+ h := http.Header{}
+ for i := range n {
+ h.Add(fmt.Sprintf("X-Custom-Header-%d", i), fmt.Sprintf("value-%d-abcdefghijklmnopqrstuvwxyz", i))
+ }
+ h.Add("Set-Cookie", "a=1")
+ h.Add("Set-Cookie", "b=2")
+ return h
+}
+
+func BenchmarkFieldValues(b *testing.B) {
+ vals := []string{"text/html", "application/json", "a=1; Path=/; HttpOnly"}
+ for b.Loop() {
+ _ = FieldValues(vals)
+ }
+}
+
+func BenchmarkAddEntries(b *testing.B) {
+ for _, size := range []int{4, 16, 64} {
+ b.Run(fmt.Sprintf("headers=%d", size), func(b *testing.B) {
+ entries := benchmarkEntries(size)
+ for b.Loop() {
+ dest := http.Header{}
+ AddEntries(dest, entries)
+ }
+ })
+ }
+}
+
+func BenchmarkHeaderToFieldValues(b *testing.B) {
+ for _, size := range []int{4, 16, 64} {
+ b.Run(fmt.Sprintf("headers=%d", size), func(b *testing.B) {
+ h := benchmarkHeader(size)
+ for b.Loop() {
+ for _, vals := range h {
+ _ = FieldValues(vals)
+ }
+ }
+ })
+ }
+}
diff --git a/regenerate_bindings.sh b/regenerate_bindings.sh
new file mode 100755
index 0000000..3f99bfa
--- /dev/null
+++ b/regenerate_bindings.sh
@@ -0,0 +1,70 @@
+#!/bin/bash
+set -euo pipefail
+
+# Regenerates the committed componentize-go bindings for this library.
+#
+# Uses the componentize-go binary from PATH by default; override with e.g.
+# COMPONENTIZE_GO=~/source/bytecodealliance/componentize-go/target/debug/componentize-go ./regenerate_bindings.sh
+COMPONENTIZE_GO="${COMPONENTIZE_GO:-componentize-go}"
+
+MODULE=go.bytecodealliance.org/pkg
+
+WORLDS=(
+ "bytecodealliance:pkg/wasip2@0.1.0"
+ "bytecodealliance:pkg/wasip3@0.1.0"
+)
+
+# Remove any previously-generated import bindings.
+rm -rf imports
+
+# Generate bindings for all supported worlds. We only keep the imports from
+# this pass, discarding the exports.
+world_flags=()
+for world in "${WORLDS[@]}"; do
+ world_flags+=(-w "$world")
+done
+
+"$COMPONENTIZE_GO" \
+ --ignore-toml-files \
+ "${world_flags[@]}" \
+ -d wit \
+ bindings \
+ --format \
+ -o imports \
+ --pkg-name "$MODULE/imports" \
+ --include-versions
+
+rm -r imports/wit_exports
+
+# For each supported world, generate bindings specific to that world. We keep
+# only the exports, deferring to the shared imports generated above.
+for world in "${WORLDS[@]}"; do
+ rm -rf tmp
+ dir=exports/$(echo "$world" | sed 's+[:/@.-]+_+g')
+ rm -rf "$dir/wit_exports"
+ mkdir -p "$dir"
+ "$COMPONENTIZE_GO" \
+ --ignore-toml-files \
+ -w "$world" \
+ -d wit \
+ bindings \
+ --format \
+ -o tmp \
+ --export-pkg-name "$MODULE/$dir" \
+ --pkg-name "$MODULE/imports" \
+ --include-versions
+ cp -r tmp/wit_exports "$dir/"
+ rm -rf tmp
+
+ # Allow the package to compile on non-wasm hosts despite bodyless
+ # //go:wasmimport declarations (same trick as the generated imports).
+ if [ ! -f "$dir/wit_exports/empty.s" ]; then
+ cat > "$dir/wit_exports/empty.s" <<'EOF'
+// This file exists for testing this package without WebAssembly,
+// allowing empty function bodies with a //go:wasmimport directive.
+// See https://pkg.go.dev/cmd/compile for more information.
+EOF
+ fi
+done
+
+go mod tidy
diff --git a/wasiconfig/config.go b/wasiconfig/config.go
new file mode 100644
index 0000000..a845694
--- /dev/null
+++ b/wasiconfig/config.go
@@ -0,0 +1,39 @@
+// Package wasiconfig provides helpers over the [wasi:config/store]
+// interface.
+//
+// [wasi:config/store]: https://github.com/WebAssembly/wasi-config/blob/main/wit/store.wit
+package wasiconfig
+
+import (
+ store "go.bytecodealliance.org/pkg/imports/wasi_config_0_2_0_rc_1_store"
+)
+
+// Get returns the configuration value for the provided key using
+// [wasi:config/store.get]. The second return value reports whether a value
+// was found.
+//
+// [wasi:config/store.get]: https://github.com/WebAssembly/wasi-config/blob/main/wit/store.wit
+func Get(key string) (string, bool) {
+ res := store.Get(key)
+ if res.IsOk() {
+ opt := res.Ok()
+ if opt.IsSome() {
+ return opt.Some(), true
+ }
+ }
+
+ return "", false
+}
+
+// GetOrDefault tries to get a configuration value by the provided key using
+// [wasi:config/store.get], falling back to the provided defaultValue if a
+// configuration value for the key is not found.
+//
+// [wasi:config/store.get]: https://github.com/WebAssembly/wasi-config/blob/main/wit/store.wit
+func GetOrDefault(key string, defaultValue string) string {
+ if val, ok := Get(key); ok {
+ return val
+ }
+
+ return defaultValue
+}
diff --git a/wasihttp/adapter_p2.go b/wasihttp/adapter_p2.go
new file mode 100644
index 0000000..66c0a32
--- /dev/null
+++ b/wasihttp/adapter_p2.go
@@ -0,0 +1,273 @@
+//go:build !componentizego_async
+
+package wasihttp
+
+// Refactored from https://github.com/rajatjindal/wasi-go-sdk/tree/d3e8665bef9fbf0794ad14f7114a9882e0d983c3/pkg/wasihttp
+
+import (
+ "fmt"
+ "io"
+ "net/http"
+ "sync"
+
+ types "go.bytecodealliance.org/pkg/imports/wasi_http_0_2_8_types"
+ streams "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_streams"
+ "go.bytecodealliance.org/pkg/internal/httpconv"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+)
+
+var _ http.ResponseWriter = (*responseOutparamWriter)(nil)
+
+// responseOutparamWriter implements a [net/http.ResponseWriter] for
+// [wasi:http/types.response-outparam].
+//
+// [wasi:http/types.response-outparam]: https://github.com/WebAssembly/wasi-http/blob/main/wit/types.wit
+type responseOutparamWriter struct {
+ outparam *types.ResponseOutparam
+ response *types.OutgoingResponse
+ wasiHeaders *types.Fields
+ httpHeaders http.Header
+ body *types.OutgoingBody
+ stream *streams.OutputStream
+
+ headerOnce sync.Once
+ headerErr error
+
+ statuscode int
+}
+
+// Header returns the header map that will be sent by WriteHeader.
+func (row *responseOutparamWriter) Header() http.Header {
+ return row.httpHeaders
+}
+
+// Write writes the data to the connection as part of an HTTP reply.
+func (row *responseOutparamWriter) Write(buf []byte) (int, error) {
+ // NOTE(lxf): If this is the first write, make sure we set the headers/statuscode
+ row.headerOnce.Do(row.reconcile)
+ if row.headerErr != nil {
+ return 0, row.headerErr
+ }
+
+ writeResult := row.stream.Write(buf)
+ if writeResult.IsErr() {
+ if writeResult.Err().Tag() == streams.StreamErrorClosed {
+ return 0, io.EOF
+ }
+
+ return 0, fmt.Errorf("failed to write to response body's stream: %s", writeResult.Err().LastOperationFailed().ToDebugString())
+ }
+
+ row.stream.BlockingFlush()
+
+ return len(buf), nil
+}
+
+// WriteHeader sends an HTTP response header with the provided
+// status code.
+func (row *responseOutparamWriter) WriteHeader(statusCode int) {
+ row.headerOnce.Do(func() {
+ row.statuscode = statusCode
+ row.reconcile()
+ })
+}
+
+// reconcile headers from go to wasi
+func (row *responseOutparamWriter) reconcileHeaders() error {
+ for key, vals := range row.httpHeaders {
+ if result := row.wasiHeaders.Set(key, httpconv.FieldValues(vals)); result.IsErr() {
+ return fmt.Errorf("failed to set header %s: %v", key, result.Err())
+ }
+ }
+
+ // NOTE(lxf): once headers are written we clear them out so they can emit http trailers
+ row.httpHeaders = http.Header{}
+
+ return nil
+}
+
+func (row *responseOutparamWriter) reconcile() {
+ if row.headerErr = row.reconcileHeaders(); row.headerErr != nil {
+ return
+ }
+
+ row.response = types.MakeOutgoingResponse(row.wasiHeaders)
+ row.response.SetStatusCode(uint16(row.statuscode))
+
+ bodyResult := row.response.Body()
+ if bodyResult.IsErr() {
+ row.headerErr = fmt.Errorf("failed to acquire resource handle to response body")
+ return
+ }
+ row.body = bodyResult.Ok()
+
+ writeResult := row.body.Write()
+ if writeResult.IsErr() {
+ row.headerErr = fmt.Errorf("failed to acquire resource handle for response body's stream")
+ return
+ }
+ row.stream = writeResult.Ok()
+
+ result := witTypes.Ok[*types.OutgoingResponse, types.ErrorCode](row.response)
+ types.ResponseOutparamSet(row.outparam, result)
+}
+
+// Close closes out the underlying stream by flushing the response and making
+// sure that the underlying resource handle is dropped.
+func (row *responseOutparamWriter) Close() error {
+ if row.stream == nil {
+ return nil
+ }
+
+ row.stream.BlockingFlush()
+ row.stream.Drop()
+ row.stream = nil
+
+ maybeTrailers := witTypes.None[*types.Fields]()
+ wasiTrailers := types.MakeFields()
+ for key, vals := range row.httpHeaders {
+ if result := wasiTrailers.Set(key, httpconv.FieldValues(vals)); result.IsErr() {
+ return fmt.Errorf("failed to set trailer %s: %v", key, result.Err())
+ }
+ }
+ if len(row.httpHeaders) > 0 {
+ maybeTrailers = witTypes.Some(wasiTrailers)
+ }
+
+ res := types.OutgoingBodyFinish(row.body, maybeTrailers)
+ if res.IsErr() {
+ return fmt.Errorf("failed to set trailer: %v", res.Err())
+ }
+ return nil
+}
+
+// newResponseOutparamWriter takes a [types.ResponseOutparam] representing
+// [wasi:http/types.response-outparam] and instantiates a new
+// [responseOutparamWriter] for writing to it.
+func newResponseOutparamWriter(out *types.ResponseOutparam) *responseOutparamWriter {
+ return &responseOutparamWriter{
+ outparam: out,
+ httpHeaders: http.Header{},
+ wasiHeaders: types.MakeFields(),
+ statuscode: http.StatusOK,
+ }
+}
+
+// wasiToHTTPRequest takes a [types.IncomingRequest] and returns a
+// [net/http.Request] representation of it.
+func wasiToHTTPRequest(ir *types.IncomingRequest) (req *http.Request, err error) {
+ method, err := methodToString(ir.Method())
+ if err != nil {
+ return nil, err
+ }
+
+ authority := "localhost"
+ if auth := ir.Authority(); auth.IsSome() {
+ authority = auth.Some()
+ }
+
+ pathWithQuery := "/"
+ if p := ir.PathWithQuery(); p.IsSome() {
+ pathWithQuery = p.Some()
+ }
+
+ body, trailers, err := newIncomingBodyTrailer(ir)
+ if err != nil {
+ switch method {
+ case http.MethodGet,
+ http.MethodHead,
+ http.MethodDelete,
+ http.MethodConnect,
+ http.MethodOptions,
+ http.MethodTrace:
+ default:
+ return nil, fmt.Errorf("failed to consume incoming request: %w", err)
+ }
+ }
+
+ url := fmt.Sprintf("http://%s%s", authority, pathWithQuery)
+ req, err = http.NewRequest(method, url, body)
+ if err != nil {
+ return nil, err
+ }
+ req.Trailer = trailers
+
+ headers := ir.Headers()
+ wasiToHTTPHeader(headers, &req.Header)
+ headers.Drop()
+
+ req.Host = authority
+ req.URL.Host = authority
+ req.RequestURI = pathWithQuery
+
+ return req, nil
+}
+
+func methodToString(m types.Method) (string, error) {
+ switch m.Tag() {
+ case types.MethodConnect:
+ return http.MethodConnect, nil
+ case types.MethodDelete:
+ return http.MethodDelete, nil
+ case types.MethodGet:
+ return http.MethodGet, nil
+ case types.MethodHead:
+ return http.MethodHead, nil
+ case types.MethodOptions:
+ return http.MethodOptions, nil
+ case types.MethodPatch:
+ return http.MethodPatch, nil
+ case types.MethodPost:
+ return http.MethodPost, nil
+ case types.MethodPut:
+ return http.MethodPut, nil
+ case types.MethodTrace:
+ return http.MethodTrace, nil
+ case types.MethodOther:
+ other := m.Other()
+ return other, fmt.Errorf("unknown http method '%s'", other)
+ }
+ return "", fmt.Errorf("failed to convert http method")
+}
+
+// wasiToHTTPHeader takes a [types.Fields] and copies them to the provided [net/http.Header] map.
+func wasiToHTTPHeader(src *types.Fields, dest *http.Header) {
+ httpconv.AddEntries(*dest, src.Entries())
+}
+
+// httpToWASIHeader takes a [net/http.Header] map and copies them to the provided [types.Fields].
+func httpToWASIHeader(src http.Header, dest *types.Fields) error {
+ for k, v := range src {
+ res := dest.Set(k, httpconv.FieldValues(v))
+ if res.IsErr() {
+ return fmt.Errorf("failed to set header %s: %v", k, res.Err())
+ }
+ }
+
+ return nil
+}
+
+func toWASIMethod(s string) types.Method {
+ switch s {
+ case http.MethodConnect:
+ return types.MakeMethodConnect()
+ case http.MethodDelete:
+ return types.MakeMethodDelete()
+ case http.MethodGet:
+ return types.MakeMethodGet()
+ case http.MethodHead:
+ return types.MakeMethodHead()
+ case http.MethodOptions:
+ return types.MakeMethodOptions()
+ case http.MethodPatch:
+ return types.MakeMethodPatch()
+ case http.MethodPost:
+ return types.MakeMethodPost()
+ case http.MethodPut:
+ return types.MakeMethodPut()
+ case http.MethodTrace:
+ return types.MakeMethodTrace()
+ default:
+ return types.MakeMethodOther(s)
+ }
+}
diff --git a/wasihttp/adapter_p3.go b/wasihttp/adapter_p3.go
new file mode 100644
index 0000000..e1e74ac
--- /dev/null
+++ b/wasihttp/adapter_p3.go
@@ -0,0 +1,134 @@
+//go:build componentizego_async
+
+package wasihttp
+
+import (
+ "fmt"
+ "net/http"
+ "strings"
+
+ types "go.bytecodealliance.org/pkg/imports/wasi_http_0_3_0_types"
+ "go.bytecodealliance.org/pkg/internal/httpconv"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+)
+
+// wasiToHTTPRequest converts an incoming wasi:http Request into a
+// [net/http.Request]. The wasi request resource is consumed.
+func wasiToHTTPRequest(ir *types.Request) (*http.Request, error) {
+ defer ir.Drop()
+
+ method, err := methodToString(ir.GetMethod())
+ if err != nil {
+ return nil, err
+ }
+
+ authority := "localhost"
+ if auth := ir.GetAuthority(); auth.IsSome() {
+ authority = auth.Some()
+ }
+
+ pathWithQuery := "/"
+ if p := ir.GetPathWithQuery(); p.IsSome() {
+ pathWithQuery = p.Some()
+ }
+
+ scheme := "http"
+ if s := ir.GetScheme(); s.IsSome() && s.Some().Tag() == types.SchemeHttps {
+ scheme = "https"
+ }
+
+ headers := ir.GetHeaders()
+ entries := headers.CopyAll()
+ headers.Drop()
+
+ stream, trailers := types.RequestConsumeBody(ir, unitFuture())
+ body := newBodyReader(stream, trailers)
+
+ req, err := http.NewRequest(method, fmt.Sprintf("%s://%s%s", scheme, authority, pathWithQuery), body)
+ if err != nil {
+ body.Close()
+ return nil, err
+ }
+
+ httpconv.AddEntries(req.Header, entries)
+ req.Trailer = body.trailer
+ req.Host = authority
+ req.RequestURI = pathWithQuery
+
+ return req, nil
+}
+
+func methodToString(m types.Method) (string, error) {
+ switch m.Tag() {
+ case types.MethodConnect:
+ return http.MethodConnect, nil
+ case types.MethodDelete:
+ return http.MethodDelete, nil
+ case types.MethodGet:
+ return http.MethodGet, nil
+ case types.MethodHead:
+ return http.MethodHead, nil
+ case types.MethodOptions:
+ return http.MethodOptions, nil
+ case types.MethodPatch:
+ return http.MethodPatch, nil
+ case types.MethodPost:
+ return http.MethodPost, nil
+ case types.MethodPut:
+ return http.MethodPut, nil
+ case types.MethodTrace:
+ return http.MethodTrace, nil
+ case types.MethodOther:
+ return m.Other(), fmt.Errorf("unknown http method '%s'", m.Other())
+ default:
+ return "", fmt.Errorf("failed to convert http method")
+ }
+}
+
+func toWASIMethod(s string) types.Method {
+ switch s {
+ case http.MethodConnect:
+ return types.MakeMethodConnect()
+ case http.MethodDelete:
+ return types.MakeMethodDelete()
+ case http.MethodGet:
+ return types.MakeMethodGet()
+ case http.MethodHead:
+ return types.MakeMethodHead()
+ case http.MethodOptions:
+ return types.MakeMethodOptions()
+ case http.MethodPatch:
+ return types.MakeMethodPatch()
+ case http.MethodPost:
+ return types.MakeMethodPost()
+ case http.MethodPut:
+ return types.MakeMethodPut()
+ case http.MethodTrace:
+ return types.MakeMethodTrace()
+ default:
+ return types.MakeMethodOther(s)
+ }
+}
+
+func toWASIHeaders(headers http.Header) (*types.Fields, error) {
+ fields := types.MakeFields()
+
+ for key, vals := range headers {
+ if result := fields.Set(key, httpconv.FieldValues(vals)); result.IsErr() {
+ fields.Drop()
+ return nil, fmt.Errorf("failed to set header %s to [%s]: %s",
+ key, strings.Join(vals, ","), headerErrorString(result.Err()))
+ }
+ }
+
+ return fields, nil
+}
+
+// unitFuture returns a pre-resolved future used as the `res` argument of
+// consume-body: it signals that we accept the body unconditionally.
+func unitFuture() *witTypes.FutureReader[witTypes.Result[witTypes.Unit, types.ErrorCode]] {
+ tx, rx := types.MakeFutureResultUnitErrorCode()
+ // FutureWriter.Write blocks until the peer reads, so resolve asynchronously.
+ go tx.Write(witTypes.Ok[witTypes.Unit, types.ErrorCode](witTypes.Unit{}))
+ return rx
+}
diff --git a/wasihttp/doc.go b/wasihttp/doc.go
new file mode 100644
index 0000000..d7b477f
--- /dev/null
+++ b/wasihttp/doc.go
@@ -0,0 +1,20 @@
+// Package wasihttp adapts [net/http] to [wasi:http]: incoming requests are
+// served by a standard [net/http.Handler] registered via [Handle] or
+// [HandleFunc], and outbound requests are sent through the host via
+// [Transport] / [DefaultClient].
+//
+// The package has two implementations selected at build time with the
+// componentizego_async build tag; the exported API is identical under both:
+//
+// - Default (no tag): sync WASI P2, wasi:http@0.2.8. Exports
+// wasi:http/incoming-handler@0.2.8 and sends outbound requests through
+// wasi:http/outgoing-handler@0.2.8. Matches the bytecodealliance:pkg/wasip2
+// world and builds with stock Go.
+// - -tags componentizego_async: async WASI P3, wasi:http@0.3.0. Exports
+// wasi:http/handler@0.3.0 with streaming bodies and native concurrency,
+// and sends outbound requests through wasi:http/client@0.3.0. Matches the
+// bytecodealliance:pkg/wasip3 world. componentize-go sets this tag
+// automatically when building an async world.
+//
+// [wasi:http]: https://github.com/WebAssembly/wasi-http
+package wasihttp
diff --git a/wasihttp/errors_p3.go b/wasihttp/errors_p3.go
new file mode 100644
index 0000000..9638e45
--- /dev/null
+++ b/wasihttp/errors_p3.go
@@ -0,0 +1,181 @@
+//go:build componentizego_async
+
+package wasihttp
+
+import (
+ "fmt"
+ "strings"
+
+ types "go.bytecodealliance.org/pkg/imports/wasi_http_0_3_0_types"
+)
+
+func headerErrorString(err types.HeaderError) string {
+ switch err.Tag() {
+ case types.HeaderErrorInvalidSyntax:
+ return "invalid syntax"
+ case types.HeaderErrorForbidden:
+ return "forbidden header"
+ case types.HeaderErrorImmutable:
+ return "immutable header fields"
+ case types.HeaderErrorSizeExceeded:
+ return "size exceeded"
+ case types.HeaderErrorOther:
+ if v := err.Other(); v.IsSome() {
+ return v.Some()
+ }
+ return "unknown header error"
+ default:
+ return "unknown header error"
+ }
+}
+
+func errorCodeString(code types.ErrorCode) string {
+ switch code.Tag() {
+ case types.ErrorCodeDnsTimeout:
+ return "DNS timeout"
+ case types.ErrorCodeDnsError:
+ p := code.DnsError()
+ var parts []string
+ if p.Rcode.IsSome() {
+ parts = append(parts, fmt.Sprintf("rcode=%s", p.Rcode.Some()))
+ }
+ if p.InfoCode.IsSome() {
+ parts = append(parts, fmt.Sprintf("info-code=%d", p.InfoCode.Some()))
+ }
+ if len(parts) == 0 {
+ return "DNS error"
+ }
+ return "DNS error (" + strings.Join(parts, ", ") + ")"
+ case types.ErrorCodeDestinationNotFound:
+ return "destination not found"
+ case types.ErrorCodeDestinationUnavailable:
+ return "destination unavailable"
+ case types.ErrorCodeDestinationIpProhibited:
+ return "destination IP prohibited"
+ case types.ErrorCodeDestinationIpUnroutable:
+ return "destination IP unroutable"
+ case types.ErrorCodeConnectionRefused:
+ return "connection refused"
+ case types.ErrorCodeConnectionTerminated:
+ return "connection terminated"
+ case types.ErrorCodeConnectionTimeout:
+ return "connection timeout"
+ case types.ErrorCodeConnectionReadTimeout:
+ return "connection read timeout"
+ case types.ErrorCodeConnectionWriteTimeout:
+ return "connection write timeout"
+ case types.ErrorCodeConnectionLimitReached:
+ return "connection limit reached"
+ case types.ErrorCodeTlsProtocolError:
+ return "TLS protocol error"
+ case types.ErrorCodeTlsCertificateError:
+ return "TLS certificate error"
+ case types.ErrorCodeTlsAlertReceived:
+ p := code.TlsAlertReceived()
+ var parts []string
+ if p.AlertId.IsSome() {
+ parts = append(parts, fmt.Sprintf("alert-id=%d", p.AlertId.Some()))
+ }
+ if p.AlertMessage.IsSome() {
+ parts = append(parts, fmt.Sprintf("alert-message=%s", p.AlertMessage.Some()))
+ }
+ if len(parts) == 0 {
+ return "TLS alert received"
+ }
+ return "TLS alert received (" + strings.Join(parts, ", ") + ")"
+ case types.ErrorCodeHttpRequestDenied:
+ return "HTTP request denied"
+ case types.ErrorCodeHttpRequestLengthRequired:
+ return "HTTP request length required"
+ case types.ErrorCodeHttpRequestBodySize:
+ if v := code.HttpRequestBodySize(); v.IsSome() {
+ return fmt.Sprintf("HTTP request body size: %d", v.Some())
+ }
+ return "HTTP request body size"
+ case types.ErrorCodeHttpRequestMethodInvalid:
+ return "HTTP request method invalid"
+ case types.ErrorCodeHttpRequestUriInvalid:
+ return "HTTP request URI invalid"
+ case types.ErrorCodeHttpRequestUriTooLong:
+ return "HTTP request URI too long"
+ case types.ErrorCodeHttpRequestHeaderSectionSize:
+ if v := code.HttpRequestHeaderSectionSize(); v.IsSome() {
+ return fmt.Sprintf("HTTP request header section size: %d", v.Some())
+ }
+ return "HTTP request header section size"
+ case types.ErrorCodeHttpRequestHeaderSize:
+ if v := code.HttpRequestHeaderSize(); v.IsSome() {
+ return "HTTP request header size " + fieldSizeString(v.Some())
+ }
+ return "HTTP request header size"
+ case types.ErrorCodeHttpRequestTrailerSectionSize:
+ if v := code.HttpRequestTrailerSectionSize(); v.IsSome() {
+ return fmt.Sprintf("HTTP request trailer section size: %d", v.Some())
+ }
+ return "HTTP request trailer section size"
+ case types.ErrorCodeHttpRequestTrailerSize:
+ return "HTTP request trailer size " + fieldSizeString(code.HttpRequestTrailerSize())
+ case types.ErrorCodeHttpResponseIncomplete:
+ return "HTTP response incomplete"
+ case types.ErrorCodeHttpResponseHeaderSectionSize:
+ if v := code.HttpResponseHeaderSectionSize(); v.IsSome() {
+ return fmt.Sprintf("HTTP response header section size: %d", v.Some())
+ }
+ return "HTTP response header section size"
+ case types.ErrorCodeHttpResponseHeaderSize:
+ return "HTTP response header size " + fieldSizeString(code.HttpResponseHeaderSize())
+ case types.ErrorCodeHttpResponseBodySize:
+ if v := code.HttpResponseBodySize(); v.IsSome() {
+ return fmt.Sprintf("HTTP response body size: %d", v.Some())
+ }
+ return "HTTP response body size"
+ case types.ErrorCodeHttpResponseTrailerSectionSize:
+ if v := code.HttpResponseTrailerSectionSize(); v.IsSome() {
+ return fmt.Sprintf("HTTP response trailer section size: %d", v.Some())
+ }
+ return "HTTP response trailer section size"
+ case types.ErrorCodeHttpResponseTrailerSize:
+ return "HTTP response trailer size " + fieldSizeString(code.HttpResponseTrailerSize())
+ case types.ErrorCodeHttpResponseTransferCoding:
+ if v := code.HttpResponseTransferCoding(); v.IsSome() {
+ return fmt.Sprintf("HTTP response transfer coding: %s", v.Some())
+ }
+ return "HTTP response transfer coding"
+ case types.ErrorCodeHttpResponseContentCoding:
+ if v := code.HttpResponseContentCoding(); v.IsSome() {
+ return fmt.Sprintf("HTTP response content coding: %s", v.Some())
+ }
+ return "HTTP response content coding"
+ case types.ErrorCodeHttpResponseTimeout:
+ return "HTTP response timeout"
+ case types.ErrorCodeHttpUpgradeFailed:
+ return "HTTP upgrade failed"
+ case types.ErrorCodeHttpProtocolError:
+ return "HTTP protocol error"
+ case types.ErrorCodeLoopDetected:
+ return "loop detected"
+ case types.ErrorCodeConfigurationError:
+ return "configuration error"
+ case types.ErrorCodeInternalError:
+ if v := code.InternalError(); v.IsSome() {
+ return "internal error: " + v.Some()
+ }
+ return "internal error"
+ default:
+ return fmt.Sprintf("unknown error code: %d", code.Tag())
+ }
+}
+
+func fieldSizeString(p types.FieldSizePayload) string {
+ var parts []string
+ if p.FieldName.IsSome() {
+ parts = append(parts, fmt.Sprintf("field-name=%s", p.FieldName.Some()))
+ }
+ if p.FieldSize.IsSome() {
+ parts = append(parts, fmt.Sprintf("field-size=%d", p.FieldSize.Some()))
+ }
+ if len(parts) == 0 {
+ return ""
+ }
+ return "(" + strings.Join(parts, ", ") + ")"
+}
diff --git a/wasihttp/responsewriter_p3.go b/wasihttp/responsewriter_p3.go
new file mode 100644
index 0000000..7e4f1f3
--- /dev/null
+++ b/wasihttp/responsewriter_p3.go
@@ -0,0 +1,155 @@
+//go:build componentizego_async
+
+package wasihttp
+
+import (
+ "fmt"
+ "net/http"
+ "slices"
+
+ types "go.bytecodealliance.org/pkg/imports/wasi_http_0_3_0_types"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+)
+
+var _ http.ResponseWriter = (*responseWriter)(nil)
+var _ http.Flusher = (*responseWriter)(nil)
+
+// responseWriter implements [http.ResponseWriter] over a wasi:http Response.
+// The wasi Response is constructed and delivered on channel as soon as the
+// handler first writes (or when the handler returns), so the body can stream
+// to the client incrementally while the handler keeps writing.
+type responseWriter struct {
+ // channel on which the constructed wasi Response is delivered exactly once
+ channel chan witTypes.Result[*types.Response, types.ErrorCode]
+ // stream to which the response body is written after send
+ stream *witTypes.StreamWriter[uint8]
+ // future which resolves to an error if the body could not be delivered
+ streamResult *witTypes.FutureReader[witTypes.Result[witTypes.Unit, types.ErrorCode]]
+ // trailersTx resolves the response's trailers future
+ trailersTx *witTypes.FutureWriter[witTypes.Result[witTypes.Option[*types.Fields], types.ErrorCode]]
+ headers http.Header
+ statusCode int
+}
+
+func newResponseWriter() *responseWriter {
+ return &responseWriter{
+ channel: make(chan witTypes.Result[*types.Response, types.ErrorCode]),
+ headers: http.Header{},
+ statusCode: http.StatusOK,
+ }
+}
+
+func (w *responseWriter) Header() http.Header {
+ return w.headers
+}
+
+func (w *responseWriter) WriteHeader(statusCode int) {
+ w.statusCode = statusCode
+}
+
+func (w *responseWriter) Write(buf []byte) (int, error) {
+ if err := w.send(); err != nil {
+ return 0, err
+ }
+
+ count := w.stream.Write(buf)
+ if count == 0 && w.stream.ReaderDropped() {
+ return 0, w.takeError()
+ }
+
+ return int(count), nil
+}
+
+func (w *responseWriter) Flush() {}
+
+// send constructs the wasi Response from the accumulated headers and status
+// code and delivers it on channel. It is a no-op after the first call.
+func (w *responseWriter) send() error {
+ channel := w.channel
+ if channel == nil {
+ return nil
+ }
+ w.channel = nil
+
+ fields, err := toWASIHeaders(w.headers)
+ if err != nil {
+ // Keep the channel so a later send (or the error path in wasiHandle)
+ // can still deliver a result; otherwise the export would block forever.
+ w.channel = channel
+ return err
+ }
+
+ tx, rx := types.MakeStreamU8()
+ w.stream = tx
+
+ trailersTx, trailersRx := types.MakeFutureResultOptionFieldsErrorCode()
+ w.trailersTx = trailersTx
+
+ response, sent := types.ResponseNew(fields, witTypes.Some(rx), trailersRx)
+ w.streamResult = sent
+
+ response.SetStatusCode(uint16(w.statusCode))
+
+ channel <- witTypes.Ok[*types.Response, types.ErrorCode](response)
+
+ return nil
+}
+
+// writeTrailers resolves the response's trailers future with any headers the
+// handler declared via the "Trailer" header, ending the response body.
+func (w *responseWriter) writeTrailers() {
+ if w.trailersTx == nil {
+ return
+ }
+ trailersTx := w.trailersTx
+ w.trailersTx = nil
+
+ declared := w.headers.Values("Trailer")
+ collected := make(http.Header)
+ for name, vals := range w.headers {
+ if slices.Contains(declared, name) {
+ collected[name] = vals
+ }
+ }
+
+ if len(collected) == 0 {
+ trailersTx.Write(witTypes.Ok[witTypes.Option[*types.Fields], types.ErrorCode](witTypes.None[*types.Fields]()))
+ return
+ }
+
+ wasiTrailers, err := toWASIHeaders(collected)
+ if err != nil {
+ trailersTx.Write(witTypes.Err[witTypes.Option[*types.Fields]](
+ types.MakeErrorCodeInternalError(witTypes.Some(fmt.Sprintf("cannot send trailers: %v", err))),
+ ))
+ return
+ }
+ trailersTx.Write(witTypes.Ok[witTypes.Option[*types.Fields], types.ErrorCode](witTypes.Some(wasiTrailers)))
+}
+
+// takeError reads the body-delivery future after the client stopped reading.
+func (w *responseWriter) takeError() error {
+ if w.streamResult != nil {
+ result := w.streamResult.Read()
+ w.streamResult = nil
+ if result.IsErr() {
+ return fmt.Errorf("failed to write to HTTP body stream: %s", errorCodeString(result.Err()))
+ }
+ }
+ return nil
+}
+
+func (w *responseWriter) close() {
+ if w.stream != nil {
+ w.stream.Drop()
+ w.stream = nil
+ }
+ if w.streamResult != nil {
+ w.streamResult.Drop()
+ w.streamResult = nil
+ }
+ if w.trailersTx != nil {
+ w.trailersTx.Drop()
+ w.trailersTx = nil
+ }
+}
diff --git a/wasihttp/roundtripper_p2.go b/wasihttp/roundtripper_p2.go
new file mode 100644
index 0000000..e13904c
--- /dev/null
+++ b/wasihttp/roundtripper_p2.go
@@ -0,0 +1,167 @@
+//go:build !componentizego_async
+
+package wasihttp
+
+import (
+ "fmt"
+ "io"
+ "net/http"
+ "time"
+
+ outgoinghandler "go.bytecodealliance.org/pkg/imports/wasi_http_0_2_8_outgoing_handler"
+ types "go.bytecodealliance.org/pkg/imports/wasi_http_0_2_8_types"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+)
+
+// Transport implements [net/http.RoundTripper] for [wasi:http].
+//
+// [wasi:http]: https://github.com/WebAssembly/wasi-http
+type Transport struct {
+ ConnectTimeout time.Duration
+}
+
+var _ http.RoundTripper = (*Transport)(nil)
+
+// DefaultTransport is the default implementation of [Transport] and is used by [DefaultClient].
+// It is configured to use the same timeout value as [net/http.DefaultTransport].
+var DefaultTransport = &Transport{
+ ConnectTimeout: 30 * time.Second, // NOTE(lxf): Same as stdlib http.Transport
+}
+
+// DefaultClient is the default [net/http.Client] that uses [DefaultTransport] to adapt [net/http] to [wasi:http].
+//
+// [wasi:http]: https://github.com/WebAssembly/wasi-http
+var DefaultClient = &http.Client{Transport: DefaultTransport}
+
+func (r *Transport) requestOptions() *types.RequestOptions {
+ options := types.MakeRequestOptions()
+ if r.ConnectTimeout > 0 {
+ // Go’s time.Duration is a nanosecond count, and WASI’s monotonic-clock duration is also a u64 of nanoseconds
+ options.SetConnectTimeout(
+ witTypes.Some(types.Duration(r.ConnectTimeout)),
+ )
+ } else {
+ options.SetConnectTimeout(
+ witTypes.None[types.Duration](),
+ )
+ }
+ return options
+}
+
+// RoundTrip implements the [net/http.RoundTripper] interface.
+func (r *Transport) RoundTrip(incomingRequest *http.Request) (*http.Response, error) {
+ outHeaders := types.MakeFields()
+ if err := httpToWASIHeader(incomingRequest.Header, outHeaders); err != nil {
+ return nil, fmt.Errorf("failed to convert outgoing headers: %w", err)
+ }
+
+ outRequest := types.MakeOutgoingRequest(outHeaders)
+
+ outRequest.SetAuthority(witTypes.Some(incomingRequest.Host))
+ outRequest.SetMethod(toWASIMethod(incomingRequest.Method))
+
+ pathWithQuery := incomingRequest.URL.Path
+ if incomingRequest.URL.RawQuery != "" {
+ pathWithQuery = pathWithQuery + "?" + incomingRequest.URL.Query().Encode()
+ }
+ outRequest.SetPathWithQuery(witTypes.Some(pathWithQuery))
+
+ switch incomingRequest.URL.Scheme {
+ case "http":
+ outRequest.SetScheme(witTypes.Some(types.MakeSchemeHttp()))
+ case "https":
+ outRequest.SetScheme(witTypes.Some(types.MakeSchemeHttps()))
+ default:
+ outRequest.SetScheme(witTypes.Some(types.MakeSchemeOther(incomingRequest.URL.Scheme)))
+ }
+
+ bodyResult := outRequest.Body()
+ if bodyResult.IsErr() {
+ return nil, fmt.Errorf("failed to acquire resource handle to request body")
+ }
+ body := bodyResult.Ok()
+
+ handleResult := outgoinghandler.Handle(outRequest, witTypes.Some(r.requestOptions()))
+ if handleResult.IsErr() {
+ return nil, fmt.Errorf("failed to acquire handle to outbound request: %v", handleResult.Err())
+ }
+ futureResponse := handleResult.Ok()
+
+ maybeTrailers := witTypes.None[*types.Fields]()
+ if len(incomingRequest.Trailer) > 0 {
+ outTrailers := types.MakeFields()
+ if err := httpToWASIHeader(incomingRequest.Trailer, outTrailers); err != nil {
+ return nil, fmt.Errorf("failed to convert outgoing trailers: %w", err)
+ }
+ maybeTrailers = witTypes.Some(outTrailers)
+ }
+
+ // NOTE(lxf): If request includes a body, copy it to the adapted wasi body
+ if incomingRequest.Body != nil {
+ // For client requests, the Transport is responsible for calling Close on request's body.
+ defer func() { _ = incomingRequest.Body.Close() }()
+ adaptedBody, err := newOutgoingBody(body)
+ if err != nil {
+ return nil, fmt.Errorf("failed to adapt body: %w", err)
+ }
+ if _, err := io.Copy(adaptedBody, incomingRequest.Body); err != nil {
+ return nil, fmt.Errorf("failed to copy body: %w", err)
+ }
+ if err := adaptedBody.Close(); err != nil {
+ return nil, fmt.Errorf("failed to close body: %w", err)
+ }
+ }
+
+ // From `outgoing-body` documentation:
+ // Finalize an outgoing body, optionally providing trailers. This must be
+ // called to signal that the response is complete.
+ outFinish := types.OutgoingBodyFinish(body, maybeTrailers)
+ if outFinish.IsErr() {
+ return nil, fmt.Errorf("failed to finish body: %v", outFinish.Err())
+ }
+
+ // wait until resp is returned
+ pollable := futureResponse.Subscribe()
+ pollable.Block()
+ pollable.Drop()
+
+ incomingResponseOuterOption := futureResponse.Get()
+ if incomingResponseOuterOption.IsNone() {
+ // NOTE: This should never happen since we subscribe to response readiness above
+ return nil, fmt.Errorf("failed to wait for future-incoming-response readiness")
+ }
+
+ // Unwrap the outer Option and the outer Result within it
+ outerResult := incomingResponseOuterOption.Some()
+ if outerResult.IsErr() {
+ return nil, fmt.Errorf("failed to unwrap the outer result for incoming-response")
+ }
+
+ // Unwrap the inner Result
+ innerResult := outerResult.Ok()
+ if innerResult.IsErr() {
+ return nil, fmt.Errorf("failed to unwrap the inner result for incoming-response: %v", innerResult.Err())
+ }
+ incomingResponse := innerResult.Ok()
+
+ incomingBody, incomingTrailers, err := newIncomingBodyTrailer(incomingResponse)
+ if err != nil {
+ return nil, fmt.Errorf("failed to parse incoming-response: %w", err)
+ }
+
+ incomingHeaders := http.Header{}
+ headers := incomingResponse.Headers()
+ wasiToHTTPHeader(headers, &incomingHeaders)
+ headers.Drop()
+
+ resp := &http.Response{
+ StatusCode: int(incomingResponse.Status()),
+ Status: http.StatusText(int(incomingResponse.Status())),
+ Request: incomingRequest,
+ Header: incomingHeaders,
+ Body: incomingBody,
+ Trailer: incomingTrailers,
+ }
+
+ return resp, nil
+}
diff --git a/wasihttp/roundtripper_p3.go b/wasihttp/roundtripper_p3.go
new file mode 100644
index 0000000..7127867
--- /dev/null
+++ b/wasihttp/roundtripper_p3.go
@@ -0,0 +1,169 @@
+//go:build componentizego_async
+
+package wasihttp
+
+import (
+ "fmt"
+ "io"
+ "net/http"
+ "os"
+ "time"
+
+ client "go.bytecodealliance.org/pkg/imports/wasi_http_0_3_0_client"
+ types "go.bytecodealliance.org/pkg/imports/wasi_http_0_3_0_types"
+ "go.bytecodealliance.org/pkg/internal/httpconv"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+)
+
+// Transport implements [http.RoundTripper] for [wasi:http].
+//
+// [wasi:http]: https://github.com/WebAssembly/wasi-http/tree/v0.3.0
+type Transport struct {
+ ConnectTimeout time.Duration
+}
+
+var _ http.RoundTripper = (*Transport)(nil)
+
+// DefaultTransport is the default implementation of [Transport] and is used by [DefaultClient].
+// It is configured to use the same timeout value as [net/http.DefaultTransport].
+var DefaultTransport = &Transport{
+ ConnectTimeout: 30 * time.Second,
+}
+
+// DefaultClient is the default [net/http.Client] that uses [DefaultTransport] to adapt [net/http] to [wasi:http].
+//
+// [wasi:http]: https://github.com/WebAssembly/wasi-http/tree/v0.3.0
+var DefaultClient = &http.Client{Transport: DefaultTransport}
+
+func (t *Transport) requestOptions() witTypes.Option[*types.RequestOptions] {
+ if t.ConnectTimeout <= 0 {
+ return witTypes.None[*types.RequestOptions]()
+ }
+ options := types.MakeRequestOptions()
+ // Both time.Duration and wasi:clocks duration are nanosecond counts.
+ options.SetConnectTimeout(witTypes.Some(uint64(t.ConnectTimeout)))
+ return witTypes.Some(options)
+}
+
+// RoundTrip implements the [net/http.RoundTripper] interface.
+func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
+ request, err := t.toWASIRequest(req)
+ if err != nil {
+ return nil, err
+ }
+
+ result := client.Send(request)
+ if result.IsErr() {
+ return nil, fmt.Errorf("error sending request: %s", errorCodeString(result.Err()))
+ }
+
+ response := result.Ok()
+ status := int(response.GetStatusCode())
+
+ headerResource := response.GetHeaders()
+ entries := headerResource.CopyAll()
+ headerResource.Drop()
+
+ stream, trailers := types.ResponseConsumeBody(response, unitFuture())
+ body := newBodyReader(stream, trailers)
+
+ resp := &http.Response{
+ StatusCode: status,
+ Status: http.StatusText(status),
+ Request: req,
+ Header: http.Header{},
+ Body: body,
+ Trailer: body.trailer,
+ }
+ httpconv.AddEntries(resp.Header, entries)
+
+ return resp, nil
+}
+
+// toWASIRequest converts an outbound [net/http.Request] into a wasi:http
+// Request. The request body (if any) is streamed from a goroutine, followed by
+// the request trailers, so the caller can send the request before the body has
+// been fully produced.
+func (t *Transport) toWASIRequest(req *http.Request) (*types.Request, error) {
+ headers, err := toWASIHeaders(req.Header)
+ if err != nil {
+ return nil, fmt.Errorf("failed to convert outgoing headers: %w", err)
+ }
+
+ trailersTx, trailersRx := types.MakeFutureResultOptionFieldsErrorCode()
+
+ body := witTypes.None[*witTypes.StreamReader[uint8]]()
+ if req.Body == nil {
+ go writeTrailers(trailersTx, req.Trailer)
+ } else {
+ tx, rx := types.MakeStreamU8()
+ body = witTypes.Some(rx)
+ go func() {
+ // For client requests, the Transport is responsible for closing the body.
+ defer req.Body.Close()
+ defer writeTrailers(trailersTx, req.Trailer)
+ defer tx.Drop()
+
+ buf := make([]uint8, 16*1024)
+ for !tx.ReaderDropped() {
+ n, err := req.Body.Read(buf)
+ if n > 0 {
+ tx.WriteAll(buf[:n])
+ }
+ if err != nil {
+ if err != io.EOF {
+ fmt.Fprintf(os.Stderr, "error reading request body: %v\n", err)
+ }
+ return
+ }
+ }
+ }()
+ }
+
+ request, sent := types.RequestNew(headers, body, trailersRx, t.requestOptions())
+ // TODO(#wasihttp3): surface body-delivery errors instead of dropping them.
+ sent.Drop()
+
+ request.SetMethod(toWASIMethod(req.Method))
+
+ authority := req.Host
+ if authority == "" {
+ authority = req.URL.Host
+ }
+ request.SetAuthority(witTypes.Some(authority))
+ request.SetPathWithQuery(witTypes.Some(req.URL.RequestURI()))
+
+ switch req.URL.Scheme {
+ case "http":
+ request.SetScheme(witTypes.Some(types.MakeSchemeHttp()))
+ case "https":
+ request.SetScheme(witTypes.Some(types.MakeSchemeHttps()))
+ default:
+ request.SetScheme(witTypes.Some(types.MakeSchemeOther(req.URL.Scheme)))
+ }
+
+ return request, nil
+}
+
+// writeTrailers resolves an outbound request's trailers future once the body
+// (if any) has been fully written.
+func writeTrailers(
+ tx *witTypes.FutureWriter[witTypes.Result[witTypes.Option[*types.Fields], types.ErrorCode]],
+ trailer http.Header,
+) {
+ defer tx.Drop()
+
+ if len(trailer) == 0 {
+ tx.Write(witTypes.Ok[witTypes.Option[*types.Fields], types.ErrorCode](witTypes.None[*types.Fields]()))
+ return
+ }
+
+ fields, err := toWASIHeaders(trailer)
+ if err != nil {
+ tx.Write(witTypes.Err[witTypes.Option[*types.Fields]](
+ types.MakeErrorCodeInternalError(witTypes.Some(fmt.Sprintf("cannot send trailers: %v", err))),
+ ))
+ return
+ }
+ tx.Write(witTypes.Ok[witTypes.Option[*types.Fields], types.ErrorCode](witTypes.Some(fields)))
+}
diff --git a/wasihttp/server_p2.go b/wasihttp/server_p2.go
new file mode 100644
index 0000000..b592f26
--- /dev/null
+++ b/wasihttp/server_p2.go
@@ -0,0 +1,59 @@
+//go:build !componentizego_async
+
+package wasihttp
+
+import (
+ "fmt"
+ "net/http"
+ "os"
+
+ incominghandler "go.bytecodealliance.org/pkg/exports/bytecodealliance_pkg_wasip2_0_1_0/export_wasi_http_0_2_8_incoming_handler"
+ types "go.bytecodealliance.org/pkg/imports/wasi_http_0_2_8_types"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+
+ // Pull in the //go:wasmexport glue for the component's exports.
+ _ "go.bytecodealliance.org/pkg/exports/bytecodealliance_pkg_wasip2_0_1_0/wit_exports"
+)
+
+func init() {
+ incominghandler.Exports.Handle = wasiHandle
+}
+
+// handlerFn is the function called by the wasi:http/incoming-handler export.
+var handlerFn = defaultHandler
+
+// defaultHandler is a placeholder for returning a useful error to stderr when
+// the handler is not set.
+var defaultHandler = func(http.ResponseWriter, *http.Request) {
+ fmt.Fprintln(os.Stderr, "http handler undefined")
+}
+
+// Handle sets the [net/http.Handler] that will be called to handle the
+// incoming request. It must be called from an init() function.
+func Handle(h http.Handler) {
+ handlerFn = h.ServeHTTP
+}
+
+// HandleFunc sets the [net/http.HandlerFunc] that will be called to handle the
+// incoming request. It must be called from an init() function.
+func HandleFunc(h http.HandlerFunc) {
+ handlerFn = h
+}
+
+func wasiHandle(request *types.IncomingRequest, responseOut *types.ResponseOutparam) {
+ httpReq, err := wasiToHTTPRequest(request)
+ if err != nil {
+ types.ResponseOutparamSet(responseOut, witTypes.Err[*types.OutgoingResponse, types.ErrorCode](
+ types.MakeErrorCodeInternalError(witTypes.Some(err.Error()))),
+ )
+ return
+ }
+ if httpReq.Body != nil {
+ defer func() { _ = httpReq.Body.Close() }()
+ }
+
+ httpRes := newResponseOutparamWriter(responseOut)
+ defer func() { _ = httpRes.Close() }()
+
+ handlerFn(httpRes, httpReq)
+}
diff --git a/wasihttp/server_p3.go b/wasihttp/server_p3.go
new file mode 100644
index 0000000..b1c4614
--- /dev/null
+++ b/wasihttp/server_p3.go
@@ -0,0 +1,79 @@
+//go:build componentizego_async
+
+package wasihttp
+
+import (
+ "fmt"
+ "net/http"
+ "os"
+
+ handler "go.bytecodealliance.org/pkg/exports/bytecodealliance_pkg_wasip3_0_1_0/export_wasi_http_0_3_0_handler"
+ _ "go.bytecodealliance.org/pkg/exports/bytecodealliance_pkg_wasip3_0_1_0/wit_exports"
+ types "go.bytecodealliance.org/pkg/imports/wasi_http_0_3_0_types"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+)
+
+func init() {
+ handler.Exports.Handle = wasiHandle
+}
+
+// handlerFn is the function called by the wasi:http/handler export.
+var handlerFn = defaultHandler
+
+// defaultHandler is a placeholder for returning a useful error to stderr when
+// the handler is not set.
+var defaultHandler = func(http.ResponseWriter, *http.Request) {
+ fmt.Fprintln(os.Stderr, "http handler undefined")
+}
+
+// Handle sets the [net/http.Handler] that will be called to handle the
+// incoming request. It must be called from an init() function.
+func Handle(h http.Handler) {
+ handlerFn = h.ServeHTTP
+}
+
+// HandleFunc sets the [net/http.HandlerFunc] that will be called to handle the
+// incoming request. It must be called from an init() function.
+func HandleFunc(h http.HandlerFunc) {
+ handlerFn = h
+}
+
+// wasiHandle bridges the async wasi:http/handler export to the registered
+// net/http handler. The handler runs in a goroutine; wasiHandle returns the
+// wasi Response as soon as the handler produces headers so the response body
+// can stream while the handler is still writing.
+func wasiHandle(request *types.Request) witTypes.Result[*types.Response, types.ErrorCode] {
+ res := newResponseWriter()
+
+ go func() {
+ defer res.close()
+
+ req, err := wasiToHTTPRequest(request)
+ if err != nil {
+ res.channel <- witTypes.Err[*types.Response](
+ types.MakeErrorCodeInternalError(witTypes.Some(fmt.Sprintf(
+ "failed to convert wasi:http request to http.Request: %v", err,
+ ))),
+ )
+ return
+ }
+ defer req.Body.Close()
+
+ handlerFn(res, req)
+
+ // If the handler never wrote to the body, the response has not been
+ // sent yet; send it now with headers and status code only.
+ if err := res.send(); err != nil {
+ res.channel <- witTypes.Err[*types.Response](
+ types.MakeErrorCodeInternalError(witTypes.Some(fmt.Sprintf(
+ "failed to produce a response: %v", err,
+ ))),
+ )
+ return
+ }
+
+ res.writeTrailers()
+ }()
+
+ return <-res.channel
+}
diff --git a/wasihttp/streams_p2.go b/wasihttp/streams_p2.go
new file mode 100644
index 0000000..38e57e5
--- /dev/null
+++ b/wasihttp/streams_p2.go
@@ -0,0 +1,177 @@
+//go:build !componentizego_async
+
+package wasihttp
+
+import (
+ "errors"
+ "fmt"
+ "io"
+ "net/http"
+ "sync"
+
+ types "go.bytecodealliance.org/pkg/imports/wasi_http_0_2_8_types"
+ streams "go.bytecodealliance.org/pkg/imports/wasi_io_0_2_8_streams"
+ "go.bytecodealliance.org/pkg/internal/httpconv"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+)
+
+// bodyConsumer is implemented by [types.IncomingRequest] and
+// [types.IncomingResponse]. It enables the consumption of
+// [wasi:http/types.incoming-request] and [wasi:http/types.incoming-response].
+//
+// [wasi:http/types.incoming-request]: https://github.com/WebAssembly/wasi-http/blob/main/wit/types.wit
+// [wasi:http/types.incoming-response]: https://github.com/WebAssembly/wasi-http/blob/main/wit/types.wit
+type bodyConsumer interface {
+ Consume() witTypes.Result[*types.IncomingBody, witTypes.Unit]
+ Headers() *types.Fields
+}
+
+type inputStreamReader struct {
+ consumer bodyConsumer
+ body *types.IncomingBody
+ stream *streams.InputStream
+ trailerLock sync.Mutex
+ trailers http.Header
+ trailerOnce sync.Once
+}
+
+func (r *inputStreamReader) Close() error {
+ r.trailerOnce.Do(r.parseTrailers)
+
+ if r.stream != nil {
+ r.stream.Drop()
+ }
+
+ if r.body != nil {
+ r.body.Drop()
+ r.body = nil
+ }
+
+ return nil
+}
+
+func (r *inputStreamReader) parseTrailers() {
+ r.trailerLock.Lock()
+ defer r.trailerLock.Unlock()
+
+ // if we got this far, then we release ownership from body, otherwise it is our responsibility to drop it
+ r.stream.Drop()
+ r.stream = nil
+
+ futureTrailers := types.IncomingBodyFinish(r.body)
+ defer futureTrailers.Drop()
+
+ trailersResult := futureTrailers.Get()
+ r.body = nil
+
+ // unroll the future
+ if trailersResult.IsNone() {
+ return
+ }
+ if trailersResult.Some().IsErr() {
+ return
+ }
+ if trailersResult.Some().Ok().IsErr() {
+ return
+ }
+ maybeWasiTrailers := trailersResult.Some().Ok().Ok()
+
+ if maybeWasiTrailers.IsNone() {
+ return
+ }
+
+ wasiTrailers := maybeWasiTrailers.Some()
+ httpconv.AddEntries(r.trailers, wasiTrailers.Entries())
+
+ wasiTrailers.Drop()
+}
+
+func (r *inputStreamReader) Read(p []byte) (n int, err error) {
+ pollable := r.stream.Subscribe()
+ pollable.Block()
+ pollable.Drop()
+
+ readResult := r.stream.Read(uint64(len(p)))
+ if readResult.IsErr() {
+ streamErr := readResult.Err()
+ if streamErr.Tag() == streams.StreamErrorClosed {
+ r.trailerOnce.Do(r.parseTrailers)
+ return 0, io.EOF
+ }
+ return 0, fmt.Errorf("failed to read from InputStream %s", streamErr.LastOperationFailed().ToDebugString())
+ }
+
+ contents := readResult.Ok()
+ copy(p, contents)
+ return len(contents), nil
+}
+
+// newIncomingBodyTrailer takes a [bodyConsumer] and parses it into a
+// corresponding [io.ReadCloser] and [net/http.Header].
+func newIncomingBodyTrailer(consumer bodyConsumer) (io.ReadCloser, http.Header, error) {
+ consumeResult := consumer.Consume()
+ if consumeResult.IsErr() {
+ return nil, nil, errors.New("failed to consume incoming request")
+ }
+
+ body := consumeResult.Ok()
+ streamResult := body.Stream()
+ if streamResult.IsErr() {
+ return nil, nil, errors.New("failed to consume incoming request body stream")
+ }
+
+ stream := streamResult.Ok()
+
+ trailers := http.Header{}
+ return &inputStreamReader{
+ consumer: consumer,
+ trailers: trailers,
+ body: body,
+ stream: stream,
+ }, trailers, nil
+}
+
+type outgoingBody struct {
+ body *types.OutgoingBody
+ stream *streams.OutputStream
+}
+
+// newOutgoingBody takes a [types.OutgoingBody] and returns an [io.WriteCloser]
+// encapsulating it.
+func newOutgoingBody(body *types.OutgoingBody) (io.WriteCloser, error) {
+ stream := body.Write()
+ if stream.IsErr() {
+ return nil, errors.New("failed to acquire resource handle to request body")
+ }
+ return &outgoingBody{
+ body: body,
+ stream: stream.Ok(),
+ }, nil
+}
+
+func (r *outgoingBody) Close() error {
+ r.stream.Drop()
+ return nil
+}
+
+func (r *outgoingBody) Write(p []byte) (n int, err error) {
+ // Split the input into 4096-byte chunks to avoid exceeding stream buffer limits
+ const chunkSize = 4096
+ totalWritten := 0
+
+ for offset := 0; offset < len(p); offset += chunkSize {
+ end := min(offset+chunkSize, len(p))
+
+ writeResult := r.stream.BlockingWriteAndFlush(p[offset:end])
+ if writeResult.IsErr() {
+ streamErr := writeResult.Err()
+ if streamErr.Tag() == streams.StreamErrorClosed {
+ return totalWritten, io.EOF
+ }
+ return totalWritten, fmt.Errorf("failed to write to response body's stream: %s", streamErr.LastOperationFailed().ToDebugString())
+ }
+
+ totalWritten += end - offset
+ }
+ return totalWritten, nil
+}
diff --git a/wasihttp/streams_p3.go b/wasihttp/streams_p3.go
new file mode 100644
index 0000000..1747330
--- /dev/null
+++ b/wasihttp/streams_p3.go
@@ -0,0 +1,84 @@
+//go:build componentizego_async
+
+package wasihttp
+
+import (
+ "fmt"
+ "io"
+ "net/http"
+
+ types "go.bytecodealliance.org/pkg/imports/wasi_http_0_3_0_types"
+ "go.bytecodealliance.org/pkg/internal/httpconv"
+ witTypes "go.bytecodealliance.org/pkg/wit/types"
+)
+
+var _ io.ReadCloser = (*bodyReader)(nil)
+
+type trailersFutureReader = witTypes.FutureReader[witTypes.Result[witTypes.Option[*types.Fields], types.ErrorCode]]
+
+// bodyReader adapts a wasi:http body (a stream of bytes plus a future that
+// resolves to optional trailers) into an [io.ReadCloser]. When the stream is
+// exhausted the trailers future is read: an error there is surfaced from Read,
+// otherwise any trailers are copied into trailer and Read returns [io.EOF].
+type bodyReader struct {
+ stream *witTypes.StreamReader[uint8]
+ trailers *trailersFutureReader
+ // trailer is populated once the body has been fully read. Callers share
+ // this map via http.Request.Trailer / http.Response.Trailer.
+ trailer http.Header
+}
+
+func newBodyReader(stream *witTypes.StreamReader[uint8], trailers *trailersFutureReader) *bodyReader {
+ return &bodyReader{
+ stream: stream,
+ trailers: trailers,
+ trailer: http.Header{},
+ }
+}
+
+func (r *bodyReader) Read(p []byte) (int, error) {
+ if r.stream.WriterDropped() {
+ return 0, r.finish()
+ }
+
+ count := r.stream.Read(p)
+ if count == 0 && r.stream.WriterDropped() {
+ return 0, r.finish()
+ }
+
+ return int(count), nil
+}
+
+// finish consumes the trailers future after the body stream has ended,
+// returning the transport error if there was one and io.EOF otherwise.
+func (r *bodyReader) finish() error {
+ if r.trailers == nil {
+ return io.EOF
+ }
+
+ result := r.trailers.Read()
+ r.trailers = nil
+ if result.IsErr() {
+ return fmt.Errorf("failed to read from HTTP body stream: %s", errorCodeString(result.Err()))
+ }
+
+ if fields := result.Ok(); fields.IsSome() {
+ trailers := fields.Some()
+ httpconv.AddEntries(r.trailer, trailers.CopyAll())
+ trailers.Drop()
+ }
+
+ return io.EOF
+}
+
+func (r *bodyReader) Close() error {
+ if r.stream != nil {
+ r.stream.Drop()
+ r.stream = nil
+ }
+ if r.trailers != nil {
+ r.trailers.Drop()
+ r.trailers = nil
+ }
+ return nil
+}
diff --git a/wasilog/slog.go b/wasilog/slog.go
new file mode 100644
index 0000000..879c2e2
--- /dev/null
+++ b/wasilog/slog.go
@@ -0,0 +1,215 @@
+package wasilog
+
+import (
+ "context"
+ "fmt"
+ "log/slog"
+ "strings"
+
+ logging "go.bytecodealliance.org/pkg/imports/wasi_logging_0_1_0_draft_logging"
+)
+
+// DefaultLogger is the default implementation that adapts the [wasi:logging] interface to a [slog.Handler].
+//
+// [wasi:logging]: https://github.com/WebAssembly/wasi-logging
+var DefaultLogger = slog.New(DefaultOptions().NewHandler())
+
+// ContextLogger returns a [DefaultLogger] implementation that has an additional "wasi-context" [slog.Attr] attached to it.
+func ContextLogger(wasiContext string) *slog.Logger {
+ return DefaultLogger.With(ContextAttr(wasiContext))
+}
+
+type contextKey string
+
+func (k contextKey) String() string {
+ return string(k)
+}
+
+// ContextKey is a predefined key used to track the wasi
+const ContextKey = contextKey("wasi-context")
+
+func ContextAttr(name string) slog.Attr {
+ return slog.String(string(ContextKey), name)
+}
+
+type wasmLoggerFunc func(level logging.Level, context string, message string)
+
+// WasiLoggingOption represents the available options for customizing the [WebassemblyHandler].
+type WasiLoggingOption struct {
+ // required: log function
+ LoggerFunc wasmLoggerFunc
+ // log level (default: info)
+ Level slog.Leveler
+
+ // optional: fetch attributes from context
+ AttrFromContext []func(ctx context.Context) []slog.Attr
+
+ // optional: replace attributes
+ ReplaceAttr func(groups []string, a slog.Attr) slog.Attr
+}
+
+// WebassemblyHandler implements the [slog.Handler] interface to adapt [slog] to wasi:logging.
+type WebassemblyHandler struct {
+ option WasiLoggingOption
+ attrs []slog.Attr
+ groups []string
+}
+
+var _ slog.Handler = (*WebassemblyHandler)(nil)
+
+func wasiLevel(level slog.Level) logging.Level {
+ switch level {
+ case slog.LevelDebug:
+ return logging.LevelDebug
+ case slog.LevelInfo:
+ return logging.LevelInfo
+ case slog.LevelWarn:
+ return logging.LevelWarn
+ case slog.LevelError:
+ return logging.LevelError
+ default:
+ return logging.LevelDebug
+ }
+}
+
+// contextAttrs collects attributes from the context using the configured
+// AttrFromContext extractors.
+func contextAttrs(ctx context.Context, fns []func(ctx context.Context) []slog.Attr) []slog.Attr {
+ var attrs []slog.Attr
+ for _, fn := range fns {
+ attrs = append(attrs, fn(ctx)...)
+ }
+ return attrs
+}
+
+// flatten reduces attrs to leaf attributes: group values are descended with
+// their names appended to the group path, LogValuers are resolved, and
+// replaceAttr is applied to each leaf with its group path (the default
+// ReplaceAttr folds the path into the key, e.g. "a.b.c"). Attributes with an
+// empty key or empty value are dropped.
+func flatten(replaceAttr func(groups []string, a slog.Attr) slog.Attr, groups []string, attrs []slog.Attr) []slog.Attr {
+ var output []slog.Attr
+ for _, attr := range attrs {
+ attr.Value = attr.Value.Resolve()
+ if attr.Value.Kind() == slog.KindGroup {
+ g := groups
+ if attr.Key != "" {
+ g = append(groups[:len(groups):len(groups)], attr.Key)
+ }
+ output = append(output, flatten(replaceAttr, g, attr.Value.Group())...)
+ continue
+ }
+ if replaceAttr != nil {
+ attr = replaceAttr(groups, attr)
+ attr.Value = attr.Value.Resolve()
+ }
+ if attr.Key == "" || attr.Value.Equal(slog.Value{}) {
+ continue
+ }
+ output = append(output, attr)
+ }
+ return output
+}
+
+func wasiConverter(replaceAttr func(groups []string, a slog.Attr) slog.Attr, loggerAttr []slog.Attr, groups []string, record *slog.Record) (string, string) {
+ recordAttrs := make([]slog.Attr, 0, record.NumAttrs())
+ record.Attrs(func(a slog.Attr) bool {
+ recordAttrs = append(recordAttrs, a)
+ return true
+ })
+
+ attrs := flatten(replaceAttr, nil, loggerAttr)
+ attrs = append(attrs, flatten(replaceAttr, groups, recordAttrs)...)
+
+ // The context key is moved to the 'Context' field in wasi:logging and
+ // removed from the log message.
+ var context string
+ parts := make([]string, 0, len(attrs)+1)
+ for _, attr := range attrs {
+ if attr.Key == string(ContextKey) {
+ context = attr.Value.String()
+ continue
+ }
+ parts = append(parts, fmt.Sprintf("%s=%q", attr.Key, attr.Value.String()))
+ }
+ parts = append(parts, record.Message)
+
+ return strings.Join(parts, " "), context
+}
+
+// DefaultOptions represents the default set of values used in [WasiLoggingOption] that are used in setting up [DefaultLogger].
+func DefaultOptions() WasiLoggingOption {
+ return WasiLoggingOption{
+ LoggerFunc: logging.Log,
+ Level: slog.LevelInfo,
+ AttrFromContext: []func(ctx context.Context) []slog.Attr{
+ func(ctx context.Context) []slog.Attr {
+ if contextName, ok := ctx.Value(ContextKey).(string); ok {
+ return []slog.Attr{slog.String(string(ContextKey), string(contextName))}
+ }
+ return nil
+ },
+ },
+ ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
+ // Make so groups become a prefix of the key
+ // Ex: groups = ["a", "b"], key = "c" => "a.b.c"
+ if len(groups) == 0 {
+ return a
+ }
+
+ a.Key = strings.Join(groups, ".") + "." + a.Key
+ return a
+ },
+ }
+}
+
+// NewHandler is used to instantiate a new instance of a [WebassemblyHandler] that implements the [slog.Handler] interface.
+func (o WasiLoggingOption) NewHandler() slog.Handler {
+ return &WebassemblyHandler{
+ option: o,
+ }
+}
+
+// Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower.
+func (h *WebassemblyHandler) Enabled(_ context.Context, level slog.Level) bool {
+ return level >= h.option.Level.Level()
+}
+
+// Handle formats its argument [slog.Record] using the provided [context.Context] into a wasi:logging compatible output.
+func (h *WebassemblyHandler) Handle(ctx context.Context, record slog.Record) error {
+ fromContext := contextAttrs(ctx, h.option.AttrFromContext)
+ loggerAttr := append(h.attrs[:len(h.attrs):len(h.attrs)], fromContext...)
+ message, logContext := wasiConverter(h.option.ReplaceAttr, loggerAttr, h.groups, &record)
+
+ h.option.LoggerFunc(wasiLevel(record.Level), logContext, message)
+
+ return nil
+}
+
+// WithAttrs returns a new [WebassemblyHandler] whose attributes consists
+// of h's attributes followed by attrs, nested under the currently open groups.
+func (h *WebassemblyHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
+ for i := len(h.groups) - 1; i >= 0; i-- {
+ attrs = []slog.Attr{{Key: h.groups[i], Value: slog.GroupValue(attrs...)}}
+ }
+ return &WebassemblyHandler{
+ option: h.option,
+ attrs: append(h.attrs[:len(h.attrs):len(h.attrs)], attrs...),
+ groups: h.groups,
+ }
+}
+
+// WithGroup returns a new [WebassemblyHandler] where the attributes are
+// grouped under a common name.
+func (h *WebassemblyHandler) WithGroup(name string) slog.Handler {
+ // https://cs.opensource.google/go/x/exp/+/46b07846:slog/handler.go;l=247
+ if name == "" {
+ return h
+ }
+
+ return &WebassemblyHandler{
+ option: h.option,
+ attrs: h.attrs,
+ groups: append(h.groups[:len(h.groups):len(h.groups)], name),
+ }
+}
diff --git a/wasilog/slog_stub_test.go b/wasilog/slog_stub_test.go
new file mode 100644
index 0000000..b794cb7
--- /dev/null
+++ b/wasilog/slog_stub_test.go
@@ -0,0 +1,15 @@
+//go:build !wasm
+
+package wasilog
+
+import (
+ _ "unsafe"
+)
+
+// wasmimportLog provides a host-side body for the wasi:logging `log` import
+// so this package's tests can link and run on non-wasm platforms. On wasm
+// targets the real //go:wasmimport declaration provides the symbol.
+//
+//go:linkname wasmimportLog go.bytecodealliance.org/pkg/imports/wasi_logging_0_1_0_draft_logging.wasm_import_log
+func wasmimportLog(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32) {
+}
diff --git a/wasilog/slog_test.go b/wasilog/slog_test.go
new file mode 100644
index 0000000..be214fb
--- /dev/null
+++ b/wasilog/slog_test.go
@@ -0,0 +1,141 @@
+package wasilog
+
+import (
+ "context"
+ "fmt"
+ "log/slog"
+ "testing"
+
+ logging "go.bytecodealliance.org/pkg/imports/wasi_logging_0_1_0_draft_logging"
+)
+
+func TestLogLevelMapping(t *testing.T) {
+ tt := map[string]struct {
+ wasiLevel logging.Level
+ slogLevel slog.Level
+ }{
+ "debug": {
+ wasiLevel: logging.LevelDebug,
+ slogLevel: slog.LevelDebug,
+ },
+ "info": {
+ wasiLevel: logging.LevelInfo,
+ slogLevel: slog.LevelInfo,
+ },
+ "warn": {
+ wasiLevel: logging.LevelWarn,
+ slogLevel: slog.LevelWarn,
+ },
+ "error": {
+ wasiLevel: logging.LevelError,
+ slogLevel: slog.LevelError,
+ },
+ }
+
+ for name, tc := range tt {
+ t.Run(name, func(t *testing.T) {
+ output := func(level logging.Level, _ string, _ string) {
+ if level != tc.wasiLevel {
+ t.Errorf("expected: %v, got: %v", tc.wasiLevel, level)
+ }
+ }
+ options := DefaultOptions()
+ options.LoggerFunc = output
+ logger := slog.New(options.NewHandler())
+ logger.Log(context.TODO(), tc.slogLevel, "test")
+ })
+ }
+}
+
+func TestDefaultLevel(t *testing.T) {
+ // default level is info
+ // debug -> info -> warn -> error
+ // not all wasi levels are mapped (ex: trace & fatal)
+
+ allLevels := []slog.Level{
+ slog.LevelDebug,
+ slog.LevelInfo,
+ slog.LevelWarn,
+ slog.LevelError,
+ }
+
+ for i, defaultLevel := range allLevels {
+ for j, emitLevel := range allLevels {
+ t.Run(fmt.Sprintf("%s_%s", defaultLevel, emitLevel), func(t *testing.T) {
+ output := func(level logging.Level, _ string, _ string) {
+ if i > j {
+ t.Errorf("Emitted log level %v is lower than default log level %v", emitLevel, defaultLevel)
+ }
+ }
+ options := DefaultOptions()
+ options.LoggerFunc = output
+ options.Level = defaultLevel
+ logger := slog.New(options.NewHandler())
+ logger.Log(context.TODO(), emitLevel, "test")
+ })
+ }
+ }
+}
+
+func TestContextLift(t *testing.T) {
+ // preferred
+ t.Run("With", func(t *testing.T) {
+ output := func(_ logging.Level, context string, _ string) {
+ if context != "from_with" {
+ t.Errorf("expected: %v, got: %v", "from_context", context)
+ }
+ }
+ options := DefaultOptions()
+ options.LoggerFunc = output
+ logger := slog.New(options.NewHandler())
+ logger = logger.With(ContextAttr("from_with"))
+ logger.Log(context.TODO(), slog.LevelInfo, "test")
+ })
+ t.Run("attribute", func(t *testing.T) {
+ output := func(_ logging.Level, context string, _ string) {
+ if context != "from_attribute" {
+ t.Errorf("expected: %v, got: %v", "from_attribute", context)
+ }
+ }
+ options := DefaultOptions()
+ options.LoggerFunc = output
+ logger := slog.New(options.NewHandler())
+ logger.Log(context.Background(), slog.LevelInfo, "test", ContextAttr("from_attribute"))
+ logger.Log(context.Background(), slog.LevelInfo, "test", ContextKey.String(), "from_attribute")
+ logger.Log(context.Background(), slog.LevelInfo, "test", slog.String(ContextKey.String(), "from_attribute"))
+ logger.Log(context.Background(), slog.LevelInfo, "test", slog.Any(ContextKey.String(), "from_attribute"))
+ })
+
+ t.Run("context", func(t *testing.T) {
+ output := func(_ logging.Level, context string, _ string) {
+ if context != "from_context" {
+ t.Errorf("expected: %v, got: %v", "from_context", context)
+ }
+ }
+ options := DefaultOptions()
+ options.LoggerFunc = output
+ logger := slog.New(options.NewHandler())
+ ctx := context.WithValue(context.Background(), ContextKey, "from_context")
+ logger.Log(ctx, slog.LevelInfo, "test")
+ })
+}
+
+type Token string
+
+// LogValue implements slog.LogValuer.
+// It avoids revealing the token.
+func (Token) LogValue() slog.Value {
+ return slog.StringValue("REDACTED_TOKEN")
+}
+
+func TestLogValueMask(t *testing.T) {
+ output := func(_ logging.Level, _ string, msg string) {
+ if want, got := `token="REDACTED_TOKEN" test`, msg; got != want {
+ t.Errorf("expected: %v, got: %v", want, got)
+ }
+ }
+ options := DefaultOptions()
+ options.LoggerFunc = output
+ logger := slog.New(options.NewHandler())
+ logger.Info("test", "token", Token("launch-the-nukes-code"))
+}
diff --git a/wit/deps/wasi-cli-0.2.8/package.wit b/wit/deps/wasi-cli-0.2.8/package.wit
new file mode 100644
index 0000000..616ac73
--- /dev/null
+++ b/wit/deps/wasi-cli-0.2.8/package.wit
@@ -0,0 +1,233 @@
+package wasi:cli@0.2.8;
+
+@since(version = 0.2.0)
+interface environment {
+ /// Get the POSIX-style environment variables.
+ ///
+ /// Each environment variable is provided as a pair of string variable names
+ /// and string value.
+ ///
+ /// Morally, these are a value import, but until value imports are available
+ /// in the component model, this import function should return the same
+ /// values each time it is called.
+ @since(version = 0.2.0)
+ get-environment: func() -> list>;
+
+ /// Get the POSIX-style arguments to the program.
+ @since(version = 0.2.0)
+ get-arguments: func() -> list;
+
+ /// Return a path that programs should use as their initial current working
+ /// directory, interpreting `.` as shorthand for this.
+ @since(version = 0.2.0)
+ initial-cwd: func() -> option;
+}
+
+@since(version = 0.2.0)
+interface exit {
+ /// Exit the current instance and any linked instances.
+ @since(version = 0.2.0)
+ exit: func(status: result);
+
+ /// Exit the current instance and any linked instances, reporting the
+ /// specified status code to the host.
+ ///
+ /// The meaning of the code depends on the context, with 0 usually meaning
+ /// "success", and other values indicating various types of failure.
+ ///
+ /// This function does not return; the effect is analogous to a trap, but
+ /// without the connotation that something bad has happened.
+ @unstable(feature = cli-exit-with-code)
+ exit-with-code: func(status-code: u8);
+}
+
+@since(version = 0.2.0)
+interface run {
+ /// Run the program.
+ @since(version = 0.2.0)
+ run: func() -> result;
+}
+
+@since(version = 0.2.0)
+interface stdin {
+ @since(version = 0.2.0)
+ use wasi:io/streams@0.2.8.{input-stream};
+
+ @since(version = 0.2.0)
+ get-stdin: func() -> input-stream;
+}
+
+@since(version = 0.2.0)
+interface stdout {
+ @since(version = 0.2.0)
+ use wasi:io/streams@0.2.8.{output-stream};
+
+ @since(version = 0.2.0)
+ get-stdout: func() -> output-stream;
+}
+
+@since(version = 0.2.0)
+interface stderr {
+ @since(version = 0.2.0)
+ use wasi:io/streams@0.2.8.{output-stream};
+
+ @since(version = 0.2.0)
+ get-stderr: func() -> output-stream;
+}
+
+/// Terminal input.
+///
+/// In the future, this may include functions for disabling echoing,
+/// disabling input buffering so that keyboard events are sent through
+/// immediately, querying supported features, and so on.
+@since(version = 0.2.0)
+interface terminal-input {
+ /// The input side of a terminal.
+ @since(version = 0.2.0)
+ resource terminal-input;
+}
+
+/// Terminal output.
+///
+/// In the future, this may include functions for querying the terminal
+/// size, being notified of terminal size changes, querying supported
+/// features, and so on.
+@since(version = 0.2.0)
+interface terminal-output {
+ /// The output side of a terminal.
+ @since(version = 0.2.0)
+ resource terminal-output;
+}
+
+/// An interface providing an optional `terminal-input` for stdin as a
+/// link-time authority.
+@since(version = 0.2.0)
+interface terminal-stdin {
+ @since(version = 0.2.0)
+ use terminal-input.{terminal-input};
+
+ /// If stdin is connected to a terminal, return a `terminal-input` handle
+ /// allowing further interaction with it.
+ @since(version = 0.2.0)
+ get-terminal-stdin: func() -> option;
+}
+
+/// An interface providing an optional `terminal-output` for stdout as a
+/// link-time authority.
+@since(version = 0.2.0)
+interface terminal-stdout {
+ @since(version = 0.2.0)
+ use terminal-output.{terminal-output};
+
+ /// If stdout is connected to a terminal, return a `terminal-output` handle
+ /// allowing further interaction with it.
+ @since(version = 0.2.0)
+ get-terminal-stdout: func() -> option;
+}
+
+/// An interface providing an optional `terminal-output` for stderr as a
+/// link-time authority.
+@since(version = 0.2.0)
+interface terminal-stderr {
+ @since(version = 0.2.0)
+ use terminal-output.{terminal-output};
+
+ /// If stderr is connected to a terminal, return a `terminal-output` handle
+ /// allowing further interaction with it.
+ @since(version = 0.2.0)
+ get-terminal-stderr: func() -> option;
+}
+
+@since(version = 0.2.0)
+world imports {
+ @since(version = 0.2.0)
+ import environment;
+ @since(version = 0.2.0)
+ import exit;
+ @since(version = 0.2.0)
+ import wasi:io/error@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:io/poll@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:io/streams@0.2.8;
+ @since(version = 0.2.0)
+ import stdin;
+ @since(version = 0.2.0)
+ import stdout;
+ @since(version = 0.2.0)
+ import stderr;
+ @since(version = 0.2.0)
+ import terminal-input;
+ @since(version = 0.2.0)
+ import terminal-output;
+ @since(version = 0.2.0)
+ import terminal-stdin;
+ @since(version = 0.2.0)
+ import terminal-stdout;
+ @since(version = 0.2.0)
+ import terminal-stderr;
+ import wasi:clocks/monotonic-clock@0.2.8;
+ import wasi:clocks/wall-clock@0.2.8;
+ @unstable(feature = clocks-timezone)
+ import wasi:clocks/timezone@0.2.8;
+ import wasi:filesystem/types@0.2.8;
+ import wasi:filesystem/preopens@0.2.8;
+ import wasi:sockets/network@0.2.8;
+ import wasi:sockets/instance-network@0.2.8;
+ import wasi:sockets/udp@0.2.8;
+ import wasi:sockets/udp-create-socket@0.2.8;
+ import wasi:sockets/tcp@0.2.8;
+ import wasi:sockets/tcp-create-socket@0.2.8;
+ import wasi:sockets/ip-name-lookup@0.2.8;
+ import wasi:random/random@0.2.8;
+ import wasi:random/insecure@0.2.8;
+ import wasi:random/insecure-seed@0.2.8;
+}
+@since(version = 0.2.0)
+world command {
+ @since(version = 0.2.0)
+ import environment;
+ @since(version = 0.2.0)
+ import exit;
+ @since(version = 0.2.0)
+ import wasi:io/error@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:io/poll@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:io/streams@0.2.8;
+ @since(version = 0.2.0)
+ import stdin;
+ @since(version = 0.2.0)
+ import stdout;
+ @since(version = 0.2.0)
+ import stderr;
+ @since(version = 0.2.0)
+ import terminal-input;
+ @since(version = 0.2.0)
+ import terminal-output;
+ @since(version = 0.2.0)
+ import terminal-stdin;
+ @since(version = 0.2.0)
+ import terminal-stdout;
+ @since(version = 0.2.0)
+ import terminal-stderr;
+ import wasi:clocks/monotonic-clock@0.2.8;
+ import wasi:clocks/wall-clock@0.2.8;
+ @unstable(feature = clocks-timezone)
+ import wasi:clocks/timezone@0.2.8;
+ import wasi:filesystem/types@0.2.8;
+ import wasi:filesystem/preopens@0.2.8;
+ import wasi:sockets/network@0.2.8;
+ import wasi:sockets/instance-network@0.2.8;
+ import wasi:sockets/udp@0.2.8;
+ import wasi:sockets/udp-create-socket@0.2.8;
+ import wasi:sockets/tcp@0.2.8;
+ import wasi:sockets/tcp-create-socket@0.2.8;
+ import wasi:sockets/ip-name-lookup@0.2.8;
+ import wasi:random/random@0.2.8;
+ import wasi:random/insecure@0.2.8;
+ import wasi:random/insecure-seed@0.2.8;
+
+ @since(version = 0.2.0)
+ export run;
+}
diff --git a/wit/deps/wasi-cli-0.3.0/package.wit b/wit/deps/wasi-cli-0.3.0/package.wit
new file mode 100644
index 0000000..7aae56c
--- /dev/null
+++ b/wit/deps/wasi-cli-0.3.0/package.wit
@@ -0,0 +1,256 @@
+package wasi:cli@0.3.0;
+
+@since(version = 0.3.0)
+interface environment {
+ /// Get the POSIX-style environment variables.
+ ///
+ /// Each environment variable is provided as a pair of string variable names
+ /// and string value.
+ ///
+ /// Morally, these are a value import, but until value imports are available
+ /// in the component model, this import function should return the same
+ /// values each time it is called.
+ @since(version = 0.3.0)
+ get-environment: func() -> list>;
+
+ /// Get the POSIX-style arguments to the program.
+ @since(version = 0.3.0)
+ get-arguments: func() -> list;
+
+ /// Return a path that programs should use as their initial current working
+ /// directory, interpreting `.` as shorthand for this.
+ @since(version = 0.3.0)
+ get-initial-cwd: func() -> option;
+}
+
+@since(version = 0.3.0)
+interface exit {
+ /// Exit the current instance and any linked instances.
+ @since(version = 0.3.0)
+ exit: func(status: result);
+
+ /// Exit the current instance and any linked instances, reporting the
+ /// specified status code to the host.
+ ///
+ /// The meaning of the code depends on the context, with 0 usually meaning
+ /// "success", and other values indicating various types of failure.
+ ///
+ /// This function does not return; the effect is analogous to a trap, but
+ /// without the connotation that something bad has happened.
+ @since(version = 0.3.0)
+ exit-with-code: func(status-code: u8);
+}
+
+@since(version = 0.3.0)
+interface run {
+ /// Run the program.
+ @since(version = 0.3.0)
+ run: async func() -> result;
+}
+
+@since(version = 0.3.0)
+interface types {
+ @since(version = 0.3.0)
+ enum error-code {
+ /// Input/output error
+ io,
+ /// Invalid or incomplete multibyte or wide character
+ illegal-byte-sequence,
+ /// Broken pipe
+ pipe,
+ }
+}
+
+@since(version = 0.3.0)
+interface stdin {
+ use types.{error-code};
+
+ /// Return a stream for reading from stdin.
+ ///
+ /// This function returns a stream which provides data read from stdin,
+ /// and a future to signal read results.
+ ///
+ /// If the stream's readable end is dropped the future will resolve to success.
+ ///
+ /// If the stream's writable end is dropped the future will either resolve to
+ /// success if stdin was closed by the writer or to an error-code if reading
+ /// failed for some other reason.
+ ///
+ /// Multiple streams may be active at the same time. The behavior of concurrent
+ /// reads is implementation-specific.
+ @since(version = 0.3.0)
+ read-via-stream: func() -> tuple, future>>;
+}
+
+@since(version = 0.3.0)
+interface stdout {
+ use types.{error-code};
+
+ /// Write the given stream to stdout.
+ ///
+ /// If the stream's writable end is dropped this function will either return
+ /// success once the entire contents of the stream have been written or an
+ /// error-code representing a failure.
+ ///
+ /// Otherwise if there is an error the readable end of the stream will be
+ /// dropped and this function will return an error-code.
+ @since(version = 0.3.0)
+ write-via-stream: func(data: stream) -> future>;
+}
+
+@since(version = 0.3.0)
+interface stderr {
+ use types.{error-code};
+
+ /// Write the given stream to stderr.
+ ///
+ /// If the stream's writable end is dropped this function will either return
+ /// success once the entire contents of the stream have been written or an
+ /// error-code representing a failure.
+ ///
+ /// Otherwise if there is an error the readable end of the stream will be
+ /// dropped and this function will return an error-code.
+ @since(version = 0.3.0)
+ write-via-stream: func(data: stream) -> future>;
+}
+
+/// Terminal input.
+///
+/// In the future, this may include functions for disabling echoing,
+/// disabling input buffering so that keyboard events are sent through
+/// immediately, querying supported features, and so on.
+@since(version = 0.3.0)
+interface terminal-input {
+ /// The input side of a terminal.
+ @since(version = 0.3.0)
+ resource terminal-input;
+}
+
+/// Terminal output.
+///
+/// In the future, this may include functions for querying the terminal
+/// size, being notified of terminal size changes, querying supported
+/// features, and so on.
+@since(version = 0.3.0)
+interface terminal-output {
+ /// The output side of a terminal.
+ @since(version = 0.3.0)
+ resource terminal-output;
+}
+
+/// An interface providing an optional `terminal-input` for stdin as a
+/// link-time authority.
+@since(version = 0.3.0)
+interface terminal-stdin {
+ @since(version = 0.3.0)
+ use terminal-input.{terminal-input};
+
+ /// If stdin is connected to a terminal, return a `terminal-input` handle
+ /// allowing further interaction with it.
+ @since(version = 0.3.0)
+ get-terminal-stdin: func() -> option;
+}
+
+/// An interface providing an optional `terminal-output` for stdout as a
+/// link-time authority.
+@since(version = 0.3.0)
+interface terminal-stdout {
+ @since(version = 0.3.0)
+ use terminal-output.{terminal-output};
+
+ /// If stdout is connected to a terminal, return a `terminal-output` handle
+ /// allowing further interaction with it.
+ @since(version = 0.3.0)
+ get-terminal-stdout: func() -> option;
+}
+
+/// An interface providing an optional `terminal-output` for stderr as a
+/// link-time authority.
+@since(version = 0.3.0)
+interface terminal-stderr {
+ @since(version = 0.3.0)
+ use terminal-output.{terminal-output};
+
+ /// If stderr is connected to a terminal, return a `terminal-output` handle
+ /// allowing further interaction with it.
+ @since(version = 0.3.0)
+ get-terminal-stderr: func() -> option;
+}
+
+@since(version = 0.3.0)
+world imports {
+ @since(version = 0.3.0)
+ import environment;
+ @since(version = 0.3.0)
+ import exit;
+ @since(version = 0.3.0)
+ import types;
+ @since(version = 0.3.0)
+ import stdin;
+ @since(version = 0.3.0)
+ import stdout;
+ @since(version = 0.3.0)
+ import stderr;
+ @since(version = 0.3.0)
+ import terminal-input;
+ @since(version = 0.3.0)
+ import terminal-output;
+ @since(version = 0.3.0)
+ import terminal-stdin;
+ @since(version = 0.3.0)
+ import terminal-stdout;
+ @since(version = 0.3.0)
+ import terminal-stderr;
+ import wasi:clocks/types@0.3.0;
+ import wasi:clocks/monotonic-clock@0.3.0;
+ import wasi:clocks/system-clock@0.3.0;
+ @unstable(feature = clocks-timezone)
+ import wasi:clocks/timezone@0.3.0;
+ import wasi:filesystem/types@0.3.0;
+ import wasi:filesystem/preopens@0.3.0;
+ import wasi:sockets/types@0.3.0;
+ import wasi:sockets/ip-name-lookup@0.3.0;
+ import wasi:random/random@0.3.0;
+ import wasi:random/insecure@0.3.0;
+ import wasi:random/insecure-seed@0.3.0;
+}
+@since(version = 0.3.0)
+world command {
+ @since(version = 0.3.0)
+ import environment;
+ @since(version = 0.3.0)
+ import exit;
+ @since(version = 0.3.0)
+ import types;
+ @since(version = 0.3.0)
+ import stdin;
+ @since(version = 0.3.0)
+ import stdout;
+ @since(version = 0.3.0)
+ import stderr;
+ @since(version = 0.3.0)
+ import terminal-input;
+ @since(version = 0.3.0)
+ import terminal-output;
+ @since(version = 0.3.0)
+ import terminal-stdin;
+ @since(version = 0.3.0)
+ import terminal-stdout;
+ @since(version = 0.3.0)
+ import terminal-stderr;
+ import wasi:clocks/types@0.3.0;
+ import wasi:clocks/monotonic-clock@0.3.0;
+ import wasi:clocks/system-clock@0.3.0;
+ @unstable(feature = clocks-timezone)
+ import wasi:clocks/timezone@0.3.0;
+ import wasi:filesystem/types@0.3.0;
+ import wasi:filesystem/preopens@0.3.0;
+ import wasi:sockets/types@0.3.0;
+ import wasi:sockets/ip-name-lookup@0.3.0;
+ import wasi:random/random@0.3.0;
+ import wasi:random/insecure@0.3.0;
+ import wasi:random/insecure-seed@0.3.0;
+
+ @since(version = 0.3.0)
+ export run;
+}
diff --git a/wit/deps/wasi-clocks-0.2.8/package.wit b/wit/deps/wasi-clocks-0.2.8/package.wit
new file mode 100644
index 0000000..918bbea
--- /dev/null
+++ b/wit/deps/wasi-clocks-0.2.8/package.wit
@@ -0,0 +1,162 @@
+package wasi:clocks@0.2.8;
+
+/// WASI Monotonic Clock is a clock API intended to let users measure elapsed
+/// time.
+///
+/// It is intended to be portable at least between Unix-family platforms and
+/// Windows.
+///
+/// A monotonic clock is a clock which has an unspecified initial value, and
+/// successive reads of the clock will produce non-decreasing values.
+@since(version = 0.2.0)
+interface monotonic-clock {
+ @since(version = 0.2.0)
+ use wasi:io/poll@0.2.8.{pollable};
+
+ /// An instant in time, in nanoseconds. An instant is relative to an
+ /// unspecified initial value, and can only be compared to instances from
+ /// the same monotonic-clock.
+ @since(version = 0.2.0)
+ type instant = u64;
+
+ /// A duration of time, in nanoseconds.
+ @since(version = 0.2.0)
+ type duration = u64;
+
+ /// Read the current value of the clock.
+ ///
+ /// The clock is monotonic, therefore calling this function repeatedly will
+ /// produce a sequence of non-decreasing values.
+ ///
+ /// For completeness, this function traps if it's not possible to represent
+ /// the value of the clock in an `instant`. Consequently, implementations
+ /// should ensure that the starting time is low enough to avoid the
+ /// possibility of overflow in practice.
+ @since(version = 0.2.0)
+ now: func() -> instant;
+
+ /// Query the resolution of the clock. Returns the duration of time
+ /// corresponding to a clock tick.
+ @since(version = 0.2.0)
+ resolution: func() -> duration;
+
+ /// Create a `pollable` which will resolve once the specified instant
+ /// has occurred.
+ @since(version = 0.2.0)
+ subscribe-instant: func(when: instant) -> pollable;
+
+ /// Create a `pollable` that will resolve after the specified duration has
+ /// elapsed from the time this function is invoked.
+ @since(version = 0.2.0)
+ subscribe-duration: func(when: duration) -> pollable;
+}
+
+/// WASI Wall Clock is a clock API intended to let users query the current
+/// time. The name "wall" makes an analogy to a "clock on the wall", which
+/// is not necessarily monotonic as it may be reset.
+///
+/// It is intended to be portable at least between Unix-family platforms and
+/// Windows.
+///
+/// A wall clock is a clock which measures the date and time according to
+/// some external reference.
+///
+/// External references may be reset, so this clock is not necessarily
+/// monotonic, making it unsuitable for measuring elapsed time.
+///
+/// It is intended for reporting the current date and time for humans.
+@since(version = 0.2.0)
+interface wall-clock {
+ /// A time and date in seconds plus nanoseconds.
+ @since(version = 0.2.0)
+ record datetime {
+ seconds: u64,
+ nanoseconds: u32,
+ }
+
+ /// Read the current value of the clock.
+ ///
+ /// This clock is not monotonic, therefore calling this function repeatedly
+ /// will not necessarily produce a sequence of non-decreasing values.
+ ///
+ /// The returned timestamps represent the number of seconds since
+ /// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch],
+ /// also known as [Unix Time].
+ ///
+ /// The nanoseconds field of the output is always less than 1000000000.
+ ///
+ /// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
+ /// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
+ @since(version = 0.2.0)
+ now: func() -> datetime;
+
+ /// Query the resolution of the clock.
+ ///
+ /// The nanoseconds field of the output is always less than 1000000000.
+ @since(version = 0.2.0)
+ resolution: func() -> datetime;
+}
+
+@unstable(feature = clocks-timezone)
+interface timezone {
+ @unstable(feature = clocks-timezone)
+ use wall-clock.{datetime};
+
+ /// Information useful for displaying the timezone of a specific `datetime`.
+ ///
+ /// This information may vary within a single `timezone` to reflect daylight
+ /// saving time adjustments.
+ @unstable(feature = clocks-timezone)
+ record timezone-display {
+ /// The number of seconds difference between UTC time and the local
+ /// time of the timezone.
+ ///
+ /// The returned value will always be less than 86400 which is the
+ /// number of seconds in a day (24*60*60).
+ ///
+ /// In implementations that do not expose an actual time zone, this
+ /// should return 0.
+ utc-offset: s32,
+ /// The abbreviated name of the timezone to display to a user. The name
+ /// `UTC` indicates Coordinated Universal Time. Otherwise, this should
+ /// reference local standards for the name of the time zone.
+ ///
+ /// In implementations that do not expose an actual time zone, this
+ /// should be the string `UTC`.
+ ///
+ /// In time zones that do not have an applicable name, a formatted
+ /// representation of the UTC offset may be returned, such as `-04:00`.
+ name: string,
+ /// Whether daylight saving time is active.
+ ///
+ /// In implementations that do not expose an actual time zone, this
+ /// should return false.
+ in-daylight-saving-time: bool,
+ }
+
+ /// Return information needed to display the given `datetime`. This includes
+ /// the UTC offset, the time zone name, and a flag indicating whether
+ /// daylight saving time is active.
+ ///
+ /// If the timezone cannot be determined for the given `datetime`, return a
+ /// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
+ /// saving time.
+ @unstable(feature = clocks-timezone)
+ display: func(when: datetime) -> timezone-display;
+
+ /// The same as `display`, but only return the UTC offset.
+ @unstable(feature = clocks-timezone)
+ utc-offset: func(when: datetime) -> s32;
+}
+
+@since(version = 0.2.0)
+world imports {
+ @since(version = 0.2.0)
+ import wasi:io/poll@0.2.8;
+ @since(version = 0.2.0)
+ import monotonic-clock;
+ @since(version = 0.2.0)
+ import wall-clock;
+ @unstable(feature = clocks-timezone)
+ import timezone;
+}
diff --git a/wit/deps/wasi-clocks-0.3.0/package.wit b/wit/deps/wasi-clocks-0.3.0/package.wit
new file mode 100644
index 0000000..d8b8cfe
--- /dev/null
+++ b/wit/deps/wasi-clocks-0.3.0/package.wit
@@ -0,0 +1,161 @@
+package wasi:clocks@0.3.0;
+
+/// This interface common types used throughout wasi:clocks.
+@since(version = 0.3.0)
+interface types {
+ /// A duration of time, in nanoseconds.
+ @since(version = 0.3.0)
+ type duration = u64;
+}
+
+/// WASI Monotonic Clock is a clock API intended to let users measure elapsed
+/// time.
+///
+/// It is intended to be portable at least between Unix-family platforms and
+/// Windows.
+///
+/// A monotonic clock is a clock which has an unspecified initial value, and
+/// successive reads of the clock will produce non-decreasing values.
+@since(version = 0.3.0)
+interface monotonic-clock {
+ use types.{duration};
+
+ /// A mark on a monotonic clock is a number of nanoseconds since an
+ /// unspecified initial value, and can only be compared to instances from
+ /// the same monotonic-clock.
+ @since(version = 0.3.0)
+ type mark = u64;
+
+ /// Read the current value of the clock.
+ ///
+ /// The clock is monotonic, therefore calling this function repeatedly will
+ /// produce a sequence of non-decreasing values.
+ ///
+ /// For completeness, this function traps if it's not possible to represent
+ /// the value of the clock in a `mark`. Consequently, implementations
+ /// should ensure that the starting time is low enough to avoid the
+ /// possibility of overflow in practice.
+ @since(version = 0.3.0)
+ now: func() -> mark;
+
+ /// Query the resolution of the clock. Returns the duration of time
+ /// corresponding to a clock tick.
+ @since(version = 0.3.0)
+ get-resolution: func() -> duration;
+
+ /// Wait until the specified mark has occurred.
+ @since(version = 0.3.0)
+ wait-until: async func(when: mark);
+
+ /// Wait for the specified duration to elapse.
+ @since(version = 0.3.0)
+ wait-for: async func(how-long: duration);
+}
+
+/// WASI System Clock is a clock API intended to let users query the current
+/// time. The clock is not necessarily monotonic as it may be reset.
+///
+/// It is intended to be portable at least between Unix-family platforms and
+/// Windows.
+///
+/// External references may be reset, so this clock is not necessarily
+/// monotonic, making it unsuitable for measuring elapsed time.
+///
+/// It is intended for reporting the current date and time for humans.
+@since(version = 0.3.0)
+interface system-clock {
+ use types.{duration};
+
+ /// An "instant", or "exact time", is a point in time without regard to any
+ /// time zone: just the time since a particular external reference point,
+ /// often called an "epoch".
+ ///
+ /// Here, the epoch is 1970-01-01T00:00:00Z, also known as
+ /// [POSIX's Seconds Since the Epoch], also known as [Unix Time].
+ ///
+ /// Note that even if the seconds field is negative, incrementing
+ /// nanoseconds always represents moving forwards in time.
+ /// For example, `{ -1 seconds, 999999999 nanoseconds }` represents the
+ /// instant one nanosecond before the epoch.
+ /// For more on various different ways to represent time, see
+ /// https://tc39.es/proposal-temporal/docs/timezone.html
+ ///
+ /// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
+ /// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
+ @since(version = 0.3.0)
+ record instant {
+ seconds: s64,
+ nanoseconds: u32,
+ }
+
+ /// Read the current value of the clock.
+ ///
+ /// This clock is not monotonic, therefore calling this function repeatedly
+ /// will not necessarily produce a sequence of non-decreasing values.
+ ///
+ /// The nanoseconds field of the output is always less than 1000000000.
+ @since(version = 0.3.0)
+ now: func() -> instant;
+
+ /// Query the resolution of the clock. Returns the smallest duration of time
+ /// that the implementation permits distinguishing.
+ @since(version = 0.3.0)
+ get-resolution: func() -> duration;
+}
+
+@unstable(feature = clocks-timezone)
+interface timezone {
+ @unstable(feature = clocks-timezone)
+ use system-clock.{instant};
+
+ /// Return the IANA identifier of the currently configured timezone. This
+ /// should be an identifier from the IANA Time Zone Database.
+ ///
+ /// For displaying to a user, the identifier should be converted into a
+ /// localized name by means of an internationalization API.
+ ///
+ /// If the implementation does not expose an actual timezone, or is unable
+ /// to provide mappings from times to deltas between the configured timezone
+ /// and UTC, or determining the current timezone fails, or the timezone does
+ /// not have an IANA identifier, this returns nothing.
+ @unstable(feature = clocks-timezone)
+ iana-id: func() -> option;
+
+ /// The number of nanoseconds difference between UTC time and the local
+ /// time of the currently configured timezone, at the exact time of
+ /// `instant`.
+ ///
+ /// The magnitude of the returned value will always be less than
+ /// 86,400,000,000,000 which is the number of nanoseconds in a day
+ /// (24*60*60*1e9).
+ ///
+ /// If the implementation does not expose an actual timezone, or is unable
+ /// to provide mappings from times to deltas between the configured timezone
+ /// and UTC, or determining the current timezone fails, this returns
+ /// nothing.
+ @unstable(feature = clocks-timezone)
+ utc-offset: func(when: instant) -> option;
+
+ /// Returns a string that is suitable to assist humans in debugging whether
+ /// any timezone is available, and if so, which. This may be the same string
+ /// as `iana-id`, or a formatted representation of the UTC offset such as
+ /// `-04:00`, or something else.
+ ///
+ /// WARNING: The returned string should not be consumed mechanically! It may
+ /// change across platforms, hosts, or other implementation details. Parsing
+ /// this string is a major platform-compatibility hazard.
+ @unstable(feature = clocks-timezone)
+ to-debug-string: func() -> string;
+}
+
+@since(version = 0.3.0)
+world imports {
+ @since(version = 0.3.0)
+ import types;
+ @since(version = 0.3.0)
+ import monotonic-clock;
+ @since(version = 0.3.0)
+ import system-clock;
+ @unstable(feature = clocks-timezone)
+ import timezone;
+}
diff --git a/wit/deps/wasi-config-0.2.0-rc.1/package.wit b/wit/deps/wasi-config-0.2.0-rc.1/package.wit
new file mode 100644
index 0000000..d8950ee
--- /dev/null
+++ b/wit/deps/wasi-config-0.2.0-rc.1/package.wit
@@ -0,0 +1,33 @@
+package wasi:config@0.2.0-rc.1;
+
+interface store {
+ /// An error type that encapsulates the different errors that can occur fetching configuration values.
+ variant error {
+ /// This indicates an error from an "upstream" config source.
+ /// As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue buckets, etc),
+ /// the error message is a string.
+ upstream(string),
+ /// This indicates an error from an I/O operation.
+ /// As this could be almost _anything_ (such as a file read, network connection, etc),
+ /// the error message is a string.
+ /// Depending on how this ends up being consumed,
+ /// we may consider moving this to use the `wasi:io/error` type instead.
+ /// For simplicity right now in supporting multiple implementations, it is being left as a string.
+ io(string),
+ }
+
+ /// Gets a configuration value of type `string` associated with the `key`.
+ ///
+ /// The value is returned as an `option`. If the key is not found,
+ /// `Ok(none)` is returned. If an error occurs, an `Err(error)` is returned.
+ get: func(key: string) -> result, error>;
+
+ /// Gets a list of configuration key-value pairs of type `string`.
+ ///
+ /// If an error occurs, an `Err(error)` is returned.
+ get-all: func() -> result>, error>;
+}
+
+world imports {
+ import store;
+}
diff --git a/wit/deps/wasi-filesystem-0.2.8/package.wit b/wit/deps/wasi-filesystem-0.2.8/package.wit
new file mode 100644
index 0000000..d5b1869
--- /dev/null
+++ b/wit/deps/wasi-filesystem-0.2.8/package.wit
@@ -0,0 +1,587 @@
+package wasi:filesystem@0.2.8;
+
+/// WASI filesystem is a filesystem API primarily intended to let users run WASI
+/// programs that access their files on their existing filesystems, without
+/// significant overhead.
+///
+/// It is intended to be roughly portable between Unix-family platforms and
+/// Windows, though it does not hide many of the major differences.
+///
+/// Paths are passed as interface-type `string`s, meaning they must consist of
+/// a sequence of Unicode Scalar Values (USVs). Some filesystems may contain
+/// paths which are not accessible by this API.
+///
+/// The directory separator in WASI is always the forward-slash (`/`).
+///
+/// All paths in WASI are relative paths, and are interpreted relative to a
+/// `descriptor` referring to a base directory. If a `path` argument to any WASI
+/// function starts with `/`, or if any step of resolving a `path`, including
+/// `..` and symbolic link steps, reaches a directory outside of the base
+/// directory, or reaches a symlink to an absolute or rooted path in the
+/// underlying filesystem, the function fails with `error-code::not-permitted`.
+///
+/// For more information about WASI path resolution and sandboxing, see
+/// [WASI filesystem path resolution].
+///
+/// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md
+@since(version = 0.2.0)
+interface types {
+ @since(version = 0.2.0)
+ use wasi:io/streams@0.2.8.{input-stream, output-stream, error};
+ @since(version = 0.2.0)
+ use wasi:clocks/wall-clock@0.2.8.{datetime};
+
+ /// File size or length of a region within a file.
+ @since(version = 0.2.0)
+ type filesize = u64;
+
+ /// The type of a filesystem object referenced by a descriptor.
+ ///
+ /// Note: This was called `filetype` in earlier versions of WASI.
+ @since(version = 0.2.0)
+ enum descriptor-type {
+ /// The type of the descriptor or file is unknown or is different from
+ /// any of the other types specified.
+ unknown,
+ /// The descriptor refers to a block device inode.
+ block-device,
+ /// The descriptor refers to a character device inode.
+ character-device,
+ /// The descriptor refers to a directory inode.
+ directory,
+ /// The descriptor refers to a named pipe.
+ fifo,
+ /// The file refers to a symbolic link inode.
+ symbolic-link,
+ /// The descriptor refers to a regular file inode.
+ regular-file,
+ /// The descriptor refers to a socket.
+ socket,
+ }
+
+ /// Descriptor flags.
+ ///
+ /// Note: This was called `fdflags` in earlier versions of WASI.
+ @since(version = 0.2.0)
+ flags descriptor-flags {
+ /// Read mode: Data can be read.
+ read,
+ /// Write mode: Data can be written to.
+ write,
+ /// Request that writes be performed according to synchronized I/O file
+ /// integrity completion. The data stored in the file and the file's
+ /// metadata are synchronized. This is similar to `O_SYNC` in POSIX.
+ ///
+ /// The precise semantics of this operation have not yet been defined for
+ /// WASI. At this time, it should be interpreted as a request, and not a
+ /// requirement.
+ file-integrity-sync,
+ /// Request that writes be performed according to synchronized I/O data
+ /// integrity completion. Only the data stored in the file is
+ /// synchronized. This is similar to `O_DSYNC` in POSIX.
+ ///
+ /// The precise semantics of this operation have not yet been defined for
+ /// WASI. At this time, it should be interpreted as a request, and not a
+ /// requirement.
+ data-integrity-sync,
+ /// Requests that reads be performed at the same level of integrity
+ /// requested for writes. This is similar to `O_RSYNC` in POSIX.
+ ///
+ /// The precise semantics of this operation have not yet been defined for
+ /// WASI. At this time, it should be interpreted as a request, and not a
+ /// requirement.
+ requested-write-sync,
+ /// Mutating directories mode: Directory contents may be mutated.
+ ///
+ /// When this flag is unset on a descriptor, operations using the
+ /// descriptor which would create, rename, delete, modify the data or
+ /// metadata of filesystem objects, or obtain another handle which
+ /// would permit any of those, shall fail with `error-code::read-only` if
+ /// they would otherwise succeed.
+ ///
+ /// This may only be set on directories.
+ mutate-directory,
+ }
+
+ /// Flags determining the method of how paths are resolved.
+ @since(version = 0.2.0)
+ flags path-flags {
+ /// As long as the resolved path corresponds to a symbolic link, it is
+ /// expanded.
+ symlink-follow,
+ }
+
+ /// Open flags used by `open-at`.
+ @since(version = 0.2.0)
+ flags open-flags {
+ /// Create file if it does not exist, similar to `O_CREAT` in POSIX.
+ create,
+ /// Fail if not a directory, similar to `O_DIRECTORY` in POSIX.
+ directory,
+ /// Fail if file already exists, similar to `O_EXCL` in POSIX.
+ exclusive,
+ /// Truncate file to size 0, similar to `O_TRUNC` in POSIX.
+ truncate,
+ }
+
+ /// Number of hard links to an inode.
+ @since(version = 0.2.0)
+ type link-count = u64;
+
+ /// File attributes.
+ ///
+ /// Note: This was called `filestat` in earlier versions of WASI.
+ @since(version = 0.2.0)
+ record descriptor-stat {
+ /// File type.
+ %type: descriptor-type,
+ /// Number of hard links to the file.
+ link-count: link-count,
+ /// For regular files, the file size in bytes. For symbolic links, the
+ /// length in bytes of the pathname contained in the symbolic link.
+ size: filesize,
+ /// Last data access timestamp.
+ ///
+ /// If the `option` is none, the platform doesn't maintain an access
+ /// timestamp for this file.
+ data-access-timestamp: option,
+ /// Last data modification timestamp.
+ ///
+ /// If the `option` is none, the platform doesn't maintain a
+ /// modification timestamp for this file.
+ data-modification-timestamp: option,
+ /// Last file status-change timestamp.
+ ///
+ /// If the `option` is none, the platform doesn't maintain a
+ /// status-change timestamp for this file.
+ status-change-timestamp: option,
+ }
+
+ /// When setting a timestamp, this gives the value to set it to.
+ @since(version = 0.2.0)
+ variant new-timestamp {
+ /// Leave the timestamp set to its previous value.
+ no-change,
+ /// Set the timestamp to the current time of the system clock associated
+ /// with the filesystem.
+ now,
+ /// Set the timestamp to the given value.
+ timestamp(datetime),
+ }
+
+ /// A directory entry.
+ record directory-entry {
+ /// The type of the file referred to by this directory entry.
+ %type: descriptor-type,
+ /// The name of the object.
+ name: string,
+ }
+
+ /// Error codes returned by functions, similar to `errno` in POSIX.
+ /// Not all of these error codes are returned by the functions provided by this
+ /// API; some are used in higher-level library layers, and others are provided
+ /// merely for alignment with POSIX.
+ enum error-code {
+ /// Permission denied, similar to `EACCES` in POSIX.
+ access,
+ /// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX.
+ would-block,
+ /// Connection already in progress, similar to `EALREADY` in POSIX.
+ already,
+ /// Bad descriptor, similar to `EBADF` in POSIX.
+ bad-descriptor,
+ /// Device or resource busy, similar to `EBUSY` in POSIX.
+ busy,
+ /// Resource deadlock would occur, similar to `EDEADLK` in POSIX.
+ deadlock,
+ /// Storage quota exceeded, similar to `EDQUOT` in POSIX.
+ quota,
+ /// File exists, similar to `EEXIST` in POSIX.
+ exist,
+ /// File too large, similar to `EFBIG` in POSIX.
+ file-too-large,
+ /// Illegal byte sequence, similar to `EILSEQ` in POSIX.
+ illegal-byte-sequence,
+ /// Operation in progress, similar to `EINPROGRESS` in POSIX.
+ in-progress,
+ /// Interrupted function, similar to `EINTR` in POSIX.
+ interrupted,
+ /// Invalid argument, similar to `EINVAL` in POSIX.
+ invalid,
+ /// I/O error, similar to `EIO` in POSIX.
+ io,
+ /// Is a directory, similar to `EISDIR` in POSIX.
+ is-directory,
+ /// Too many levels of symbolic links, similar to `ELOOP` in POSIX.
+ loop,
+ /// Too many links, similar to `EMLINK` in POSIX.
+ too-many-links,
+ /// Message too large, similar to `EMSGSIZE` in POSIX.
+ message-size,
+ /// Filename too long, similar to `ENAMETOOLONG` in POSIX.
+ name-too-long,
+ /// No such device, similar to `ENODEV` in POSIX.
+ no-device,
+ /// No such file or directory, similar to `ENOENT` in POSIX.
+ no-entry,
+ /// No locks available, similar to `ENOLCK` in POSIX.
+ no-lock,
+ /// Not enough space, similar to `ENOMEM` in POSIX.
+ insufficient-memory,
+ /// No space left on device, similar to `ENOSPC` in POSIX.
+ insufficient-space,
+ /// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX.
+ not-directory,
+ /// Directory not empty, similar to `ENOTEMPTY` in POSIX.
+ not-empty,
+ /// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX.
+ not-recoverable,
+ /// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX.
+ unsupported,
+ /// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX.
+ no-tty,
+ /// No such device or address, similar to `ENXIO` in POSIX.
+ no-such-device,
+ /// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX.
+ overflow,
+ /// Operation not permitted, similar to `EPERM` in POSIX.
+ not-permitted,
+ /// Broken pipe, similar to `EPIPE` in POSIX.
+ pipe,
+ /// Read-only file system, similar to `EROFS` in POSIX.
+ read-only,
+ /// Invalid seek, similar to `ESPIPE` in POSIX.
+ invalid-seek,
+ /// Text file busy, similar to `ETXTBSY` in POSIX.
+ text-file-busy,
+ /// Cross-device link, similar to `EXDEV` in POSIX.
+ cross-device,
+ }
+
+ /// File or memory access pattern advisory information.
+ @since(version = 0.2.0)
+ enum advice {
+ /// The application has no advice to give on its behavior with respect
+ /// to the specified data.
+ normal,
+ /// The application expects to access the specified data sequentially
+ /// from lower offsets to higher offsets.
+ sequential,
+ /// The application expects to access the specified data in a random
+ /// order.
+ random,
+ /// The application expects to access the specified data in the near
+ /// future.
+ will-need,
+ /// The application expects that it will not access the specified data
+ /// in the near future.
+ dont-need,
+ /// The application expects to access the specified data once and then
+ /// not reuse it thereafter.
+ no-reuse,
+ }
+
+ /// A 128-bit hash value, split into parts because wasm doesn't have a
+ /// 128-bit integer type.
+ @since(version = 0.2.0)
+ record metadata-hash-value {
+ /// 64 bits of a 128-bit hash value.
+ lower: u64,
+ /// Another 64 bits of a 128-bit hash value.
+ upper: u64,
+ }
+
+ /// A descriptor is a reference to a filesystem object, which may be a file,
+ /// directory, named pipe, special file, or other object on which filesystem
+ /// calls may be made.
+ @since(version = 0.2.0)
+ resource descriptor {
+ /// Return a stream for reading from a file, if available.
+ ///
+ /// May fail with an error-code describing why the file cannot be read.
+ ///
+ /// Multiple read, write, and append streams may be active on the same open
+ /// file and they do not interfere with each other.
+ ///
+ /// Note: This allows using `read-stream`, which is similar to `read` in POSIX.
+ @since(version = 0.2.0)
+ read-via-stream: func(offset: filesize) -> result;
+ /// Return a stream for writing to a file, if available.
+ ///
+ /// May fail with an error-code describing why the file cannot be written.
+ ///
+ /// Note: This allows using `write-stream`, which is similar to `write` in
+ /// POSIX.
+ @since(version = 0.2.0)
+ write-via-stream: func(offset: filesize) -> result;
+ /// Return a stream for appending to a file, if available.
+ ///
+ /// May fail with an error-code describing why the file cannot be appended.
+ ///
+ /// Note: This allows using `write-stream`, which is similar to `write` with
+ /// `O_APPEND` in POSIX.
+ @since(version = 0.2.0)
+ append-via-stream: func() -> result;
+ /// Provide file advisory information on a descriptor.
+ ///
+ /// This is similar to `posix_fadvise` in POSIX.
+ @since(version = 0.2.0)
+ advise: func(offset: filesize, length: filesize, advice: advice) -> result<_, error-code>;
+ /// Synchronize the data of a file to disk.
+ ///
+ /// This function succeeds with no effect if the file descriptor is not
+ /// opened for writing.
+ ///
+ /// Note: This is similar to `fdatasync` in POSIX.
+ @since(version = 0.2.0)
+ sync-data: func() -> result<_, error-code>;
+ /// Get flags associated with a descriptor.
+ ///
+ /// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX.
+ ///
+ /// Note: This returns the value that was the `fs_flags` value returned
+ /// from `fdstat_get` in earlier versions of WASI.
+ @since(version = 0.2.0)
+ get-flags: func() -> result;
+ /// Get the dynamic type of a descriptor.
+ ///
+ /// Note: This returns the same value as the `type` field of the `fd-stat`
+ /// returned by `stat`, `stat-at` and similar.
+ ///
+ /// Note: This returns similar flags to the `st_mode & S_IFMT` value provided
+ /// by `fstat` in POSIX.
+ ///
+ /// Note: This returns the value that was the `fs_filetype` value returned
+ /// from `fdstat_get` in earlier versions of WASI.
+ @since(version = 0.2.0)
+ get-type: func() -> result;
+ /// Adjust the size of an open file. If this increases the file's size, the
+ /// extra bytes are filled with zeros.
+ ///
+ /// Note: This was called `fd_filestat_set_size` in earlier versions of WASI.
+ @since(version = 0.2.0)
+ set-size: func(size: filesize) -> result<_, error-code>;
+ /// Adjust the timestamps of an open file or directory.
+ ///
+ /// Note: This is similar to `futimens` in POSIX.
+ ///
+ /// Note: This was called `fd_filestat_set_times` in earlier versions of WASI.
+ @since(version = 0.2.0)
+ set-times: func(data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code>;
+ /// Read from a descriptor, without using and updating the descriptor's offset.
+ ///
+ /// This function returns a list of bytes containing the data that was
+ /// read, along with a bool which, when true, indicates that the end of the
+ /// file was reached. The returned list will contain up to `length` bytes; it
+ /// may return fewer than requested, if the end of the file is reached or
+ /// if the I/O operation is interrupted.
+ ///
+ /// In the future, this may change to return a `stream`.
+ ///
+ /// Note: This is similar to `pread` in POSIX.
+ @since(version = 0.2.0)
+ read: func(length: filesize, offset: filesize) -> result, bool>, error-code>;
+ /// Write to a descriptor, without using and updating the descriptor's offset.
+ ///
+ /// It is valid to write past the end of a file; the file is extended to the
+ /// extent of the write, with bytes between the previous end and the start of
+ /// the write set to zero.
+ ///
+ /// In the future, this may change to take a `stream`.
+ ///
+ /// Note: This is similar to `pwrite` in POSIX.
+ @since(version = 0.2.0)
+ write: func(buffer: list, offset: filesize) -> result;
+ /// Read directory entries from a directory.
+ ///
+ /// On filesystems where directories contain entries referring to themselves
+ /// and their parents, often named `.` and `..` respectively, these entries
+ /// are omitted.
+ ///
+ /// This always returns a new stream which starts at the beginning of the
+ /// directory. Multiple streams may be active on the same directory, and they
+ /// do not interfere with each other.
+ @since(version = 0.2.0)
+ read-directory: func() -> result;
+ /// Synchronize the data and metadata of a file to disk.
+ ///
+ /// This function succeeds with no effect if the file descriptor is not
+ /// opened for writing.
+ ///
+ /// Note: This is similar to `fsync` in POSIX.
+ @since(version = 0.2.0)
+ sync: func() -> result<_, error-code>;
+ /// Create a directory.
+ ///
+ /// Note: This is similar to `mkdirat` in POSIX.
+ @since(version = 0.2.0)
+ create-directory-at: func(path: string) -> result<_, error-code>;
+ /// Return the attributes of an open file or directory.
+ ///
+ /// Note: This is similar to `fstat` in POSIX, except that it does not return
+ /// device and inode information. For testing whether two descriptors refer to
+ /// the same underlying filesystem object, use `is-same-object`. To obtain
+ /// additional data that can be used do determine whether a file has been
+ /// modified, use `metadata-hash`.
+ ///
+ /// Note: This was called `fd_filestat_get` in earlier versions of WASI.
+ @since(version = 0.2.0)
+ stat: func() -> result;
+ /// Return the attributes of a file or directory.
+ ///
+ /// Note: This is similar to `fstatat` in POSIX, except that it does not
+ /// return device and inode information. See the `stat` description for a
+ /// discussion of alternatives.
+ ///
+ /// Note: This was called `path_filestat_get` in earlier versions of WASI.
+ @since(version = 0.2.0)
+ stat-at: func(path-flags: path-flags, path: string) -> result;
+ /// Adjust the timestamps of a file or directory.
+ ///
+ /// Note: This is similar to `utimensat` in POSIX.
+ ///
+ /// Note: This was called `path_filestat_set_times` in earlier versions of
+ /// WASI.
+ @since(version = 0.2.0)
+ set-times-at: func(path-flags: path-flags, path: string, data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code>;
+ /// Create a hard link.
+ ///
+ /// Fails with `error-code::no-entry` if the old path does not exist,
+ /// with `error-code::exist` if the new path already exists, and
+ /// `error-code::not-permitted` if the old path is not a file.
+ ///
+ /// Note: This is similar to `linkat` in POSIX.
+ @since(version = 0.2.0)
+ link-at: func(old-path-flags: path-flags, old-path: string, new-descriptor: borrow, new-path: string) -> result<_, error-code>;
+ /// Open a file or directory.
+ ///
+ /// If `flags` contains `descriptor-flags::mutate-directory`, and the base
+ /// descriptor doesn't have `descriptor-flags::mutate-directory` set,
+ /// `open-at` fails with `error-code::read-only`.
+ ///
+ /// If `flags` contains `write` or `mutate-directory`, or `open-flags`
+ /// contains `truncate` or `create`, and the base descriptor doesn't have
+ /// `descriptor-flags::mutate-directory` set, `open-at` fails with
+ /// `error-code::read-only`.
+ ///
+ /// Note: This is similar to `openat` in POSIX.
+ @since(version = 0.2.0)
+ open-at: func(path-flags: path-flags, path: string, open-flags: open-flags, %flags: descriptor-flags) -> result;
+ /// Read the contents of a symbolic link.
+ ///
+ /// If the contents contain an absolute or rooted path in the underlying
+ /// filesystem, this function fails with `error-code::not-permitted`.
+ ///
+ /// Note: This is similar to `readlinkat` in POSIX.
+ @since(version = 0.2.0)
+ readlink-at: func(path: string) -> result;
+ /// Remove a directory.
+ ///
+ /// Return `error-code::not-empty` if the directory is not empty.
+ ///
+ /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
+ @since(version = 0.2.0)
+ remove-directory-at: func(path: string) -> result<_, error-code>;
+ /// Rename a filesystem object.
+ ///
+ /// Note: This is similar to `renameat` in POSIX.
+ @since(version = 0.2.0)
+ rename-at: func(old-path: string, new-descriptor: borrow, new-path: string) -> result<_, error-code>;
+ /// Create a symbolic link (also known as a "symlink").
+ ///
+ /// If `old-path` starts with `/`, the function fails with
+ /// `error-code::not-permitted`.
+ ///
+ /// Note: This is similar to `symlinkat` in POSIX.
+ @since(version = 0.2.0)
+ symlink-at: func(old-path: string, new-path: string) -> result<_, error-code>;
+ /// Unlink a filesystem object that is not a directory.
+ ///
+ /// Return `error-code::is-directory` if the path refers to a directory.
+ /// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
+ @since(version = 0.2.0)
+ unlink-file-at: func(path: string) -> result<_, error-code>;
+ /// Test whether two descriptors refer to the same filesystem object.
+ ///
+ /// In POSIX, this corresponds to testing whether the two descriptors have the
+ /// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers.
+ /// wasi-filesystem does not expose device and inode numbers, so this function
+ /// may be used instead.
+ @since(version = 0.2.0)
+ is-same-object: func(other: borrow) -> bool;
+ /// Return a hash of the metadata associated with a filesystem object referred
+ /// to by a descriptor.
+ ///
+ /// This returns a hash of the last-modification timestamp and file size, and
+ /// may also include the inode number, device number, birth timestamp, and
+ /// other metadata fields that may change when the file is modified or
+ /// replaced. It may also include a secret value chosen by the
+ /// implementation and not otherwise exposed.
+ ///
+ /// Implementations are encouraged to provide the following properties:
+ ///
+ /// - If the file is not modified or replaced, the computed hash value should
+ /// usually not change.
+ /// - If the object is modified or replaced, the computed hash value should
+ /// usually change.
+ /// - The inputs to the hash should not be easily computable from the
+ /// computed hash.
+ ///
+ /// However, none of these is required.
+ @since(version = 0.2.0)
+ metadata-hash: func() -> result;
+ /// Return a hash of the metadata associated with a filesystem object referred
+ /// to by a directory descriptor and a relative path.
+ ///
+ /// This performs the same hash computation as `metadata-hash`.
+ @since(version = 0.2.0)
+ metadata-hash-at: func(path-flags: path-flags, path: string) -> result;
+ }
+
+ /// A stream of directory entries.
+ @since(version = 0.2.0)
+ resource directory-entry-stream {
+ /// Read a single directory entry from a `directory-entry-stream`.
+ @since(version = 0.2.0)
+ read-directory-entry: func() -> result, error-code>;
+ }
+
+ /// Attempts to extract a filesystem-related `error-code` from the stream
+ /// `error` provided.
+ ///
+ /// Stream operations which return `stream-error::last-operation-failed`
+ /// have a payload with more information about the operation that failed.
+ /// This payload can be passed through to this function to see if there's
+ /// filesystem-related information about the error to return.
+ ///
+ /// Note that this function is fallible because not all stream-related
+ /// errors are filesystem-related errors.
+ @since(version = 0.2.0)
+ filesystem-error-code: func(err: borrow) -> option;
+}
+
+@since(version = 0.2.0)
+interface preopens {
+ @since(version = 0.2.0)
+ use types.{descriptor};
+
+ /// Return the set of preopened directories, and their paths.
+ @since(version = 0.2.0)
+ get-directories: func() -> list>;
+}
+
+@since(version = 0.2.0)
+world imports {
+ @since(version = 0.2.0)
+ import wasi:io/error@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:io/poll@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:io/streams@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:clocks/wall-clock@0.2.8;
+ @since(version = 0.2.0)
+ import types;
+ @since(version = 0.2.0)
+ import preopens;
+}
diff --git a/wit/deps/wasi-filesystem-0.3.0/package.wit b/wit/deps/wasi-filesystem-0.3.0/package.wit
new file mode 100644
index 0000000..e4a778f
--- /dev/null
+++ b/wit/deps/wasi-filesystem-0.3.0/package.wit
@@ -0,0 +1,575 @@
+package wasi:filesystem@0.3.0;
+
+/// WASI filesystem is a filesystem API primarily intended to let users run WASI
+/// programs that access their files on their existing filesystems, without
+/// significant overhead.
+///
+/// Paths are passed as interface-type `string`s, meaning they must consist of
+/// a sequence of Unicode Scalar Values (USVs). Some filesystems may contain
+/// paths which are not accessible by this API.
+///
+/// The directory separator in WASI is always the forward-slash (`/`).
+///
+/// All paths in WASI are relative paths, and are interpreted relative to a
+/// `descriptor` referring to a base directory. If a `path` argument to any WASI
+/// function starts with `/`, or if any step of resolving a `path`, including
+/// `..` and symbolic link steps, reaches a directory outside of the base
+/// directory, or reaches a symlink to an absolute or rooted path in the
+/// underlying filesystem, the function fails with `error-code::not-permitted`.
+///
+/// For more information about WASI path resolution and sandboxing, see
+/// [WASI filesystem path resolution].
+///
+/// Though this package presents a portable interface modelled on POSIX, it
+/// prioritizes compatibility over portability: allowing users to access their
+/// files on their machine is more important than exposing a single semantics
+/// across all platforms. Notably, depending on the underlying operating system
+/// and file system:
+/// * Paths may be case-folded or not.
+/// * Deleting (unlinking) a file may fail if there are other file descriptors
+/// open.
+/// * Durability and atomicity of changes to underlying files when there are
+/// concurrent writers.
+///
+/// Users that need well-defined, portable semantics should use a key-value
+/// store or a database instead.
+///
+/// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md
+@since(version = 0.3.0)
+interface types {
+ @since(version = 0.3.0)
+ use wasi:clocks/system-clock@0.3.0.{instant};
+
+ /// File size or length of a region within a file.
+ @since(version = 0.3.0)
+ type filesize = u64;
+
+ /// The type of a filesystem object referenced by a descriptor.
+ ///
+ /// Note: This was called `filetype` in earlier versions of WASI.
+ @since(version = 0.3.0)
+ variant descriptor-type {
+ /// The descriptor refers to a block device inode.
+ block-device,
+ /// The descriptor refers to a character device inode.
+ character-device,
+ /// The descriptor refers to a directory inode.
+ directory,
+ /// The descriptor refers to a named pipe.
+ fifo,
+ /// The file refers to a symbolic link inode.
+ symbolic-link,
+ /// The descriptor refers to a regular file inode.
+ regular-file,
+ /// The descriptor refers to a socket.
+ socket,
+ /// The type of the descriptor or file is different from any of the
+ /// other types specified.
+ other(option),
+ }
+
+ /// Descriptor flags.
+ ///
+ /// Note: This was called `fdflags` in earlier versions of WASI.
+ @since(version = 0.3.0)
+ flags descriptor-flags {
+ /// Read mode: Data can be read.
+ read,
+ /// Write mode: Data can be written to.
+ write,
+ /// Request that writes be performed according to synchronized I/O file
+ /// integrity completion. The data stored in the file and the file's
+ /// metadata are synchronized. This is similar to `O_SYNC` in POSIX.
+ ///
+ /// The precise semantics of this operation have not yet been defined for
+ /// WASI. At this time, it should be interpreted as a request, and not a
+ /// requirement.
+ file-integrity-sync,
+ /// Request that writes be performed according to synchronized I/O data
+ /// integrity completion. Only the data stored in the file is
+ /// synchronized. This is similar to `O_DSYNC` in POSIX.
+ ///
+ /// The precise semantics of this operation have not yet been defined for
+ /// WASI. At this time, it should be interpreted as a request, and not a
+ /// requirement.
+ data-integrity-sync,
+ /// Requests that reads be performed at the same level of integrity
+ /// requested for writes. This is similar to `O_RSYNC` in POSIX.
+ ///
+ /// The precise semantics of this operation have not yet been defined for
+ /// WASI. At this time, it should be interpreted as a request, and not a
+ /// requirement.
+ requested-write-sync,
+ /// Mutating directories mode: Directory contents may be mutated.
+ ///
+ /// When this flag is unset on a descriptor, operations using the
+ /// descriptor which would create, rename, delete, modify the data or
+ /// metadata of filesystem objects, or obtain another handle which
+ /// would permit any of those, shall fail with `error-code::read-only` if
+ /// they would otherwise succeed.
+ ///
+ /// This may only be set on directories.
+ mutate-directory,
+ }
+
+ /// Flags determining the method of how paths are resolved.
+ @since(version = 0.3.0)
+ flags path-flags {
+ /// As long as the resolved path corresponds to a symbolic link, it is
+ /// expanded.
+ symlink-follow,
+ }
+
+ /// Open flags used by `open-at`.
+ @since(version = 0.3.0)
+ flags open-flags {
+ /// Create file if it does not exist, similar to `O_CREAT` in POSIX.
+ create,
+ /// Fail if not a directory, similar to `O_DIRECTORY` in POSIX.
+ directory,
+ /// Fail if file already exists, similar to `O_EXCL` in POSIX.
+ exclusive,
+ /// Truncate file to size 0, similar to `O_TRUNC` in POSIX.
+ truncate,
+ }
+
+ /// Number of hard links to an inode.
+ @since(version = 0.3.0)
+ type link-count = u64;
+
+ /// File attributes.
+ ///
+ /// Note: This was called `filestat` in earlier versions of WASI.
+ @since(version = 0.3.0)
+ record descriptor-stat {
+ /// File type.
+ %type: descriptor-type,
+ /// Number of hard links to the file.
+ link-count: link-count,
+ /// For regular files, the file size in bytes. For symbolic links, the
+ /// length in bytes of the pathname contained in the symbolic link.
+ size: filesize,
+ /// Last data access timestamp.
+ ///
+ /// If the `option` is none, the platform doesn't maintain an access
+ /// timestamp for this file.
+ data-access-timestamp: option,
+ /// Last data modification timestamp.
+ ///
+ /// If the `option` is none, the platform doesn't maintain a
+ /// modification timestamp for this file.
+ data-modification-timestamp: option,
+ /// Last file status-change timestamp.
+ ///
+ /// If the `option` is none, the platform doesn't maintain a
+ /// status-change timestamp for this file.
+ status-change-timestamp: option,
+ }
+
+ /// When setting a timestamp, this gives the value to set it to.
+ @since(version = 0.3.0)
+ variant new-timestamp {
+ /// Leave the timestamp set to its previous value.
+ no-change,
+ /// Set the timestamp to the current time of the system clock associated
+ /// with the filesystem.
+ now,
+ /// Set the timestamp to the given value.
+ timestamp(instant),
+ }
+
+ /// A directory entry.
+ @since(version = 0.3.0)
+ record directory-entry {
+ /// The type of the file referred to by this directory entry.
+ %type: descriptor-type,
+ /// The name of the object.
+ name: string,
+ }
+
+ /// Error codes returned by functions, similar to `errno` in POSIX.
+ /// Not all of these error codes are returned by the functions provided by this
+ /// API; some are used in higher-level library layers, and others are provided
+ /// merely for alignment with POSIX.
+ @since(version = 0.3.0)
+ variant error-code {
+ /// Permission denied, similar to `EACCES` in POSIX.
+ access,
+ /// Connection already in progress, similar to `EALREADY` in POSIX.
+ already,
+ /// Bad descriptor, similar to `EBADF` in POSIX.
+ bad-descriptor,
+ /// Device or resource busy, similar to `EBUSY` in POSIX.
+ busy,
+ /// Resource deadlock would occur, similar to `EDEADLK` in POSIX.
+ deadlock,
+ /// Storage quota exceeded, similar to `EDQUOT` in POSIX.
+ quota,
+ /// File exists, similar to `EEXIST` in POSIX.
+ exist,
+ /// File too large, similar to `EFBIG` in POSIX.
+ file-too-large,
+ /// Illegal byte sequence, similar to `EILSEQ` in POSIX.
+ illegal-byte-sequence,
+ /// Operation in progress, similar to `EINPROGRESS` in POSIX.
+ in-progress,
+ /// Interrupted function, similar to `EINTR` in POSIX.
+ interrupted,
+ /// Invalid argument, similar to `EINVAL` in POSIX.
+ invalid,
+ /// I/O error, similar to `EIO` in POSIX.
+ io,
+ /// Is a directory, similar to `EISDIR` in POSIX.
+ is-directory,
+ /// Too many levels of symbolic links, similar to `ELOOP` in POSIX.
+ loop,
+ /// Too many links, similar to `EMLINK` in POSIX.
+ too-many-links,
+ /// Message too large, similar to `EMSGSIZE` in POSIX.
+ message-size,
+ /// Filename too long, similar to `ENAMETOOLONG` in POSIX.
+ name-too-long,
+ /// No such device, similar to `ENODEV` in POSIX.
+ no-device,
+ /// No such file or directory, similar to `ENOENT` in POSIX.
+ no-entry,
+ /// No locks available, similar to `ENOLCK` in POSIX.
+ no-lock,
+ /// Not enough space, similar to `ENOMEM` in POSIX.
+ insufficient-memory,
+ /// No space left on device, similar to `ENOSPC` in POSIX.
+ insufficient-space,
+ /// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX.
+ not-directory,
+ /// Directory not empty, similar to `ENOTEMPTY` in POSIX.
+ not-empty,
+ /// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX.
+ not-recoverable,
+ /// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX.
+ unsupported,
+ /// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX.
+ no-tty,
+ /// No such device or address, similar to `ENXIO` in POSIX.
+ no-such-device,
+ /// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX.
+ overflow,
+ /// Operation not permitted, similar to `EPERM` in POSIX.
+ not-permitted,
+ /// Broken pipe, similar to `EPIPE` in POSIX.
+ pipe,
+ /// Read-only file system, similar to `EROFS` in POSIX.
+ read-only,
+ /// Invalid seek, similar to `ESPIPE` in POSIX.
+ invalid-seek,
+ /// Text file busy, similar to `ETXTBSY` in POSIX.
+ text-file-busy,
+ /// Cross-device link, similar to `EXDEV` in POSIX.
+ cross-device,
+ /// A catch-all for errors not captured by the existing variants.
+ /// Implementations can use this to extend the error type without
+ /// breaking existing code.
+ other(option),
+ }
+
+ /// File or memory access pattern advisory information.
+ @since(version = 0.3.0)
+ enum advice {
+ /// The application has no advice to give on its behavior with respect
+ /// to the specified data.
+ normal,
+ /// The application expects to access the specified data sequentially
+ /// from lower offsets to higher offsets.
+ sequential,
+ /// The application expects to access the specified data in a random
+ /// order.
+ random,
+ /// The application expects to access the specified data in the near
+ /// future.
+ will-need,
+ /// The application expects that it will not access the specified data
+ /// in the near future.
+ dont-need,
+ /// The application expects to access the specified data once and then
+ /// not reuse it thereafter.
+ no-reuse,
+ }
+
+ /// A 128-bit hash value, split into parts because wasm doesn't have a
+ /// 128-bit integer type.
+ @since(version = 0.3.0)
+ record metadata-hash-value {
+ /// 64 bits of a 128-bit hash value.
+ lower: u64,
+ /// Another 64 bits of a 128-bit hash value.
+ upper: u64,
+ }
+
+ /// A descriptor is a reference to a filesystem object, which may be a file,
+ /// directory, named pipe, special file, or other object on which filesystem
+ /// calls may be made.
+ @since(version = 0.3.0)
+ resource descriptor {
+ /// Return a stream for reading from a file.
+ ///
+ /// Multiple read, write, and append streams may be active on the same open
+ /// file and they do not interfere with each other.
+ ///
+ /// This function returns a `stream` which provides the data received from the
+ /// file, and a `future` providing additional error information in case an
+ /// error is encountered.
+ ///
+ /// If no error is encountered, `stream.read` on the `stream` will return
+ /// `read-status::closed` with no `error-context` and the future resolves to
+ /// the value `ok`. If an error is encountered, `stream.read` on the
+ /// `stream` returns `read-status::closed` with an `error-context` and the future
+ /// resolves to `err` with an `error-code`.
+ ///
+ /// Note: This is similar to `pread` in POSIX.
+ @since(version = 0.3.0)
+ read-via-stream: func(offset: filesize) -> tuple, future>>;
+ /// Return a stream for writing to a file, if available.
+ ///
+ /// May fail with an error-code describing why the file cannot be written.
+ ///
+ /// It is valid to write past the end of a file; the file is extended to the
+ /// extent of the write, with bytes between the previous end and the start of
+ /// the write set to zero.
+ ///
+ /// This function returns once either full contents of the stream are
+ /// written or an error is encountered.
+ ///
+ /// Note: This is similar to `pwrite` in POSIX.
+ @since(version = 0.3.0)
+ write-via-stream: func(data: stream, offset: filesize) -> future>;
+ /// Return a stream for appending to a file, if available.
+ ///
+ /// May fail with an error-code describing why the file cannot be appended.
+ ///
+ /// This function returns once either full contents of the stream are
+ /// written or an error is encountered.
+ ///
+ /// Note: This is similar to `write` with `O_APPEND` in POSIX.
+ @since(version = 0.3.0)
+ append-via-stream: func(data: stream) -> future>;
+ /// Provide file advisory information on a descriptor.
+ ///
+ /// This is similar to `posix_fadvise` in POSIX.
+ @since(version = 0.3.0)
+ advise: async func(offset: filesize, length: filesize, advice: advice) -> result<_, error-code>;
+ /// Synchronize the data of a file to disk.
+ ///
+ /// This function succeeds with no effect if the file descriptor is not
+ /// opened for writing.
+ ///
+ /// Note: This is similar to `fdatasync` in POSIX.
+ @since(version = 0.3.0)
+ sync-data: async func() -> result<_, error-code>;
+ /// Get flags associated with a descriptor.
+ ///
+ /// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX.
+ ///
+ /// Note: This returns the value that was the `fs_flags` value returned
+ /// from `fdstat_get` in earlier versions of WASI.
+ @since(version = 0.3.0)
+ get-flags: async func() -> result;
+ /// Get the dynamic type of a descriptor.
+ ///
+ /// Note: This returns the same value as the `type` field of the `fd-stat`
+ /// returned by `stat`, `stat-at` and similar.
+ ///
+ /// Note: This returns similar flags to the `st_mode & S_IFMT` value provided
+ /// by `fstat` in POSIX.
+ ///
+ /// Note: This returns the value that was the `fs_filetype` value returned
+ /// from `fdstat_get` in earlier versions of WASI.
+ @since(version = 0.3.0)
+ get-type: async func() -> result;
+ /// Adjust the size of an open file. If this increases the file's size, the
+ /// extra bytes are filled with zeros.
+ ///
+ /// Note: This was called `fd_filestat_set_size` in earlier versions of WASI.
+ @since(version = 0.3.0)
+ set-size: async func(size: filesize) -> result<_, error-code>;
+ /// Adjust the timestamps of an open file or directory.
+ ///
+ /// Note: This is similar to `futimens` in POSIX.
+ ///
+ /// Note: This was called `fd_filestat_set_times` in earlier versions of WASI.
+ @since(version = 0.3.0)
+ set-times: async func(data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code>;
+ /// Read directory entries from a directory.
+ ///
+ /// On filesystems where directories contain entries referring to themselves
+ /// and their parents, often named `.` and `..` respectively, these entries
+ /// are omitted.
+ ///
+ /// This always returns a new stream which starts at the beginning of the
+ /// directory. Multiple streams may be active on the same directory, and they
+ /// do not interfere with each other.
+ ///
+ /// This function returns a future, which will resolve to an error code if
+ /// reading full contents of the directory fails.
+ @since(version = 0.3.0)
+ read-directory: func() -> tuple, future>>;
+ /// Synchronize the data and metadata of a file to disk.
+ ///
+ /// This function succeeds with no effect if the file descriptor is not
+ /// opened for writing.
+ ///
+ /// Note: This is similar to `fsync` in POSIX.
+ @since(version = 0.3.0)
+ sync: async func() -> result<_, error-code>;
+ /// Create a directory.
+ ///
+ /// Note: This is similar to `mkdirat` in POSIX.
+ @since(version = 0.3.0)
+ create-directory-at: async func(path: string) -> result<_, error-code>;
+ /// Return the attributes of an open file or directory.
+ ///
+ /// Note: This is similar to `fstat` in POSIX, except that it does not return
+ /// device and inode information. For testing whether two descriptors refer to
+ /// the same underlying filesystem object, use `is-same-object`. To obtain
+ /// additional data that can be used do determine whether a file has been
+ /// modified, use `metadata-hash`.
+ ///
+ /// Note: This was called `fd_filestat_get` in earlier versions of WASI.
+ @since(version = 0.3.0)
+ stat: async func() -> result;
+ /// Return the attributes of a file or directory.
+ ///
+ /// Note: This is similar to `fstatat` in POSIX, except that it does not
+ /// return device and inode information. See the `stat` description for a
+ /// discussion of alternatives.
+ ///
+ /// Note: This was called `path_filestat_get` in earlier versions of WASI.
+ @since(version = 0.3.0)
+ stat-at: async func(path-flags: path-flags, path: string) -> result;
+ /// Adjust the timestamps of a file or directory.
+ ///
+ /// Note: This is similar to `utimensat` in POSIX.
+ ///
+ /// Note: This was called `path_filestat_set_times` in earlier versions of
+ /// WASI.
+ @since(version = 0.3.0)
+ set-times-at: async func(path-flags: path-flags, path: string, data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code>;
+ /// Create a hard link.
+ ///
+ /// Fails with `error-code::no-entry` if the old path does not exist,
+ /// with `error-code::exist` if the new path already exists, and
+ /// `error-code::not-permitted` if the old path is not a file.
+ ///
+ /// Note: This is similar to `linkat` in POSIX.
+ @since(version = 0.3.0)
+ link-at: async func(old-path-flags: path-flags, old-path: string, new-descriptor: borrow, new-path: string) -> result<_, error-code>;
+ /// Open a file or directory.
+ ///
+ /// If `flags` contains `descriptor-flags::mutate-directory`, and the base
+ /// descriptor doesn't have `descriptor-flags::mutate-directory` set,
+ /// `open-at` fails with `error-code::read-only`.
+ ///
+ /// If `flags` contains `write` or `mutate-directory`, or `open-flags`
+ /// contains `truncate` or `create`, and the base descriptor doesn't have
+ /// `descriptor-flags::mutate-directory` set, `open-at` fails with
+ /// `error-code::read-only`.
+ ///
+ /// Note: This is similar to `openat` in POSIX.
+ @since(version = 0.3.0)
+ open-at: async func(path-flags: path-flags, path: string, open-flags: open-flags, %flags: descriptor-flags) -> result;
+ /// Read the contents of a symbolic link.
+ ///
+ /// If the contents contain an absolute or rooted path in the underlying
+ /// filesystem, this function fails with `error-code::not-permitted`.
+ ///
+ /// Note: This is similar to `readlinkat` in POSIX.
+ @since(version = 0.3.0)
+ readlink-at: async func(path: string) -> result;
+ /// Remove a directory.
+ ///
+ /// Return `error-code::not-empty` if the directory is not empty.
+ ///
+ /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
+ @since(version = 0.3.0)
+ remove-directory-at: async func(path: string) -> result<_, error-code>;
+ /// Rename a filesystem object.
+ ///
+ /// Note: This is similar to `renameat` in POSIX.
+ @since(version = 0.3.0)
+ rename-at: async func(old-path: string, new-descriptor: borrow, new-path: string) -> result<_, error-code>;
+ /// Create a symbolic link (also known as a "symlink").
+ ///
+ /// If `old-path` starts with `/`, the function fails with
+ /// `error-code::not-permitted`.
+ ///
+ /// Note: This is similar to `symlinkat` in POSIX.
+ @since(version = 0.3.0)
+ symlink-at: async func(old-path: string, new-path: string) -> result<_, error-code>;
+ /// Unlink a filesystem object that is not a directory.
+ ///
+ /// This is similar to `unlinkat(fd, path, 0)` in POSIX.
+ ///
+ /// Error returns are as specified by POSIX.
+ ///
+ /// If the filesystem object is a directory, `error-code::access` or
+ /// `error-code::is-directory` may be returned instead of the
+ /// POSIX-specified `error-code::not-permitted`.
+ @since(version = 0.3.0)
+ unlink-file-at: async func(path: string) -> result<_, error-code>;
+ /// Test whether two descriptors refer to the same filesystem object.
+ ///
+ /// In POSIX, this corresponds to testing whether the two descriptors have the
+ /// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers.
+ /// wasi-filesystem does not expose device and inode numbers, so this function
+ /// may be used instead.
+ @since(version = 0.3.0)
+ is-same-object: async func(other: borrow) -> bool;
+ /// Return a hash of the metadata associated with a filesystem object referred
+ /// to by a descriptor.
+ ///
+ /// This returns a hash of the last-modification timestamp and file size, and
+ /// may also include the inode number, device number, birth timestamp, and
+ /// other metadata fields that may change when the file is modified or
+ /// replaced. It may also include a secret value chosen by the
+ /// implementation and not otherwise exposed.
+ ///
+ /// Implementations are encouraged to provide the following properties:
+ ///
+ /// - If the file is not modified or replaced, the computed hash value should
+ /// usually not change.
+ /// - If the object is modified or replaced, the computed hash value should
+ /// usually change.
+ /// - The inputs to the hash should not be easily computable from the
+ /// computed hash.
+ ///
+ /// However, none of these is required.
+ @since(version = 0.3.0)
+ metadata-hash: async func() -> result;
+ /// Return a hash of the metadata associated with a filesystem object referred
+ /// to by a directory descriptor and a relative path.
+ ///
+ /// This performs the same hash computation as `metadata-hash`.
+ @since(version = 0.3.0)
+ metadata-hash-at: async func(path-flags: path-flags, path: string) -> result;
+ }
+}
+
+@since(version = 0.3.0)
+interface preopens {
+ @since(version = 0.3.0)
+ use types.{descriptor};
+
+ /// Return the set of preopened directories, and their paths.
+ @since(version = 0.3.0)
+ get-directories: func() -> list>;
+}
+
+@since(version = 0.3.0)
+world imports {
+ @since(version = 0.3.0)
+ import wasi:clocks/types@0.3.0;
+ @since(version = 0.3.0)
+ import wasi:clocks/system-clock@0.3.0;
+ @since(version = 0.3.0)
+ import types;
+ @since(version = 0.3.0)
+ import preopens;
+}
diff --git a/wit/deps/wasi-http-0.2.8/package.wit b/wit/deps/wasi-http-0.2.8/package.wit
new file mode 100644
index 0000000..a644ead
--- /dev/null
+++ b/wit/deps/wasi-http-0.2.8/package.wit
@@ -0,0 +1,733 @@
+package wasi:http@0.2.8;
+
+/// This interface defines all of the types and methods for implementing
+/// HTTP Requests and Responses, both incoming and outgoing, as well as
+/// their headers, trailers, and bodies.
+@since(version = 0.2.0)
+interface types {
+ @since(version = 0.2.0)
+ use wasi:clocks/monotonic-clock@0.2.8.{duration};
+ @since(version = 0.2.0)
+ use wasi:io/streams@0.2.8.{input-stream, output-stream};
+ @since(version = 0.2.0)
+ use wasi:io/error@0.2.8.{error as io-error};
+ @since(version = 0.2.0)
+ use wasi:io/poll@0.2.8.{pollable};
+
+ /// This type corresponds to HTTP standard Methods.
+ @since(version = 0.2.0)
+ variant method {
+ get,
+ head,
+ post,
+ put,
+ delete,
+ connect,
+ options,
+ trace,
+ patch,
+ other(string),
+ }
+
+ /// This type corresponds to HTTP standard Related Schemes.
+ @since(version = 0.2.0)
+ variant scheme {
+ HTTP,
+ HTTPS,
+ other(string),
+ }
+
+ /// Defines the case payload type for `DNS-error` above:
+ @since(version = 0.2.0)
+ record DNS-error-payload {
+ rcode: option,
+ info-code: option,
+ }
+
+ /// Defines the case payload type for `TLS-alert-received` above:
+ @since(version = 0.2.0)
+ record TLS-alert-received-payload {
+ alert-id: option,
+ alert-message: option,
+ }
+
+ /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
+ @since(version = 0.2.0)
+ record field-size-payload {
+ field-name: option,
+ field-size: option,
+ }
+
+ /// These cases are inspired by the IANA HTTP Proxy Error Types:
+ ///
+ @since(version = 0.2.0)
+ variant error-code {
+ DNS-timeout,
+ DNS-error(DNS-error-payload),
+ destination-not-found,
+ destination-unavailable,
+ destination-IP-prohibited,
+ destination-IP-unroutable,
+ connection-refused,
+ connection-terminated,
+ connection-timeout,
+ connection-read-timeout,
+ connection-write-timeout,
+ connection-limit-reached,
+ TLS-protocol-error,
+ TLS-certificate-error,
+ TLS-alert-received(TLS-alert-received-payload),
+ HTTP-request-denied,
+ HTTP-request-length-required,
+ HTTP-request-body-size(option),
+ HTTP-request-method-invalid,
+ HTTP-request-URI-invalid,
+ HTTP-request-URI-too-long,
+ HTTP-request-header-section-size(option),
+ HTTP-request-header-size(option),
+ HTTP-request-trailer-section-size(option),
+ HTTP-request-trailer-size(field-size-payload),
+ HTTP-response-incomplete,
+ HTTP-response-header-section-size(option),
+ HTTP-response-header-size(field-size-payload),
+ HTTP-response-body-size(option),
+ HTTP-response-trailer-section-size(option),
+ HTTP-response-trailer-size(field-size-payload),
+ HTTP-response-transfer-coding(option),
+ HTTP-response-content-coding(option),
+ HTTP-response-timeout,
+ HTTP-upgrade-failed,
+ HTTP-protocol-error,
+ loop-detected,
+ configuration-error,
+ /// This is a catch-all error for anything that doesn't fit cleanly into a
+ /// more specific case. It also includes an optional string for an
+ /// unstructured description of the error. Users should not depend on the
+ /// string for diagnosing errors, as it's not required to be consistent
+ /// between implementations.
+ internal-error(option),
+ }
+
+ /// This type enumerates the different kinds of errors that may occur when
+ /// setting or appending to a `fields` resource.
+ @since(version = 0.2.0)
+ variant header-error {
+ /// This error indicates that a `field-name` or `field-value` was
+ /// syntactically invalid when used with an operation that sets headers in a
+ /// `fields`.
+ invalid-syntax,
+ /// This error indicates that a forbidden `field-name` was used when trying
+ /// to set a header in a `fields`.
+ forbidden,
+ /// This error indicates that the operation on the `fields` was not
+ /// permitted because the fields are immutable.
+ immutable,
+ }
+
+ /// Field keys are always strings.
+ ///
+ /// Field keys should always be treated as case insensitive by the `fields`
+ /// resource for the purposes of equality checking.
+ ///
+ /// # Deprecation
+ ///
+ /// This type has been deprecated in favor of the `field-name` type.
+ @since(version = 0.2.0)
+ @deprecated(version = 0.2.2)
+ type field-key = string;
+
+ /// Field names are always strings.
+ ///
+ /// Field names should always be treated as case insensitive by the `fields`
+ /// resource for the purposes of equality checking.
+ @since(version = 0.2.1)
+ type field-name = field-key;
+
+ /// Field values should always be ASCII strings. However, in
+ /// reality, HTTP implementations often have to interpret malformed values,
+ /// so they are provided as a list of bytes.
+ @since(version = 0.2.0)
+ type field-value = list;
+
+ /// This following block defines the `fields` resource which corresponds to
+ /// HTTP standard Fields. Fields are a common representation used for both
+ /// Headers and Trailers.
+ ///
+ /// A `fields` may be mutable or immutable. A `fields` created using the
+ /// constructor, `from-list`, or `clone` will be mutable, but a `fields`
+ /// resource given by other means (including, but not limited to,
+ /// `incoming-request.headers`, `outgoing-request.headers`) might be
+ /// immutable. In an immutable fields, the `set`, `append`, and `delete`
+ /// operations will fail with `header-error.immutable`.
+ @since(version = 0.2.0)
+ resource fields {
+ /// Construct an empty HTTP Fields.
+ ///
+ /// The resulting `fields` is mutable.
+ @since(version = 0.2.0)
+ constructor();
+ /// Construct an HTTP Fields.
+ ///
+ /// The resulting `fields` is mutable.
+ ///
+ /// The list represents each name-value pair in the Fields. Names
+ /// which have multiple values are represented by multiple entries in this
+ /// list with the same name.
+ ///
+ /// The tuple is a pair of the field name, represented as a string, and
+ /// Value, represented as a list of bytes.
+ ///
+ /// An error result will be returned if any `field-name` or `field-value` is
+ /// syntactically invalid, or if a field is forbidden.
+ @since(version = 0.2.0)
+ from-list: static func(entries: list>) -> result;
+ /// Get all of the values corresponding to a name. If the name is not present
+ /// in this `fields` or is syntactically invalid, an empty list is returned.
+ /// However, if the name is present but empty, this is represented by a list
+ /// with one or more empty field-values present.
+ @since(version = 0.2.0)
+ get: func(name: field-name) -> list;
+ /// Returns `true` when the name is present in this `fields`. If the name is
+ /// syntactically invalid, `false` is returned.
+ @since(version = 0.2.0)
+ has: func(name: field-name) -> bool;
+ /// Set all of the values for a name. Clears any existing values for that
+ /// name, if they have been set.
+ ///
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
+ ///
+ /// Fails with `header-error.invalid-syntax` if the `field-name` or any of
+ /// the `field-value`s are syntactically invalid.
+ @since(version = 0.2.0)
+ set: func(name: field-name, value: list) -> result<_, header-error>;
+ /// Delete all values for a name. Does nothing if no values for the name
+ /// exist.
+ ///
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
+ ///
+ /// Fails with `header-error.invalid-syntax` if the `field-name` is
+ /// syntactically invalid.
+ @since(version = 0.2.0)
+ delete: func(name: field-name) -> result<_, header-error>;
+ /// Append a value for a name. Does not change or delete any existing
+ /// values for that name.
+ ///
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
+ ///
+ /// Fails with `header-error.invalid-syntax` if the `field-name` or
+ /// `field-value` are syntactically invalid.
+ @since(version = 0.2.0)
+ append: func(name: field-name, value: field-value) -> result<_, header-error>;
+ /// Retrieve the full set of names and values in the Fields. Like the
+ /// constructor, the list represents each name-value pair.
+ ///
+ /// The outer list represents each name-value pair in the Fields. Names
+ /// which have multiple values are represented by multiple entries in this
+ /// list with the same name.
+ ///
+ /// The names and values are always returned in the original casing and in
+ /// the order in which they will be serialized for transport.
+ @since(version = 0.2.0)
+ entries: func() -> list>;
+ /// Make a deep copy of the Fields. Equivalent in behavior to calling the
+ /// `fields` constructor on the return value of `entries`. The resulting
+ /// `fields` is mutable.
+ @since(version = 0.2.0)
+ clone: func() -> fields;
+ }
+
+ /// Headers is an alias for Fields.
+ @since(version = 0.2.0)
+ type headers = fields;
+
+ /// Trailers is an alias for Fields.
+ @since(version = 0.2.0)
+ type trailers = fields;
+
+ /// Represents an incoming HTTP Request.
+ @since(version = 0.2.0)
+ resource incoming-request {
+ /// Returns the method of the incoming request.
+ @since(version = 0.2.0)
+ method: func() -> method;
+ /// Returns the path with query parameters from the request, as a string.
+ @since(version = 0.2.0)
+ path-with-query: func() -> option;
+ /// Returns the protocol scheme from the request.
+ @since(version = 0.2.0)
+ scheme: func() -> option;
+ /// Returns the authority of the Request's target URI, if present.
+ @since(version = 0.2.0)
+ authority: func() -> option;
+ /// Get the `headers` associated with the request.
+ ///
+ /// The returned `headers` resource is immutable: `set`, `append`, and
+ /// `delete` operations will fail with `header-error.immutable`.
+ ///
+ /// The `headers` returned are a child resource: it must be dropped before
+ /// the parent `incoming-request` is dropped. Dropping this
+ /// `incoming-request` before all children are dropped will trap.
+ @since(version = 0.2.0)
+ headers: func() -> headers;
+ /// Gives the `incoming-body` associated with this request. Will only
+ /// return success at most once, and subsequent calls will return error.
+ @since(version = 0.2.0)
+ consume: func() -> result;
+ }
+
+ /// Represents an outgoing HTTP Request.
+ @since(version = 0.2.0)
+ resource outgoing-request {
+ /// Construct a new `outgoing-request` with a default `method` of `GET`, and
+ /// `none` values for `path-with-query`, `scheme`, and `authority`.
+ ///
+ /// * `headers` is the HTTP Headers for the Request.
+ ///
+ /// It is possible to construct, or manipulate with the accessor functions
+ /// below, an `outgoing-request` with an invalid combination of `scheme`
+ /// and `authority`, or `headers` which are not permitted to be sent.
+ /// It is the obligation of the `outgoing-handler.handle` implementation
+ /// to reject invalid constructions of `outgoing-request`.
+ @since(version = 0.2.0)
+ constructor(headers: headers);
+ /// Returns the resource corresponding to the outgoing Body for this
+ /// Request.
+ ///
+ /// Returns success on the first call: the `outgoing-body` resource for
+ /// this `outgoing-request` can be retrieved at most once. Subsequent
+ /// calls will return error.
+ @since(version = 0.2.0)
+ body: func() -> result;
+ /// Get the Method for the Request.
+ @since(version = 0.2.0)
+ method: func() -> method;
+ /// Set the Method for the Request. Fails if the string present in a
+ /// `method.other` argument is not a syntactically valid method.
+ @since(version = 0.2.0)
+ set-method: func(method: method) -> result;
+ /// Get the combination of the HTTP Path and Query for the Request.
+ /// When `none`, this represents an empty Path and empty Query.
+ @since(version = 0.2.0)
+ path-with-query: func() -> option;
+ /// Set the combination of the HTTP Path and Query for the Request.
+ /// When `none`, this represents an empty Path and empty Query. Fails is the
+ /// string given is not a syntactically valid path and query uri component.
+ @since(version = 0.2.0)
+ set-path-with-query: func(path-with-query: option) -> result;
+ /// Get the HTTP Related Scheme for the Request. When `none`, the
+ /// implementation may choose an appropriate default scheme.
+ @since(version = 0.2.0)
+ scheme: func() -> option;
+ /// Set the HTTP Related Scheme for the Request. When `none`, the
+ /// implementation may choose an appropriate default scheme. Fails if the
+ /// string given is not a syntactically valid uri scheme.
+ @since(version = 0.2.0)
+ set-scheme: func(scheme: option) -> result;
+ /// Get the authority of the Request's target URI. A value of `none` may be used
+ /// with Related Schemes which do not require an authority. The HTTP and
+ /// HTTPS schemes always require an authority.
+ @since(version = 0.2.0)
+ authority: func() -> option;
+ /// Set the authority of the Request's target URI. A value of `none` may be used
+ /// with Related Schemes which do not require an authority. The HTTP and
+ /// HTTPS schemes always require an authority. Fails if the string given is
+ /// not a syntactically valid URI authority.
+ @since(version = 0.2.0)
+ set-authority: func(authority: option) -> result;
+ /// Get the headers associated with the Request.
+ ///
+ /// The returned `headers` resource is immutable: `set`, `append`, and
+ /// `delete` operations will fail with `header-error.immutable`.
+ ///
+ /// This headers resource is a child: it must be dropped before the parent
+ /// `outgoing-request` is dropped, or its ownership is transferred to
+ /// another component by e.g. `outgoing-handler.handle`.
+ @since(version = 0.2.0)
+ headers: func() -> headers;
+ }
+
+ /// Parameters for making an HTTP Request. Each of these parameters is
+ /// currently an optional timeout applicable to the transport layer of the
+ /// HTTP protocol.
+ ///
+ /// These timeouts are separate from any the user may use to bound a
+ /// blocking call to `wasi:io/poll.poll`.
+ @since(version = 0.2.0)
+ resource request-options {
+ /// Construct a default `request-options` value.
+ @since(version = 0.2.0)
+ constructor();
+ /// The timeout for the initial connect to the HTTP Server.
+ @since(version = 0.2.0)
+ connect-timeout: func() -> option;
+ /// Set the timeout for the initial connect to the HTTP Server. An error
+ /// return value indicates that this timeout is not supported.
+ @since(version = 0.2.0)
+ set-connect-timeout: func(duration: option) -> result;
+ /// The timeout for receiving the first byte of the Response body.
+ @since(version = 0.2.0)
+ first-byte-timeout: func() -> option;
+ /// Set the timeout for receiving the first byte of the Response body. An
+ /// error return value indicates that this timeout is not supported.
+ @since(version = 0.2.0)
+ set-first-byte-timeout: func(duration: option) -> result;
+ /// The timeout for receiving subsequent chunks of bytes in the Response
+ /// body stream.
+ @since(version = 0.2.0)
+ between-bytes-timeout: func() -> option;
+ /// Set the timeout for receiving subsequent chunks of bytes in the Response
+ /// body stream. An error return value indicates that this timeout is not
+ /// supported.
+ @since(version = 0.2.0)
+ set-between-bytes-timeout: func(duration: option) -> result;
+ }
+
+ /// Represents the ability to send an HTTP Response.
+ ///
+ /// This resource is used by the `wasi:http/incoming-handler` interface to
+ /// allow a Response to be sent corresponding to the Request provided as the
+ /// other argument to `incoming-handler.handle`.
+ @since(version = 0.2.0)
+ resource response-outparam {
+ /// Send an HTTP 1xx response.
+ ///
+ /// Unlike `response-outparam.set`, this does not consume the
+ /// `response-outparam`, allowing the guest to send an arbitrary number of
+ /// informational responses before sending the final response using
+ /// `response-outparam.set`.
+ ///
+ /// This will return an `HTTP-protocol-error` if `status` is not in the
+ /// range [100-199], or an `internal-error` if the implementation does not
+ /// support informational responses.
+ @unstable(feature = informational-outbound-responses)
+ send-informational: func(status: u16, headers: headers) -> result<_, error-code>;
+ /// Set the value of the `response-outparam` to either send a response,
+ /// or indicate an error.
+ ///
+ /// This method consumes the `response-outparam` to ensure that it is
+ /// called at most once. If it is never called, the implementation
+ /// will respond with an error.
+ ///
+ /// The user may provide an `error` to `response` to allow the
+ /// implementation determine how to respond with an HTTP error response.
+ @since(version = 0.2.0)
+ set: static func(param: response-outparam, response: result);
+ }
+
+ /// This type corresponds to the HTTP standard Status Code.
+ @since(version = 0.2.0)
+ type status-code = u16;
+
+ /// Represents an incoming HTTP Response.
+ @since(version = 0.2.0)
+ resource incoming-response {
+ /// Returns the status code from the incoming response.
+ @since(version = 0.2.0)
+ status: func() -> status-code;
+ /// Returns the headers from the incoming response.
+ ///
+ /// The returned `headers` resource is immutable: `set`, `append`, and
+ /// `delete` operations will fail with `header-error.immutable`.
+ ///
+ /// This headers resource is a child: it must be dropped before the parent
+ /// `incoming-response` is dropped.
+ @since(version = 0.2.0)
+ headers: func() -> headers;
+ /// Returns the incoming body. May be called at most once. Returns error
+ /// if called additional times.
+ @since(version = 0.2.0)
+ consume: func() -> result;
+ }
+
+ /// Represents an incoming HTTP Request or Response's Body.
+ ///
+ /// A body has both its contents - a stream of bytes - and a (possibly
+ /// empty) set of trailers, indicating that the full contents of the
+ /// body have been received. This resource represents the contents as
+ /// an `input-stream` and the delivery of trailers as a `future-trailers`,
+ /// and ensures that the user of this interface may only be consuming either
+ /// the body contents or waiting on trailers at any given time.
+ @since(version = 0.2.0)
+ resource incoming-body {
+ /// Returns the contents of the body, as a stream of bytes.
+ ///
+ /// Returns success on first call: the stream representing the contents
+ /// can be retrieved at most once. Subsequent calls will return error.
+ ///
+ /// The returned `input-stream` resource is a child: it must be dropped
+ /// before the parent `incoming-body` is dropped, or consumed by
+ /// `incoming-body.finish`.
+ ///
+ /// This invariant ensures that the implementation can determine whether
+ /// the user is consuming the contents of the body, waiting on the
+ /// `future-trailers` to be ready, or neither. This allows for network
+ /// backpressure is to be applied when the user is consuming the body,
+ /// and for that backpressure to not inhibit delivery of the trailers if
+ /// the user does not read the entire body.
+ @since(version = 0.2.0)
+ %stream: func() -> result;
+ /// Takes ownership of `incoming-body`, and returns a `future-trailers`.
+ /// This function will trap if the `input-stream` child is still alive.
+ @since(version = 0.2.0)
+ finish: static func(this: incoming-body) -> future-trailers;
+ }
+
+ /// Represents a future which may eventually return trailers, or an error.
+ ///
+ /// In the case that the incoming HTTP Request or Response did not have any
+ /// trailers, this future will resolve to the empty set of trailers once the
+ /// complete Request or Response body has been received.
+ @since(version = 0.2.0)
+ resource future-trailers {
+ /// Returns a pollable which becomes ready when either the trailers have
+ /// been received, or an error has occurred. When this pollable is ready,
+ /// the `get` method will return `some`.
+ @since(version = 0.2.0)
+ subscribe: func() -> pollable;
+ /// Returns the contents of the trailers, or an error which occurred,
+ /// once the future is ready.
+ ///
+ /// The outer `option` represents future readiness. Users can wait on this
+ /// `option` to become `some` using the `subscribe` method.
+ ///
+ /// The outer `result` is used to retrieve the trailers or error at most
+ /// once. It will be success on the first call in which the outer option
+ /// is `some`, and error on subsequent calls.
+ ///
+ /// The inner `result` represents that either the HTTP Request or Response
+ /// body, as well as any trailers, were received successfully, or that an
+ /// error occurred receiving them. The optional `trailers` indicates whether
+ /// or not trailers were present in the body.
+ ///
+ /// When some `trailers` are returned by this method, the `trailers`
+ /// resource is immutable, and a child. Use of the `set`, `append`, or
+ /// `delete` methods will return an error, and the resource must be
+ /// dropped before the parent `future-trailers` is dropped.
+ @since(version = 0.2.0)
+ get: func() -> option, error-code>>>;
+ }
+
+ /// Represents an outgoing HTTP Response.
+ @since(version = 0.2.0)
+ resource outgoing-response {
+ /// Construct an `outgoing-response`, with a default `status-code` of `200`.
+ /// If a different `status-code` is needed, it must be set via the
+ /// `set-status-code` method.
+ ///
+ /// * `headers` is the HTTP Headers for the Response.
+ @since(version = 0.2.0)
+ constructor(headers: headers);
+ /// Get the HTTP Status Code for the Response.
+ @since(version = 0.2.0)
+ status-code: func() -> status-code;
+ /// Set the HTTP Status Code for the Response. Fails if the status-code
+ /// given is not a valid http status code.
+ @since(version = 0.2.0)
+ set-status-code: func(status-code: status-code) -> result;
+ /// Get the headers associated with the Request.
+ ///
+ /// The returned `headers` resource is immutable: `set`, `append`, and
+ /// `delete` operations will fail with `header-error.immutable`.
+ ///
+ /// This headers resource is a child: it must be dropped before the parent
+ /// `outgoing-request` is dropped, or its ownership is transferred to
+ /// another component by e.g. `outgoing-handler.handle`.
+ @since(version = 0.2.0)
+ headers: func() -> headers;
+ /// Returns the resource corresponding to the outgoing Body for this Response.
+ ///
+ /// Returns success on the first call: the `outgoing-body` resource for
+ /// this `outgoing-response` can be retrieved at most once. Subsequent
+ /// calls will return error.
+ @since(version = 0.2.0)
+ body: func() -> result;
+ }
+
+ /// Represents an outgoing HTTP Request or Response's Body.
+ ///
+ /// A body has both its contents - a stream of bytes - and a (possibly
+ /// empty) set of trailers, inducating the full contents of the body
+ /// have been sent. This resource represents the contents as an
+ /// `output-stream` child resource, and the completion of the body (with
+ /// optional trailers) with a static function that consumes the
+ /// `outgoing-body` resource, and ensures that the user of this interface
+ /// may not write to the body contents after the body has been finished.
+ ///
+ /// If the user code drops this resource, as opposed to calling the static
+ /// method `finish`, the implementation should treat the body as incomplete,
+ /// and that an error has occurred. The implementation should propagate this
+ /// error to the HTTP protocol by whatever means it has available,
+ /// including: corrupting the body on the wire, aborting the associated
+ /// Request, or sending a late status code for the Response.
+ @since(version = 0.2.0)
+ resource outgoing-body {
+ /// Returns a stream for writing the body contents.
+ ///
+ /// The returned `output-stream` is a child resource: it must be dropped
+ /// before the parent `outgoing-body` resource is dropped (or finished),
+ /// otherwise the `outgoing-body` drop or `finish` will trap.
+ ///
+ /// Returns success on the first call: the `output-stream` resource for
+ /// this `outgoing-body` may be retrieved at most once. Subsequent calls
+ /// will return error.
+ @since(version = 0.2.0)
+ write: func() -> result;
+ /// Finalize an outgoing body, optionally providing trailers. This must be
+ /// called to signal that the response is complete. If the `outgoing-body`
+ /// is dropped without calling `outgoing-body.finalize`, the implementation
+ /// should treat the body as corrupted.
+ ///
+ /// Fails if the body's `outgoing-request` or `outgoing-response` was
+ /// constructed with a Content-Length header, and the contents written
+ /// to the body (via `write`) does not match the value given in the
+ /// Content-Length.
+ @since(version = 0.2.0)
+ finish: static func(this: outgoing-body, trailers: option) -> result<_, error-code>;
+ }
+
+ /// Represents a future which may eventually return an incoming HTTP
+ /// Response, or an error.
+ ///
+ /// This resource is returned by the `wasi:http/outgoing-handler` interface to
+ /// provide the HTTP Response corresponding to the sent Request.
+ @since(version = 0.2.0)
+ resource future-incoming-response {
+ /// Returns a pollable which becomes ready when either the Response has
+ /// been received, or an error has occurred. When this pollable is ready,
+ /// the `get` method will return `some`.
+ @since(version = 0.2.0)
+ subscribe: func() -> pollable;
+ /// Returns the incoming HTTP Response, or an error, once one is ready.
+ ///
+ /// The outer `option` represents future readiness. Users can wait on this
+ /// `option` to become `some` using the `subscribe` method.
+ ///
+ /// The outer `result` is used to retrieve the response or error at most
+ /// once. It will be success on the first call in which the outer option
+ /// is `some`, and error on subsequent calls.
+ ///
+ /// The inner `result` represents that either the incoming HTTP Response
+ /// status and headers have received successfully, or that an error
+ /// occurred. Errors may also occur while consuming the response body,
+ /// but those will be reported by the `incoming-body` and its
+ /// `output-stream` child.
+ @since(version = 0.2.0)
+ get: func() -> option>>;
+ }
+
+ /// Attempts to extract a http-related `error` from the wasi:io `error`
+ /// provided.
+ ///
+ /// Stream operations which return
+ /// `wasi:io/stream/stream-error::last-operation-failed` have a payload of
+ /// type `wasi:io/error/error` with more information about the operation
+ /// that failed. This payload can be passed through to this function to see
+ /// if there's http-related information about the error to return.
+ ///
+ /// Note that this function is fallible because not all io-errors are
+ /// http-related errors.
+ @since(version = 0.2.0)
+ http-error-code: func(err: borrow) -> option;
+}
+
+/// This interface defines a handler of incoming HTTP Requests. It should
+/// be exported by components which can respond to HTTP Requests.
+@since(version = 0.2.0)
+interface incoming-handler {
+ @since(version = 0.2.0)
+ use types.{incoming-request, response-outparam};
+
+ /// This function is invoked with an incoming HTTP Request, and a resource
+ /// `response-outparam` which provides the capability to reply with an HTTP
+ /// Response. The response is sent by calling the `response-outparam.set`
+ /// method, which allows execution to continue after the response has been
+ /// sent. This enables both streaming to the response body, and performing other
+ /// work.
+ ///
+ /// The implementor of this function must write a response to the
+ /// `response-outparam` before returning, or else the caller will respond
+ /// with an error on its behalf.
+ @since(version = 0.2.0)
+ handle: func(request: incoming-request, response-out: response-outparam);
+}
+
+/// This interface defines a handler of outgoing HTTP Requests. It should be
+/// imported by components which wish to make HTTP Requests.
+@since(version = 0.2.0)
+interface outgoing-handler {
+ @since(version = 0.2.0)
+ use types.{outgoing-request, request-options, future-incoming-response, error-code};
+
+ /// This function is invoked with an outgoing HTTP Request, and it returns
+ /// a resource `future-incoming-response` which represents an HTTP Response
+ /// which may arrive in the future.
+ ///
+ /// The `options` argument accepts optional parameters for the HTTP
+ /// protocol's transport layer.
+ ///
+ /// This function may return an error if the `outgoing-request` is invalid
+ /// or not allowed to be made. Otherwise, protocol errors are reported
+ /// through the `future-incoming-response`.
+ @since(version = 0.2.0)
+ handle: func(request: outgoing-request, options: option) -> result;
+}
+
+/// The `wasi:http/imports` world imports all the APIs for HTTP proxies.
+/// It is intended to be `include`d in other worlds.
+@since(version = 0.2.0)
+world imports {
+ @since(version = 0.2.0)
+ import wasi:io/poll@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:clocks/monotonic-clock@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:clocks/wall-clock@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:random/random@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:io/error@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:io/streams@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:cli/stdout@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:cli/stderr@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:cli/stdin@0.2.8;
+ @since(version = 0.2.0)
+ import types;
+ @since(version = 0.2.0)
+ import outgoing-handler;
+}
+/// The `wasi:http/proxy` world captures a widely-implementable intersection of
+/// hosts that includes HTTP forward and reverse proxies. Components targeting
+/// this world may concurrently stream in and out any number of incoming and
+/// outgoing HTTP requests.
+@since(version = 0.2.0)
+world proxy {
+ @since(version = 0.2.0)
+ import wasi:io/poll@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:clocks/monotonic-clock@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:clocks/wall-clock@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:random/random@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:io/error@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:io/streams@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:cli/stdout@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:cli/stderr@0.2.8;
+ @since(version = 0.2.0)
+ import wasi:cli/stdin@0.2.8;
+ @since(version = 0.2.0)
+ import types;
+ @since(version = 0.2.0)
+ import outgoing-handler;
+
+ @since(version = 0.2.0)
+ export incoming-handler;
+}
diff --git a/wit/deps/wasi-http-0.3.0/package.wit b/wit/deps/wasi-http-0.3.0/package.wit
new file mode 100644
index 0000000..08458f7
--- /dev/null
+++ b/wit/deps/wasi-http-0.3.0/package.wit
@@ -0,0 +1,509 @@
+package wasi:http@0.3.0;
+
+/// This interface defines all of the types and methods for implementing HTTP
+/// Requests and Responses, as well as their headers, trailers, and bodies.
+@since(version = 0.3.0)
+interface types {
+ use wasi:clocks/types@0.3.0.{duration};
+
+ /// This type corresponds to HTTP standard Methods.
+ @since(version = 0.3.0)
+ variant method {
+ get,
+ head,
+ post,
+ put,
+ delete,
+ connect,
+ options,
+ trace,
+ patch,
+ other(string),
+ }
+
+ /// This type corresponds to HTTP standard Related Schemes.
+ @since(version = 0.3.0)
+ variant scheme {
+ HTTP,
+ HTTPS,
+ other(string),
+ }
+
+ /// Defines the case payload type for `DNS-error` above:
+ @since(version = 0.3.0)
+ record DNS-error-payload {
+ rcode: option,
+ info-code: option,
+ }
+
+ /// Defines the case payload type for `TLS-alert-received` above:
+ @since(version = 0.3.0)
+ record TLS-alert-received-payload {
+ alert-id: option,
+ alert-message: option,
+ }
+
+ /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
+ @since(version = 0.3.0)
+ record field-size-payload {
+ field-name: option,
+ field-size: option,
+ }
+
+ /// These cases are inspired by the IANA HTTP Proxy Error Types:
+ ///
+ @since(version = 0.3.0)
+ variant error-code {
+ DNS-timeout,
+ DNS-error(DNS-error-payload),
+ destination-not-found,
+ destination-unavailable,
+ destination-IP-prohibited,
+ destination-IP-unroutable,
+ connection-refused,
+ connection-terminated,
+ connection-timeout,
+ connection-read-timeout,
+ connection-write-timeout,
+ connection-limit-reached,
+ TLS-protocol-error,
+ TLS-certificate-error,
+ TLS-alert-received(TLS-alert-received-payload),
+ HTTP-request-denied,
+ HTTP-request-length-required,
+ HTTP-request-body-size(option),
+ HTTP-request-method-invalid,
+ HTTP-request-URI-invalid,
+ HTTP-request-URI-too-long,
+ HTTP-request-header-section-size(option),
+ HTTP-request-header-size(option),
+ HTTP-request-trailer-section-size(option),
+ HTTP-request-trailer-size(field-size-payload),
+ HTTP-response-incomplete,
+ HTTP-response-header-section-size(option),
+ HTTP-response-header-size(field-size-payload),
+ HTTP-response-body-size(option),
+ HTTP-response-trailer-section-size(option),
+ HTTP-response-trailer-size(field-size-payload),
+ HTTP-response-transfer-coding(option),
+ HTTP-response-content-coding(option),
+ HTTP-response-timeout,
+ HTTP-upgrade-failed,
+ HTTP-protocol-error,
+ loop-detected,
+ configuration-error,
+ /// This is a catch-all error for anything that doesn't fit cleanly into a
+ /// more specific case. It also includes an optional string for an
+ /// unstructured description of the error. Users should not depend on the
+ /// string for diagnosing errors, as it's not required to be consistent
+ /// between implementations.
+ internal-error(option),
+ }
+
+ /// This type enumerates the different kinds of errors that may occur when
+ /// setting or appending to a `fields` resource.
+ @since(version = 0.3.0)
+ variant header-error {
+ /// This error indicates that a `field-name` or `field-value` was
+ /// syntactically invalid when used with an operation that sets headers in a
+ /// `fields`.
+ invalid-syntax,
+ /// This error indicates that a forbidden `field-name` was used when trying
+ /// to set a header in a `fields`.
+ forbidden,
+ /// This error indicates that the operation on the `fields` was not
+ /// permitted because the fields are immutable.
+ immutable,
+ /// This error indicates that the operation would exceed an
+ /// implementation-defined limit on field sizes. This may apply to
+ /// an individual `field-value`, a single `field-name` plus all its
+ /// values, or the total aggregate size of all fields.
+ size-exceeded,
+ /// This is a catch-all error for anything that doesn't fit cleanly into a
+ /// more specific case. Implementations can use this to extend the error
+ /// type without breaking existing code. It also includes an optional
+ /// string for an unstructured description of the error. Users should not
+ /// depend on the string for diagnosing errors, as it's not required to be
+ /// consistent between implementations.
+ other(option),
+ }
+
+ /// This type enumerates the different kinds of errors that may occur when
+ /// setting fields of a `request-options` resource.
+ @since(version = 0.3.0)
+ variant request-options-error {
+ /// Indicates the specified field is not supported by this implementation.
+ not-supported,
+ /// Indicates that the operation on the `request-options` was not permitted
+ /// because it is immutable.
+ immutable,
+ /// This is a catch-all error for anything that doesn't fit cleanly into a
+ /// more specific case. Implementations can use this to extend the error
+ /// type without breaking existing code. It also includes an optional
+ /// string for an unstructured description of the error. Users should not
+ /// depend on the string for diagnosing errors, as it's not required to be
+ /// consistent between implementations.
+ other(option),
+ }
+
+ /// Field names are always strings.
+ ///
+ /// Field names should always be treated as case insensitive by the `fields`
+ /// resource for the purposes of equality checking.
+ @since(version = 0.3.0)
+ type field-name = string;
+
+ /// Field values should always be ASCII strings. However, in
+ /// reality, HTTP implementations often have to interpret malformed values,
+ /// so they are provided as a list of bytes.
+ @since(version = 0.3.0)
+ type field-value = list;
+
+ /// This following block defines the `fields` resource which corresponds to
+ /// HTTP standard Fields. Fields are a common representation used for both
+ /// Headers and Trailers.
+ ///
+ /// A `fields` may be mutable or immutable. A `fields` created using the
+ /// constructor, `from-list`, or `clone` will be mutable, but a `fields`
+ /// resource given by other means (including, but not limited to,
+ /// `request.headers`) might be be immutable. In an immutable fields, the
+ /// `set`, `append`, and `delete` operations will fail with
+ /// `header-error.immutable`.
+ ///
+ /// A `fields` resource should store `field-name`s and `field-value`s in their
+ /// original casing used to construct or mutate the `fields` resource. The `fields`
+ /// resource should use that original casing when serializing the fields for
+ /// transport or when returning them from a method.
+ ///
+ /// Implementations may impose limits on individual field values and on total
+ /// aggregate field section size. Operations that would exceed these limits
+ /// fail with `header-error.size-exceeded`
+ @since(version = 0.3.0)
+ resource fields {
+ /// Construct an empty HTTP Fields.
+ ///
+ /// The resulting `fields` is mutable.
+ constructor();
+ /// Construct an HTTP Fields.
+ ///
+ /// The resulting `fields` is mutable.
+ ///
+ /// The list represents each name-value pair in the Fields. Names
+ /// which have multiple values are represented by multiple entries in this
+ /// list with the same name.
+ ///
+ /// The tuple is a pair of the field name, represented as a string, and
+ /// Value, represented as a list of bytes. In a valid Fields, all names
+ /// and values are valid UTF-8 strings. However, values are not always
+ /// well-formed, so they are represented as a raw list of bytes.
+ ///
+ /// An error result will be returned if any header or value was
+ /// syntactically invalid, if a header was forbidden, or if the
+ /// entries would exceed an implementation size limit.
+ from-list: static func(entries: list>) -> result;
+ /// Get all of the values corresponding to a name. If the name is not present
+ /// in this `fields`, an empty list is returned. However, if the name is
+ /// present but empty, this is represented by a list with one or more
+ /// empty field-values present.
+ get: func(name: field-name) -> list;
+ /// Returns `true` when the name is present in this `fields`. If the name is
+ /// syntactically invalid, `false` is returned.
+ has: func(name: field-name) -> bool;
+ /// Set all of the values for a name. Clears any existing values for that
+ /// name, if they have been set.
+ ///
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
+ ///
+ /// Fails with `header-error.size-exceeded` if the name or values would
+ /// exceed an implementation-defined size limit.
+ set: func(name: field-name, value: list) -> result<_, header-error>;
+ /// Delete all values for a name. Does nothing if no values for the name
+ /// exist.
+ ///
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
+ delete: func(name: field-name) -> result<_, header-error>;
+ /// Delete all values for a name. Does nothing if no values for the name
+ /// exist.
+ ///
+ /// Returns all values previously corresponding to the name, if any.
+ ///
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
+ get-and-delete: func(name: field-name) -> result, header-error>;
+ /// Append a value for a name. Does not change or delete any existing
+ /// values for that name.
+ ///
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
+ ///
+ /// Fails with `header-error.size-exceeded` if the value would exceed
+ /// an implementation-defined size limit.
+ append: func(name: field-name, value: field-value) -> result<_, header-error>;
+ /// Retrieve the full set of names and values in the Fields. Like the
+ /// constructor, the list represents each name-value pair.
+ ///
+ /// The outer list represents each name-value pair in the Fields. Names
+ /// which have multiple values are represented by multiple entries in this
+ /// list with the same name.
+ ///
+ /// The names and values are always returned in the original casing and in
+ /// the order in which they will be serialized for transport.
+ copy-all: func() -> list>;
+ /// Make a deep copy of the Fields. Equivalent in behavior to calling the
+ /// `fields` constructor on the return value of `copy-all`. The resulting
+ /// `fields` is mutable.
+ clone: func() -> fields;
+ }
+
+ /// Headers is an alias for Fields.
+ @since(version = 0.3.0)
+ type headers = fields;
+
+ /// Trailers is an alias for Fields.
+ @since(version = 0.3.0)
+ type trailers = fields;
+
+ /// Represents an HTTP Request.
+ @since(version = 0.3.0)
+ resource request {
+ /// Construct a new `request` with a default `method` of `GET`, and
+ /// `none` values for `path-with-query`, `scheme`, and `authority`.
+ ///
+ /// `headers` is the HTTP Headers for the Request.
+ ///
+ /// `contents` is the optional body content stream with `none`
+ /// representing a zero-length content stream.
+ /// Once it is closed, `trailers` future must resolve to a result.
+ /// If `trailers` resolves to an error, underlying connection
+ /// will be closed immediately.
+ ///
+ /// `options` is optional `request-options` resource to be used
+ /// if the request is sent over a network connection.
+ ///
+ /// It is possible to construct, or manipulate with the accessor functions
+ /// below, a `request` with an invalid combination of `scheme`
+ /// and `authority`, or `headers` which are not permitted to be sent.
+ /// It is the obligation of the `handler.handle` implementation
+ /// to reject invalid constructions of `request`.
+ ///
+ /// The returned future resolves to result of transmission of this request.
+ new: static func(headers: headers, contents: option>, trailers: future, error-code>>, options: option) -> tuple>>;
+ /// Get the Method for the Request.
+ get-method: func() -> method;
+ /// Set the Method for the Request. Fails if the string present in a
+ /// `method.other` argument is not a syntactically valid method.
+ set-method: func(method: method) -> result;
+ /// Get the combination of the HTTP Path and Query for the Request. When
+ /// `none`, this represents an empty Path and empty Query.
+ get-path-with-query: func() -> option;
+ /// Set the combination of the HTTP Path and Query for the Request. When
+ /// `none`, this represents an empty Path and empty Query. Fails is the
+ /// string given is not a syntactically valid path and query uri component.
+ set-path-with-query: func(path-with-query: option) -> result;
+ /// Get the HTTP Related Scheme for the Request. When `none`, the
+ /// implementation may choose an appropriate default scheme.
+ get-scheme: func() -> option;
+ /// Set the HTTP Related Scheme for the Request. When `none`, the
+ /// implementation may choose an appropriate default scheme. Fails if the
+ /// string given is not a syntactically valid uri scheme.
+ set-scheme: func(scheme: option) -> result;
+ /// Get the authority of the Request's target URI. A value of `none` may be used
+ /// with Related Schemes which do not require an authority. The HTTP and
+ /// HTTPS schemes always require an authority.
+ get-authority: func() -> option;
+ /// Set the authority of the Request's target URI. A value of `none` may be used
+ /// with Related Schemes which do not require an authority. The HTTP and
+ /// HTTPS schemes always require an authority. Fails if the string given is
+ /// not a syntactically valid URI authority.
+ set-authority: func(authority: option) -> result;
+ /// Get the `request-options` to be associated with this request
+ ///
+ /// The returned `request-options` resource is immutable: `set-*` operations
+ /// will fail if invoked.
+ ///
+ /// This `request-options` resource is a child: it must be dropped before
+ /// the parent `request` is dropped, or its ownership is transferred to
+ /// another component by e.g. `handler.handle`.
+ get-options: func() -> option;
+ /// Get the headers associated with the Request.
+ ///
+ /// The returned `headers` resource is immutable: `set`, `append`, and
+ /// `delete` operations will fail with `header-error.immutable`.
+ get-headers: func() -> headers;
+ /// Get body of the Request.
+ ///
+ /// Stream returned by this method represents the contents of the body.
+ /// Once the stream is reported as closed, callers should await the returned
+ /// future to determine whether the body was received successfully.
+ /// The future will only resolve after the stream is reported as closed.
+ ///
+ /// This function takes a `res` future as a parameter, which can be used to
+ /// communicate an error in handling of the request.
+ ///
+ /// Note that function will move the `request`, but references to headers or
+ /// request options acquired from it previously will remain valid.
+ consume-body: static func(this: request, res: future>) -> tuple, future, error-code>>>;
+ }
+
+ /// Parameters for making an HTTP Request. Each of these parameters is
+ /// currently an optional timeout applicable to the transport layer of the
+ /// HTTP protocol.
+ ///
+ /// These timeouts are separate from any the user may use to bound an
+ /// asynchronous call.
+ @since(version = 0.3.0)
+ resource request-options {
+ /// Construct a default `request-options` value.
+ constructor();
+ /// The timeout for the initial connect to the HTTP Server.
+ get-connect-timeout: func() -> option;
+ /// Set the timeout for the initial connect to the HTTP Server. An error
+ /// return value indicates that this timeout is not supported or that this
+ /// handle is immutable.
+ set-connect-timeout: func(duration: option) -> result<_, request-options-error>;
+ /// The timeout for receiving the first byte of the Response body.
+ get-first-byte-timeout: func() -> option;
+ /// Set the timeout for receiving the first byte of the Response body. An
+ /// error return value indicates that this timeout is not supported or that
+ /// this handle is immutable.
+ set-first-byte-timeout: func(duration: option) -> result<_, request-options-error>;
+ /// The timeout for receiving subsequent chunks of bytes in the Response
+ /// body stream.
+ get-between-bytes-timeout: func() -> option;
+ /// Set the timeout for receiving subsequent chunks of bytes in the Response
+ /// body stream. An error return value indicates that this timeout is not
+ /// supported or that this handle is immutable.
+ set-between-bytes-timeout: func(duration: option) -> result<_, request-options-error>;
+ /// Make a deep copy of the `request-options`.
+ /// The resulting `request-options` is mutable.
+ clone: func() -> request-options;
+ }
+
+ /// This type corresponds to the HTTP standard Status Code.
+ @since(version = 0.3.0)
+ type status-code = u16;
+
+ /// Represents an HTTP Response.
+ @since(version = 0.3.0)
+ resource response {
+ /// Construct a new `response`, with a default `status-code` of `200`.
+ /// If a different `status-code` is needed, it must be set via the
+ /// `set-status-code` method.
+ ///
+ /// `headers` is the HTTP Headers for the Response.
+ ///
+ /// `contents` is the optional body content stream with `none`
+ /// representing a zero-length content stream.
+ /// Once it is closed, `trailers` future must resolve to a result.
+ /// If `trailers` resolves to an error, underlying connection
+ /// will be closed immediately.
+ ///
+ /// The returned future resolves to result of transmission of this response.
+ new: static func(headers: headers, contents: option>, trailers: future, error-code>>) -> tuple>>;
+ /// Get the HTTP Status Code for the Response.
+ get-status-code: func() -> status-code;
+ /// Set the HTTP Status Code for the Response. Fails if the status-code
+ /// given is not a valid http status code.
+ set-status-code: func(status-code: status-code) -> result;
+ /// Get the headers associated with the Response.
+ ///
+ /// The returned `headers` resource is immutable: `set`, `append`, and
+ /// `delete` operations will fail with `header-error.immutable`.
+ get-headers: func() -> headers;
+ /// Get body of the Response.
+ ///
+ /// Stream returned by this method represents the contents of the body.
+ /// Once the stream is reported as closed, callers should await the returned
+ /// future to determine whether the body was received successfully.
+ /// The future will only resolve after the stream is reported as closed.
+ ///
+ /// This function takes a `res` future as a parameter, which can be used to
+ /// communicate an error in handling of the response.
+ ///
+ /// Note that function will move the `response`, but references to headers
+ /// acquired from it previously will remain valid.
+ consume-body: static func(this: response, res: future>) -> tuple, future, error-code>>>;
+ }
+}
+
+/// This interface defines a handler of HTTP Requests.
+///
+/// In a `wasi:http/service` this interface is exported to respond to an
+/// incoming HTTP Request with a Response.
+///
+/// In `wasi:http/middleware` this interface is both exported and imported as
+/// the "downstream" and "upstream" directions of the middleware chain.
+@since(version = 0.3.0)
+interface handler {
+ use types.{request, response, error-code};
+
+ /// This function may be called with either an incoming request read from the
+ /// network or a request synthesized or forwarded by another component.
+ handle: async func(request: request) -> result;
+}
+
+/// This interface defines an HTTP client for sending "outgoing" requests.
+///
+/// Most components are expected to import this interface to provide the
+/// capability to send HTTP requests to arbitrary destinations on a network.
+///
+/// The type signature of `client.send` is the same as `handler.handle`. This
+/// duplication is currently necessary because some Component Model tooling
+/// (including WIT itself) is unable to represent a component importing two
+/// instances of the same interface. A `client.send` import may be linked
+/// directly to a `handler.handle` export to bypass the network.
+@since(version = 0.3.0)
+interface client {
+ use types.{request, response, error-code};
+
+ /// This function may be used to either send an outgoing request over the
+ /// network or to forward it to another component.
+ send: async func(request: request) -> result;
+}
+
+/// The `wasi:http/service` world captures a broad category of HTTP services
+/// including web applications, API servers, and proxies. It may be `include`d
+/// in more specific worlds such as `wasi:http/middleware`.
+@since(version = 0.3.0)
+world service {
+ import wasi:cli/types@0.3.0;
+ import wasi:cli/stdout@0.3.0;
+ import wasi:cli/stderr@0.3.0;
+ import wasi:cli/stdin@0.3.0;
+ import wasi:clocks/types@0.3.0;
+ import types;
+ import client;
+ import wasi:clocks/monotonic-clock@0.3.0;
+ import wasi:clocks/system-clock@0.3.0;
+ @unstable(feature = clocks-timezone)
+ import wasi:clocks/timezone@0.3.0;
+ import wasi:random/random@0.3.0;
+ import wasi:random/insecure@0.3.0;
+ import wasi:random/insecure-seed@0.3.0;
+
+ export handler;
+}
+/// The `wasi:http/middleware` world captures HTTP services that forward HTTP
+/// Requests to another handler.
+///
+/// Components may implement this world to allow them to participate in handler
+/// "chains" where a `request` flows through handlers on its way to some terminal
+/// `service` and corresponding `response` flows in the opposite direction.
+@since(version = 0.3.0)
+world middleware {
+ import wasi:clocks/types@0.3.0;
+ import types;
+ import handler;
+ import wasi:cli/types@0.3.0;
+ import wasi:cli/stdout@0.3.0;
+ import wasi:cli/stderr@0.3.0;
+ import wasi:cli/stdin@0.3.0;
+ import client;
+ import wasi:clocks/monotonic-clock@0.3.0;
+ import wasi:clocks/system-clock@0.3.0;
+ @unstable(feature = clocks-timezone)
+ import wasi:clocks/timezone@0.3.0;
+ import wasi:random/random@0.3.0;
+ import wasi:random/insecure@0.3.0;
+ import wasi:random/insecure-seed@0.3.0;
+
+ export handler;
+}
diff --git a/wit/deps/wasi-io-0.2.8/package.wit b/wit/deps/wasi-io-0.2.8/package.wit
new file mode 100644
index 0000000..81f5ce6
--- /dev/null
+++ b/wit/deps/wasi-io-0.2.8/package.wit
@@ -0,0 +1,299 @@
+package wasi:io@0.2.8;
+
+@since(version = 0.2.0)
+interface error {
+ /// A resource which represents some error information.
+ ///
+ /// The only method provided by this resource is `to-debug-string`,
+ /// which provides some human-readable information about the error.
+ ///
+ /// In the `wasi:io` package, this resource is returned through the
+ /// `wasi:io/streams/stream-error` type.
+ ///
+ /// To provide more specific error information, other interfaces may
+ /// offer functions to "downcast" this error into more specific types. For example,
+ /// errors returned from streams derived from filesystem types can be described using
+ /// the filesystem's own error-code type. This is done using the function
+ /// `wasi:filesystem/types/filesystem-error-code`, which takes a `borrow`
+ /// parameter and returns an `option`.
+ ///
+ /// The set of functions which can "downcast" an `error` into a more
+ /// concrete type is open.
+ @since(version = 0.2.0)
+ resource error {
+ /// Returns a string that is suitable to assist humans in debugging
+ /// this error.
+ ///
+ /// WARNING: The returned string should not be consumed mechanically!
+ /// It may change across platforms, hosts, or other implementation
+ /// details. Parsing this string is a major platform-compatibility
+ /// hazard.
+ @since(version = 0.2.0)
+ to-debug-string: func() -> string;
+ }
+}
+
+/// A poll API intended to let users wait for I/O events on multiple handles
+/// at once.
+@since(version = 0.2.0)
+interface poll {
+ /// `pollable` represents a single I/O event which may be ready, or not.
+ @since(version = 0.2.0)
+ resource pollable {
+ /// Return the readiness of a pollable. This function never blocks.
+ ///
+ /// Returns `true` when the pollable is ready, and `false` otherwise.
+ @since(version = 0.2.0)
+ 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.
+ @since(version = 0.2.0)
+ 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.
+ ///
+ /// This function traps if either:
+ /// - the list is empty, or:
+ /// - the list contains more elements than can be indexed with a `u32` value.
+ ///
+ /// 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 ready for I/O.
+ @since(version = 0.2.0)
+ poll: func(in: list>) -> list;
+}
+
+/// WASI I/O is an I/O abstraction API which is currently focused on providing
+/// stream types.
+///
+/// In the future, the component model is expected to add built-in stream types;
+/// when it does, they are expected to subsume this API.
+@since(version = 0.2.0)
+interface streams {
+ @since(version = 0.2.0)
+ use error.{error};
+ @since(version = 0.2.0)
+ use poll.{pollable};
+
+ /// An error for input-stream and output-stream operations.
+ @since(version = 0.2.0)
+ variant stream-error {
+ /// The last operation (a write or flush) failed before completion.
+ ///
+ /// More information is available in the `error` payload.
+ ///
+ /// After this, the stream will be closed. All future operations return
+ /// `stream-error::closed`.
+ last-operation-failed(error),
+ /// The stream is closed: no more input will be accepted by the
+ /// stream. A closed output-stream will return this error on all
+ /// future operations.
+ closed,
+ }
+
+ /// An input bytestream.
+ ///
+ /// `input-stream`s are *non-blocking* to the extent practical on underlying
+ /// platforms. I/O operations always return promptly; if fewer bytes are
+ /// promptly available than requested, they return the number of bytes promptly
+ /// available, which could even be zero. To wait for data to be available,
+ /// use the `subscribe` function to obtain a `pollable` which can be polled
+ /// for using `wasi:io/poll`.
+ @since(version = 0.2.0)
+ resource input-stream {
+ /// Perform a non-blocking read from the stream.
+ ///
+ /// When the source of a `read` is binary data, the bytes from the source
+ /// are returned verbatim. When the source of a `read` is known to the
+ /// implementation to be text, bytes containing the UTF-8 encoding of the
+ /// text are returned.
+ ///
+ /// This function returns a list of bytes containing the read data,
+ /// when successful. The returned list will contain up to `len` bytes;
+ /// it may return fewer than requested, but not more. The list is
+ /// empty when no bytes are available for reading at this time. The
+ /// pollable given by `subscribe` will be ready when more bytes are
+ /// available.
+ ///
+ /// This function fails with a `stream-error` when the operation
+ /// encounters an error, giving `last-operation-failed`, or when the
+ /// stream is closed, giving `closed`.
+ ///
+ /// When the caller gives a `len` of 0, it represents a request to
+ /// read 0 bytes. If the stream is still open, this call should
+ /// succeed and return an empty list, or otherwise fail with `closed`.
+ ///
+ /// The `len` parameter is a `u64`, which could represent a list of u8 which
+ /// is not possible to allocate in wasm32, or not desirable to allocate as
+ /// as a return value by the callee. The callee may return a list of bytes
+ /// less than `len` in size while more bytes are available for reading.
+ @since(version = 0.2.0)
+ read: func(len: u64) -> result, stream-error>;
+ /// Read bytes from a stream, after blocking until at least one byte can
+ /// be read. Except for blocking, behavior is identical to `read`.
+ @since(version = 0.2.0)
+ blocking-read: func(len: u64) -> result, stream-error>;
+ /// Skip bytes from a stream. Returns number of bytes skipped.
+ ///
+ /// Behaves identical to `read`, except instead of returning a list
+ /// of bytes, returns the number of bytes consumed from the stream.
+ @since(version = 0.2.0)
+ skip: func(len: u64) -> result;
+ /// Skip bytes from a stream, after blocking until at least one byte
+ /// can be skipped. Except for blocking behavior, identical to `skip`.
+ @since(version = 0.2.0)
+ blocking-skip: func(len: u64) -> result;
+ /// Create a `pollable` which will resolve once either the specified stream
+ /// has bytes available to read or the other end of the stream has been
+ /// closed.
+ /// The created `pollable` is a child resource of the `input-stream`.
+ /// Implementations may trap if the `input-stream` is dropped before
+ /// all derived `pollable`s created with this function are dropped.
+ @since(version = 0.2.0)
+ subscribe: func() -> pollable;
+ }
+
+ /// An output bytestream.
+ ///
+ /// `output-stream`s are *non-blocking* to the extent practical on
+ /// underlying platforms. Except where specified otherwise, I/O operations also
+ /// always return promptly, after the number of bytes that can be written
+ /// promptly, which could even be zero. To wait for the stream to be ready to
+ /// accept data, the `subscribe` function to obtain a `pollable` which can be
+ /// polled for using `wasi:io/poll`.
+ ///
+ /// Dropping an `output-stream` while there's still an active write in
+ /// progress may result in the data being lost. Before dropping the stream,
+ /// be sure to fully flush your writes.
+ @since(version = 0.2.0)
+ resource output-stream {
+ /// Check readiness for writing. This function never blocks.
+ ///
+ /// Returns the number of bytes permitted for the next call to `write`,
+ /// or an error. Calling `write` with more bytes than this function has
+ /// permitted will trap.
+ ///
+ /// When this function returns 0 bytes, the `subscribe` pollable will
+ /// become ready when this function will report at least 1 byte, or an
+ /// error.
+ @since(version = 0.2.0)
+ check-write: func() -> result;
+ /// Perform a write. This function never blocks.
+ ///
+ /// When the destination of a `write` is binary data, the bytes from
+ /// `contents` are written verbatim. When the destination of a `write` is
+ /// known to the implementation to be text, the bytes of `contents` are
+ /// transcoded from UTF-8 into the encoding of the destination and then
+ /// written.
+ ///
+ /// Precondition: check-write gave permit of Ok(n) and contents has a
+ /// length of less than or equal to n. Otherwise, this function will trap.
+ ///
+ /// returns Err(closed) without writing if the stream has closed since
+ /// the last call to check-write provided a permit.
+ @since(version = 0.2.0)
+ write: func(contents: list) -> result<_, stream-error>;
+ /// Perform a write of up to 4096 bytes, and then flush the stream. Block
+ /// until all of these operations are complete, or an error occurs.
+ ///
+ /// Returns success when all of the contents written are successfully
+ /// flushed to output. If an error occurs at any point before all
+ /// contents are successfully flushed, that error is returned as soon as
+ /// possible. If writing and flushing the complete contents causes the
+ /// stream to become closed, this call should return success, and
+ /// subsequent calls to check-write or other interfaces should return
+ /// stream-error::closed.
+ @since(version = 0.2.0)
+ blocking-write-and-flush: func(contents: list) -> result<_, stream-error>;
+ /// Request to flush buffered output. This function never blocks.
+ ///
+ /// This tells the output-stream that the caller intends any buffered
+ /// output to be flushed. the output which is expected to be flushed
+ /// is all that has been passed to `write` prior to this call.
+ ///
+ /// Upon calling this function, the `output-stream` will not accept any
+ /// writes (`check-write` will return `ok(0)`) until the flush has
+ /// completed. The `subscribe` pollable will become ready when the
+ /// flush has completed and the stream can accept more writes.
+ @since(version = 0.2.0)
+ flush: func() -> result<_, stream-error>;
+ /// Request to flush buffered output, and block until flush completes
+ /// and stream is ready for writing again.
+ @since(version = 0.2.0)
+ blocking-flush: func() -> result<_, stream-error>;
+ /// Create a `pollable` which will resolve once the output-stream
+ /// is ready for more writing, or an error has occurred. When this
+ /// pollable is ready, `check-write` will return `ok(n)` with n>0, or an
+ /// error.
+ ///
+ /// If the stream is closed, this pollable is always ready immediately.
+ ///
+ /// The created `pollable` is a child resource of the `output-stream`.
+ /// Implementations may trap if the `output-stream` is dropped before
+ /// all derived `pollable`s created with this function are dropped.
+ @since(version = 0.2.0)
+ subscribe: func() -> pollable;
+ /// Write zeroes to a stream.
+ ///
+ /// This should be used precisely like `write` with the exact same
+ /// preconditions (must use check-write first), but instead of
+ /// passing a list of bytes, you simply pass the number of zero-bytes
+ /// that should be written.
+ @since(version = 0.2.0)
+ write-zeroes: func(len: u64) -> result<_, stream-error>;
+ /// Perform a write of up to 4096 zeroes, and then flush the stream.
+ /// Block until all of these operations are complete, or an error
+ /// occurs.
+ ///
+ /// Functionality is equivelant to `blocking-write-and-flush` with
+ /// contents given as a list of len containing only zeroes.
+ @since(version = 0.2.0)
+ blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error>;
+ /// Read from one stream and write to another.
+ ///
+ /// The behavior of splice is equivalent to:
+ /// 1. calling `check-write` on the `output-stream`
+ /// 2. calling `read` on the `input-stream` with the smaller of the
+ /// `check-write` permitted length and the `len` provided to `splice`
+ /// 3. calling `write` on the `output-stream` with that read data.
+ ///
+ /// Any error reported by the call to `check-write`, `read`, or
+ /// `write` ends the splice and reports that error.
+ ///
+ /// This function returns the number of bytes transferred; it may be less
+ /// than `len`.
+ @since(version = 0.2.0)
+ splice: func(src: borrow, len: u64) -> result;
+ /// Read from one stream and write to another, with blocking.
+ ///
+ /// This is similar to `splice`, except that it blocks until the
+ /// `output-stream` is ready for writing, and the `input-stream`
+ /// is ready for reading, before performing the `splice`.
+ @since(version = 0.2.0)
+ blocking-splice: func(src: borrow, len: u64) -> result;
+ }
+}
+
+@since(version = 0.2.0)
+world imports {
+ @since(version = 0.2.0)
+ import error;
+ @since(version = 0.2.0)
+ import poll;
+ @since(version = 0.2.0)
+ import streams;
+}
diff --git a/wit/deps/wasi-logging-0.1.0-draft/package.wit b/wit/deps/wasi-logging-0.1.0-draft/package.wit
new file mode 100644
index 0000000..164cb5b
--- /dev/null
+++ b/wit/deps/wasi-logging-0.1.0-draft/package.wit
@@ -0,0 +1,36 @@
+package wasi:logging@0.1.0-draft;
+
+/// WASI Logging is a logging API intended to let users emit log messages with
+/// simple priority levels and context values.
+interface logging {
+ /// A log level, describing a kind of message.
+ enum level {
+ /// Describes messages about the values of variables and the flow of
+ /// control within a program.
+ trace,
+ /// Describes messages likely to be of interest to someone debugging a
+ /// program.
+ debug,
+ /// Describes messages likely to be of interest to someone monitoring a
+ /// program.
+ info,
+ /// Describes messages indicating hazardous situations.
+ warn,
+ /// Describes messages indicating serious errors.
+ error,
+ /// Describes messages indicating fatal errors.
+ critical,
+ }
+
+ /// Emit a log message.
+ ///
+ /// A log message has a `level` describing what kind of message is being
+ /// sent, a context, which is an uninterpreted string meant to help
+ /// consumers group similar messages, and a string containing the message
+ /// text.
+ log: func(level: level, context: string, message: string);
+}
+
+world imports {
+ import logging;
+}
diff --git a/wit/deps/wasi-random-0.2.8/package.wit b/wit/deps/wasi-random-0.2.8/package.wit
new file mode 100644
index 0000000..f42bd58
--- /dev/null
+++ b/wit/deps/wasi-random-0.2.8/package.wit
@@ -0,0 +1,92 @@
+package wasi:random@0.2.8;
+
+/// The insecure-seed interface for seeding hash-map DoS resistance.
+///
+/// It is intended to be portable at least between Unix-family platforms and
+/// Windows.
+@since(version = 0.2.0)
+interface insecure-seed {
+ /// Return a 128-bit value that may contain a pseudo-random value.
+ ///
+ /// The returned value is not required to be computed from a CSPRNG, and may
+ /// even be entirely deterministic. Host implementations are encouraged to
+ /// provide pseudo-random values to any program exposed to
+ /// attacker-controlled content, to enable DoS protection built into many
+ /// languages' hash-map implementations.
+ ///
+ /// This function is intended to only be called once, by a source language
+ /// to initialize Denial Of Service (DoS) protection in its hash-map
+ /// implementation.
+ ///
+ /// # Expected future evolution
+ ///
+ /// This will likely be changed to a value import, to prevent it from being
+ /// called multiple times and potentially used for purposes other than DoS
+ /// protection.
+ @since(version = 0.2.0)
+ insecure-seed: func() -> tuple;
+}
+
+/// The insecure interface for insecure pseudo-random numbers.
+///
+/// It is intended to be portable at least between Unix-family platforms and
+/// Windows.
+@since(version = 0.2.0)
+interface insecure {
+ /// Return `len` insecure pseudo-random bytes.
+ ///
+ /// This function is not cryptographically secure. Do not use it for
+ /// anything related to security.
+ ///
+ /// There are no requirements on the values of the returned bytes, however
+ /// implementations are encouraged to return evenly distributed values with
+ /// a long period.
+ @since(version = 0.2.0)
+ get-insecure-random-bytes: func(len: u64) -> list;
+
+ /// Return an insecure pseudo-random `u64` value.
+ ///
+ /// This function returns the same type of pseudo-random data as
+ /// `get-insecure-random-bytes`, represented as a `u64`.
+ @since(version = 0.2.0)
+ get-insecure-random-u64: func() -> u64;
+}
+
+/// WASI Random is a random data API.
+///
+/// It is intended to be portable at least between Unix-family platforms and
+/// Windows.
+@since(version = 0.2.0)
+interface random {
+ /// Return `len` cryptographically-secure random or pseudo-random bytes.
+ ///
+ /// This function must produce data at least as cryptographically secure and
+ /// fast as an adequately seeded cryptographically-secure pseudo-random
+ /// number generator (CSPRNG). It must not block, from the perspective of
+ /// the calling program, under any circumstances, including on the first
+ /// request and on requests for numbers of bytes. The returned data must
+ /// always be unpredictable.
+ ///
+ /// This function must always return fresh data. Deterministic environments
+ /// must omit this function, rather than implementing it with deterministic
+ /// data.
+ @since(version = 0.2.0)
+ get-random-bytes: func(len: u64) -> list;
+
+ /// Return a cryptographically-secure random or pseudo-random `u64` value.
+ ///
+ /// This function returns the same type of data as `get-random-bytes`,
+ /// represented as a `u64`.
+ @since(version = 0.2.0)
+ get-random-u64: func() -> u64;
+}
+
+@since(version = 0.2.0)
+world imports {
+ @since(version = 0.2.0)
+ import random;
+ @since(version = 0.2.0)
+ import insecure;
+ @since(version = 0.2.0)
+ import insecure-seed;
+}
diff --git a/wit/deps/wasi-random-0.3.0/package.wit b/wit/deps/wasi-random-0.3.0/package.wit
new file mode 100644
index 0000000..0b9a55f
--- /dev/null
+++ b/wit/deps/wasi-random-0.3.0/package.wit
@@ -0,0 +1,107 @@
+package wasi:random@0.3.0;
+
+/// The insecure-seed interface for seeding hash-map DoS resistance.
+///
+/// It is intended to be portable at least between Unix-family platforms and
+/// Windows.
+@since(version = 0.3.0)
+interface insecure-seed {
+ /// Return a 128-bit value that may contain a pseudo-random value.
+ ///
+ /// The returned value is not required to be computed from a CSPRNG, and may
+ /// even be entirely deterministic. Host implementations are encouraged to
+ /// provide pseudo-random values to any program exposed to
+ /// attacker-controlled content, to enable DoS protection built into many
+ /// languages' hash-map implementations.
+ ///
+ /// This function is intended to only be called once, by a source language
+ /// to initialize Denial Of Service (DoS) protection in its hash-map
+ /// implementation.
+ ///
+ /// # Expected future evolution
+ ///
+ /// This will likely be changed to a value import, to prevent it from being
+ /// called multiple times and potentially used for purposes other than DoS
+ /// protection.
+ @since(version = 0.3.0)
+ get-insecure-seed: func() -> tuple;
+}
+
+/// The insecure interface for insecure pseudo-random numbers.
+///
+/// It is intended to be portable at least between Unix-family platforms and
+/// Windows.
+@since(version = 0.3.0)
+interface insecure {
+ /// Return up to `max-len` insecure pseudo-random bytes.
+ ///
+ /// This function is not cryptographically secure. Do not use it for
+ /// anything related to security.
+ ///
+ /// There are no requirements on the values of the returned bytes, however
+ /// implementations are encouraged to return evenly distributed values with
+ /// a long period.
+ ///
+ /// Implementations MAY return fewer bytes than requested (a short read).
+ /// Callers that require exactly `max-len` bytes MUST call this function in
+ /// a loop until the desired number of bytes has been accumulated.
+ /// Implementations MUST return at least 1 byte when `max-len` is greater
+ /// than zero. When `max-len` is zero, implementations MUST return an empty
+ /// list without trapping.
+ @since(version = 0.3.0)
+ get-insecure-random-bytes: func(max-len: u64) -> list;
+
+ /// Return an insecure pseudo-random `u64` value.
+ ///
+ /// This function returns the same type of pseudo-random data as
+ /// `get-insecure-random-bytes`, represented as a `u64`.
+ @since(version = 0.3.0)
+ get-insecure-random-u64: func() -> u64;
+}
+
+/// WASI Random is a random data API.
+///
+/// It is intended to be portable at least between Unix-family platforms and
+/// Windows.
+@since(version = 0.3.0)
+interface random {
+ /// Return up to `max-len` cryptographically-secure random or pseudo-random
+ /// bytes.
+ ///
+ /// This function must produce data at least as cryptographically secure and
+ /// fast as an adequately seeded cryptographically-secure pseudo-random
+ /// number generator (CSPRNG). It must not block, from the perspective of
+ /// the calling program, under any circumstances, including on the first
+ /// request and on requests for numbers of bytes. The returned data must
+ /// always be unpredictable.
+ ///
+ /// Implementations MAY return fewer bytes than requested (a short read).
+ /// Callers that require exactly `max-len` bytes MUST call this function in
+ /// a loop until the desired number of bytes has been accumulated.
+ /// Implementations MUST return at least 1 byte when `max-len` is greater
+ /// than zero. When `max-len` is zero, implementations MUST return an empty
+ /// list without trapping.
+ ///
+ /// This function must always return fresh data. Deterministic environments
+ /// must omit this function, rather than implementing it with deterministic
+ /// data.
+ @since(version = 0.3.0)
+ get-random-bytes: func(max-len: u64) -> list;
+
+ /// Return a cryptographically-secure random or pseudo-random `u64` value.
+ ///
+ /// This function returns the same type of data as `get-random-bytes`,
+ /// represented as a `u64`.
+ @since(version = 0.3.0)
+ get-random-u64: func() -> u64;
+}
+
+@since(version = 0.3.0)
+world imports {
+ @since(version = 0.3.0)
+ import random;
+ @since(version = 0.3.0)
+ import insecure;
+ @since(version = 0.3.0)
+ import insecure-seed;
+}
diff --git a/wit/deps/wasi-sockets-0.2.8/package.wit b/wit/deps/wasi-sockets-0.2.8/package.wit
new file mode 100644
index 0000000..94b11cc
--- /dev/null
+++ b/wit/deps/wasi-sockets-0.2.8/package.wit
@@ -0,0 +1,949 @@
+package wasi:sockets@0.2.8;
+
+@since(version = 0.2.0)
+interface network {
+ @unstable(feature = network-error-code)
+ use wasi:io/error@0.2.8.{error};
+
+ /// An opaque resource that represents access to (a subset of) the network.
+ /// This enables context-based security for networking.
+ /// There is no need for this to map 1:1 to a physical network interface.
+ @since(version = 0.2.0)
+ resource network;
+
+ /// Error codes.
+ ///
+ /// In theory, every API can return any error code.
+ /// In practice, API's typically only return the errors documented per API
+ /// combined with a couple of errors that are always possible:
+ /// - `unknown`
+ /// - `access-denied`
+ /// - `not-supported`
+ /// - `out-of-memory`
+ /// - `concurrency-conflict`
+ ///
+ /// See each individual API for what the POSIX equivalents are. They sometimes differ per API.
+ @since(version = 0.2.0)
+ enum error-code {
+ /// Unknown error
+ unknown,
+ /// Access denied.
+ ///
+ /// POSIX equivalent: EACCES, EPERM
+ access-denied,
+ /// The operation is not supported.
+ ///
+ /// POSIX equivalent: EOPNOTSUPP
+ not-supported,
+ /// One of the arguments is invalid.
+ ///
+ /// POSIX equivalent: EINVAL
+ invalid-argument,
+ /// Not enough memory to complete the operation.
+ ///
+ /// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY
+ out-of-memory,
+ /// The operation timed out before it could finish completely.
+ timeout,
+ /// This operation is incompatible with another asynchronous operation that is already in progress.
+ ///
+ /// POSIX equivalent: EALREADY
+ concurrency-conflict,
+ /// Trying to finish an asynchronous operation that:
+ /// - has not been started yet, or:
+ /// - was already finished by a previous `finish-*` call.
+ ///
+ /// Note: this is scheduled to be removed when `future`s are natively supported.
+ not-in-progress,
+ /// The operation has been aborted because it could not be completed immediately.
+ ///
+ /// Note: this is scheduled to be removed when `future`s are natively supported.
+ would-block,
+ /// The operation is not valid in the socket's current state.
+ invalid-state,
+ /// A new socket resource could not be created because of a system limit.
+ new-socket-limit,
+ /// A bind operation failed because the provided address is not an address that the `network` can bind to.
+ address-not-bindable,
+ /// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available.
+ address-in-use,
+ /// The remote address is not reachable
+ remote-unreachable,
+ /// The TCP connection was forcefully rejected
+ connection-refused,
+ /// The TCP connection was reset.
+ connection-reset,
+ /// A TCP connection was aborted.
+ connection-aborted,
+ /// The size of a datagram sent to a UDP socket exceeded the maximum
+ /// supported size.
+ datagram-too-large,
+ /// Name does not exist or has no suitable associated IP addresses.
+ name-unresolvable,
+ /// A temporary failure in name resolution occurred.
+ temporary-resolver-failure,
+ /// A permanent failure in name resolution occurred.
+ permanent-resolver-failure,
+ }
+
+ @since(version = 0.2.0)
+ enum ip-address-family {
+ /// Similar to `AF_INET` in POSIX.
+ ipv4,
+ /// Similar to `AF_INET6` in POSIX.
+ ipv6,
+ }
+
+ @since(version = 0.2.0)
+ type ipv4-address = tuple;
+
+ @since(version = 0.2.0)
+ type ipv6-address = tuple;
+
+ @since(version = 0.2.0)
+ variant ip-address {
+ ipv4(ipv4-address),
+ ipv6(ipv6-address),
+ }
+
+ @since(version = 0.2.0)
+ record ipv4-socket-address {
+ /// sin_port
+ port: u16,
+ /// sin_addr
+ address: ipv4-address,
+ }
+
+ @since(version = 0.2.0)
+ record ipv6-socket-address {
+ /// sin6_port
+ port: u16,
+ /// sin6_flowinfo
+ flow-info: u32,
+ /// sin6_addr
+ address: ipv6-address,
+ /// sin6_scope_id
+ scope-id: u32,
+ }
+
+ @since(version = 0.2.0)
+ variant ip-socket-address {
+ ipv4(ipv4-socket-address),
+ ipv6(ipv6-socket-address),
+ }
+
+ /// Attempts to extract a network-related `error-code` from the stream
+ /// `error` provided.
+ ///
+ /// Stream operations which return `stream-error::last-operation-failed`
+ /// have a payload with more information about the operation that failed.
+ /// This payload can be passed through to this function to see if there's
+ /// network-related information about the error to return.
+ ///
+ /// Note that this function is fallible because not all stream-related
+ /// errors are network-related errors.
+ @unstable(feature = network-error-code)
+ network-error-code: func(err: borrow) -> option;
+}
+
+/// This interface provides a value-export of the default network handle..
+@since(version = 0.2.0)
+interface instance-network {
+ @since(version = 0.2.0)
+ use network.{network};
+
+ /// Get a handle to the default network.
+ @since(version = 0.2.0)
+ instance-network: func() -> network;
+}
+
+@since(version = 0.2.0)
+interface ip-name-lookup {
+ @since(version = 0.2.0)
+ use wasi:io/poll@0.2.8.{pollable};
+ @since(version = 0.2.0)
+ use network.{network, error-code, ip-address};
+
+ @since(version = 0.2.0)
+ resource resolve-address-stream {
+ /// Returns the next address from the resolver.
+ ///
+ /// This function should be called multiple times. On each call, it will
+ /// return the next address in connection order preference. If all
+ /// addresses have been exhausted, this function returns `none`.
+ ///
+ /// This function never returns IPv4-mapped IPv6 addresses.
+ ///
+ /// # Typical errors
+ /// - `name-unresolvable`: Name does not exist or has no suitable associated IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY)
+ /// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN)
+ /// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL)
+ /// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN)
+ @since(version = 0.2.0)
+ resolve-next-address: func() -> result, error-code>;
+ /// Create a `pollable` which will resolve once the stream is ready for I/O.
+ ///
+ /// Note: this function is here for WASI 0.2 only.
+ /// It's planned to be removed when `future` is natively supported in Preview3.
+ @since(version = 0.2.0)
+ subscribe: func() -> pollable;
+ }
+
+ /// Resolve an internet host name to a list of IP addresses.
+ ///
+ /// Unicode domain names are automatically converted to ASCII using IDNA encoding.
+ /// If the input is an IP address string, the address is parsed and returned
+ /// as-is without making any external requests.
+ ///
+ /// See the wasi-socket proposal README.md for a comparison with getaddrinfo.
+ ///
+ /// This function never blocks. It either immediately fails or immediately
+ /// returns successfully with a `resolve-address-stream` that can be used
+ /// to (asynchronously) fetch the results.
+ ///
+ /// # Typical errors
+ /// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address.
+ ///
+ /// # References:
+ /// -
+ /// -
+ /// -
+ /// -
+ @since(version = 0.2.0)
+ resolve-addresses: func(network: borrow, name: string) -> result;
+}
+
+@since(version = 0.2.0)
+interface tcp {
+ @since(version = 0.2.0)
+ use wasi:io/streams@0.2.8.{input-stream, output-stream};
+ @since(version = 0.2.0)
+ use wasi:io/poll@0.2.8.{pollable};
+ @since(version = 0.2.0)
+ use wasi:clocks/monotonic-clock@0.2.8.{duration};
+ @since(version = 0.2.0)
+ use network.{network, error-code, ip-socket-address, ip-address-family};
+
+ @since(version = 0.2.0)
+ enum shutdown-type {
+ /// Similar to `SHUT_RD` in POSIX.
+ receive,
+ /// Similar to `SHUT_WR` in POSIX.
+ send,
+ /// Similar to `SHUT_RDWR` in POSIX.
+ both,
+ }
+
+ /// A TCP socket resource.
+ ///
+ /// The socket can be in one of the following states:
+ /// - `unbound`
+ /// - `bind-in-progress`
+ /// - `bound` (See note below)
+ /// - `listen-in-progress`
+ /// - `listening`
+ /// - `connect-in-progress`
+ /// - `connected`
+ /// - `closed`
+ /// See
+ /// for more information.
+ ///
+ /// Note: Except where explicitly mentioned, whenever this documentation uses
+ /// the term "bound" without backticks it actually means: in the `bound` state *or higher*.
+ /// (i.e. `bound`, `listen-in-progress`, `listening`, `connect-in-progress` or `connected`)
+ ///
+ /// In addition to the general error codes documented on the
+ /// `network::error-code` type, TCP socket methods may always return
+ /// `error(invalid-state)` when in the `closed` state.
+ @since(version = 0.2.0)
+ resource tcp-socket {
+ /// Bind the socket to a specific network on the provided IP address and port.
+ ///
+ /// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which
+ /// network interface(s) to bind to.
+ /// If the TCP/UDP port is zero, the socket will be bound to a random free port.
+ ///
+ /// Bind can be attempted multiple times on the same socket, even with
+ /// different arguments on each iteration. But never concurrently and
+ /// only as long as the previous bind failed. Once a bind succeeds, the
+ /// binding can't be changed anymore.
+ ///
+ /// # Typical errors
+ /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)
+ /// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL)
+ /// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL)
+ /// - `invalid-state`: The socket is already bound. (EINVAL)
+ /// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)
+ /// - `address-in-use`: Address is already in use. (EADDRINUSE)
+ /// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL)
+ /// - `not-in-progress`: A `bind` operation is not in progress.
+ /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
+ ///
+ /// # Implementors note
+ /// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT
+ /// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR
+ /// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior
+ /// and SO_REUSEADDR performs something different entirely.
+ ///
+ /// Unlike in POSIX, in WASI the bind operation is async. This enables
+ /// interactive WASI hosts to inject permission prompts. Runtimes that
+ /// don't want to make use of this ability can simply call the native
+ /// `bind` as part of either `start-bind` or `finish-bind`.
+ ///
+ /// # References
+ /// -
+ /// -
+ /// -
+ /// -
+ @since(version = 0.2.0)
+ start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>;
+ @since(version = 0.2.0)
+ finish-bind: func() -> result<_, error-code>;
+ /// Connect to a remote endpoint.
+ ///
+ /// On success:
+ /// - the socket is transitioned into the `connected` state.
+ /// - a pair of streams is returned that can be used to read & write to the connection
+ ///
+ /// After a failed connection attempt, the socket will be in the `closed`
+ /// state and the only valid action left is to `drop` the socket. A single
+ /// socket can not be used to connect more than once.
+ ///
+ /// # Typical errors
+ /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
+ /// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS)
+ /// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos)
+ /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows)
+ /// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows)
+ /// - `invalid-argument`: The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`.
+ /// - `invalid-state`: The socket is already in the `connected` state. (EISCONN)
+ /// - `invalid-state`: The socket is already in the `listening` state. (EOPNOTSUPP, EINVAL on Windows)
+ /// - `timeout`: Connection timed out. (ETIMEDOUT)
+ /// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED)
+ /// - `connection-reset`: The connection was reset. (ECONNRESET)
+ /// - `connection-aborted`: The connection was aborted. (ECONNABORTED)
+ /// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
+ /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)
+ /// - `not-in-progress`: A connect operation is not in progress.
+ /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
+ ///
+ /// # Implementors note
+ /// The POSIX equivalent of `start-connect` is the regular `connect` syscall.
+ /// Because all WASI sockets are non-blocking this is expected to return
+ /// EINPROGRESS, which should be translated to `ok()` in WASI.
+ ///
+ /// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT`
+ /// with a timeout of 0 on the socket descriptor. Followed by a check for
+ /// the `SO_ERROR` socket option, in case the poll signaled readiness.
+ ///
+ /// # References
+ /// -
+ /// -
+ /// -
+ /// -
+ @since(version = 0.2.0)
+ start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>;
+ @since(version = 0.2.0)
+ finish-connect: func() -> result, error-code>;
+ /// Start listening for new connections.
+ ///
+ /// Transitions the socket into the `listening` state.
+ ///
+ /// Unlike POSIX, the socket must already be explicitly bound.
+ ///
+ /// # Typical errors
+ /// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ)
+ /// - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD)
+ /// - `invalid-state`: The socket is already in the `listening` state.
+ /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE)
+ /// - `not-in-progress`: A listen operation is not in progress.
+ /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
+ ///
+ /// # Implementors note
+ /// Unlike in POSIX, in WASI the listen operation is async. This enables
+ /// interactive WASI hosts to inject permission prompts. Runtimes that
+ /// don't want to make use of this ability can simply call the native
+ /// `listen` as part of either `start-listen` or `finish-listen`.
+ ///
+ /// # References
+ /// -
+ /// -
+ /// -
+ /// -
+ @since(version = 0.2.0)
+ start-listen: func() -> result<_, error-code>;
+ @since(version = 0.2.0)
+ finish-listen: func() -> result<_, error-code>;
+ /// Accept a new client socket.
+ ///
+ /// The returned socket is bound and in the `connected` state. The following properties are inherited from the listener socket:
+ /// - `address-family`
+ /// - `keep-alive-enabled`
+ /// - `keep-alive-idle-time`
+ /// - `keep-alive-interval`
+ /// - `keep-alive-count`
+ /// - `hop-limit`
+ /// - `receive-buffer-size`
+ /// - `send-buffer-size`
+ ///
+ /// On success, this function returns the newly accepted client socket along with
+ /// a pair of streams that can be used to read & write to the connection.
+ ///
+ /// # Typical errors
+ /// - `invalid-state`: Socket is not in the `listening` state. (EINVAL)
+ /// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN)
+ /// - `connection-aborted`: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED)
+ /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE)
+ ///
+ /// # References
+ /// -
+ /// -
+ /// -
+ /// -
+ @since(version = 0.2.0)
+ accept: func() -> result, error-code>;
+ /// Get the bound local address.
+ ///
+ /// POSIX mentions:
+ /// > If the socket has not been bound to a local name, the value
+ /// > stored in the object pointed to by `address` is unspecified.
+ ///
+ /// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet.
+ ///
+ /// # Typical errors
+ /// - `invalid-state`: The socket is not bound to any local address.
+ ///
+ /// # References
+ /// -
+ /// -
+ /// -
+ /// -
+ @since(version = 0.2.0)
+ local-address: func() -> result;
+ /// Get the remote address.
+ ///
+ /// # Typical errors
+ /// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN)
+ ///
+ /// # References
+ /// -
+ /// -
+ /// -
+ /// -
+ @since(version = 0.2.0)
+ remote-address: func() -> result;
+ /// Whether the socket is in the `listening` state.
+ ///
+ /// Equivalent to the SO_ACCEPTCONN socket option.
+ @since(version = 0.2.0)
+ is-listening: func() -> bool;
+ /// Whether this is a IPv4 or IPv6 socket.
+ ///
+ /// Equivalent to the SO_DOMAIN socket option.
+ @since(version = 0.2.0)
+ address-family: func() -> ip-address-family;
+ /// Hints the desired listen queue size. Implementations are free to ignore this.
+ ///
+ /// If the provided value is 0, an `invalid-argument` error is returned.
+ /// Any other value will never cause an error, but it might be silently clamped and/or rounded.
+ ///
+ /// # Typical errors
+ /// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen.
+ /// - `invalid-argument`: (set) The provided value was 0.
+ /// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state.
+ @since(version = 0.2.0)
+ set-listen-backlog-size: func(value: u64) -> result<_, error-code>;
+ /// Enables or disables keepalive.
+ ///
+ /// The keepalive behavior can be adjusted using:
+ /// - `keep-alive-idle-time`
+ /// - `keep-alive-interval`
+ /// - `keep-alive-count`
+ /// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true.
+ ///
+ /// Equivalent to the SO_KEEPALIVE socket option.
+ @since(version = 0.2.0)
+ keep-alive-enabled: func() -> result;
+ @since(version = 0.2.0)
+ set-keep-alive-enabled: func(value: bool) -> result<_, error-code>;
+ /// Amount of time the connection has to be idle before TCP starts sending keepalive packets.
+ ///
+ /// If the provided value is 0, an `invalid-argument` error is returned.
+ /// Any other value will never cause an error, but it might be silently clamped and/or rounded.
+ /// I.e. after setting a value, reading the same setting back may return a different value.
+ ///
+ /// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS)
+ ///
+ /// # Typical errors
+ /// - `invalid-argument`: (set) The provided value was 0.
+ @since(version = 0.2.0)
+ keep-alive-idle-time: func() -> result