From d61801fc5dd37e23606621d9ca666d8509307396 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Tue, 16 Sep 2025 20:12:26 -0600 Subject: [PATCH] attempt http call --- samples/calculator/Adder/Adder.csproj | 18 +- samples/calculator/Adder/OperationsImpl.cs | 126 +- samples/calculator/Adder/calculator.wit | 14 - .../Adder/generated/wit/Computer.cs | 139 + ....exports.example.calculator.IOperations.cs | 14 + ...ts.example.calculator.OperationsInterop.cs | 72 + ...asi.clocks.v0_2_0.MonotonicClockInterop.cs | 66 + ...rld.wit.imports.wasi.http.v0_2_0.ITypes.cs | 6090 +++++++++++++++++ ...wasi.http.v0_2_0.OutgoingHandlerInterop.cs | 657 ++ ...t.imports.wasi.http.v0_2_0.TypesInterop.cs | 629 ++ ...wit.imports.wasi.io.v0_2_0.ErrorInterop.cs | 10 + ...World.wit.imports.wasi.io.v0_2_0.IError.cs | 54 + ...rWorld.wit.imports.wasi.io.v0_2_0.IPoll.cs | 63 + ...rld.wit.imports.wasi.io.v0_2_0.IStreams.cs | 1161 ++++ ....wit.imports.wasi.io.v0_2_0.PollInterop.cs | 57 + ...t.imports.wasi.io.v0_2_0.StreamsInterop.cs | 10 + .../wit/ComputerWorld_component_type.wit | 276 + ...uterWorld_wasm_import_linkage_attribute.cs | 11 + .../Adder/generated/wit/lastbuild.txt | 0 samples/calculator/Adder/policy.yaml | 6 + samples/calculator/Adder/wit/calculator.wit | 16 + .../Adder/wit/deps/wasi-cli-0.2.0/package.wit | 20 + .../wit/deps/wasi-clocks-0.2.0/package.wit | 29 + .../wit/deps/wasi-http-0.2.0/package.wit | 571 ++ .../Adder/wit/deps/wasi-io-0.2.0/package.wit | 48 + .../wit/deps/wasi-random-0.2.0/package.wit | 8 + samples/calculator/Adder/wkg.lock | 12 + .../CalculatorComposed.csproj | 3 +- .../CalculatorHost/CalculatorHost.csproj | 3 +- samples/calculator/CalculatorHost/Program.cs | 12 + samples/calculator/run.ps1 | 23 + 31 files changed, 10194 insertions(+), 24 deletions(-) delete mode 100644 samples/calculator/Adder/calculator.wit create mode 100644 samples/calculator/Adder/generated/wit/Computer.cs create mode 100644 samples/calculator/Adder/generated/wit/ComputerWorld.wit.exports.example.calculator.IOperations.cs create mode 100644 samples/calculator/Adder/generated/wit/ComputerWorld.wit.exports.example.calculator.OperationsInterop.cs create mode 100644 samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop.cs create mode 100644 samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.cs create mode 100644 samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.http.v0_2_0.OutgoingHandlerInterop.cs create mode 100644 samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.http.v0_2_0.TypesInterop.cs create mode 100644 samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.ErrorInterop.cs create mode 100644 samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.cs create mode 100644 samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.cs create mode 100644 samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.cs create mode 100644 samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.PollInterop.cs create mode 100644 samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.StreamsInterop.cs create mode 100644 samples/calculator/Adder/generated/wit/ComputerWorld_component_type.wit create mode 100644 samples/calculator/Adder/generated/wit/ComputerWorld_wasm_import_linkage_attribute.cs create mode 100644 samples/calculator/Adder/generated/wit/lastbuild.txt create mode 100644 samples/calculator/Adder/policy.yaml create mode 100644 samples/calculator/Adder/wit/calculator.wit create mode 100644 samples/calculator/Adder/wit/deps/wasi-cli-0.2.0/package.wit create mode 100644 samples/calculator/Adder/wit/deps/wasi-clocks-0.2.0/package.wit create mode 100644 samples/calculator/Adder/wit/deps/wasi-http-0.2.0/package.wit create mode 100644 samples/calculator/Adder/wit/deps/wasi-io-0.2.0/package.wit create mode 100644 samples/calculator/Adder/wit/deps/wasi-random-0.2.0/package.wit create mode 100644 samples/calculator/Adder/wkg.lock create mode 100644 samples/calculator/run.ps1 diff --git a/samples/calculator/Adder/Adder.csproj b/samples/calculator/Adder/Adder.csproj index 3909d08..5b0d86b 100644 --- a/samples/calculator/Adder/Adder.csproj +++ b/samples/calculator/Adder/Adder.csproj @@ -12,7 +12,8 @@ wasi-wasm - adder + adder2 + generated/wit @@ -21,7 +22,18 @@ - + + + - + + + + $(ProjectDir)policy.yaml + $(PublishDir)$(TargetName).policy.yaml + + + + diff --git a/samples/calculator/Adder/OperationsImpl.cs b/samples/calculator/Adder/OperationsImpl.cs index 0f6bb96..735cfaa 100644 --- a/samples/calculator/Adder/OperationsImpl.cs +++ b/samples/calculator/Adder/OperationsImpl.cs @@ -1,14 +1,130 @@ -namespace ComputerWorld.wit.exports.example.calculator; +using System; +using ComputerWorld.wit.imports.wasi.http.v0_2_0; // May be generated if wasi:http present; harmless if unused +using static ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes; +namespace ComputerWorld.wit.exports.example.calculator; + +// Implementation of operations interface generated from WIT public class OperationsImpl : IOperations { - public static int Add(int left, int right) + public static int Add(int left, int right) => left + right; + + public static string ToUpper(string input) => input.ToUpperInvariant(); + + // Renamed to match WIT change: get-repo(owner, name) + public static string GetRepo(string owner, string name) { - return left + right; + // Performs a simple unauthenticated GET to the GitHub repository metadata endpoint. + // Parameters map directly to the GitHub URL path segments. + try + { + if (string.IsNullOrWhiteSpace(owner) || string.IsNullOrWhiteSpace(name)) + return "{\"error\":\"missing-owner-or-name\"}"; + var safeOwner = owner.Trim(); + var safeName = name.Trim(); + // Very basic validation to avoid path injection + if (safeOwner.Contains('/') || safeName.Contains('/')) + return "{\"error\":\"invalid-slash\"}"; + var url = $"https://api.github.com/repos/{safeOwner}/{safeName}"; + + // Empty headers collection (GitHub typically requires a User-Agent, but per request no headers are passed). + // Fields headers; + // try + // { + // headers = Fields.FromList(new System.Collections.Generic.List<(string, byte[])>()); + // } + // catch (WitException hex) + // { + // return $"{{\"error\":\"header-build\",\"detail\":\"{hex.TypedValue.Tag}\"}}"; + // } + + var headers = new Fields(); + try { + // GitHub API recommends providing a User-Agent; also add Accept for clarity. + headers.Set("User-Agent", new System.Collections.Generic.List { System.Text.Encoding.UTF8.GetBytes("componentize-dotnet-sample/1.0") }); + headers.Set("Accept", new System.Collections.Generic.List { System.Text.Encoding.UTF8.GetBytes("application/vnd.github+json") }); + } catch (WitException) { /* non-fatal if immutable/forbidden */ } + var req = new OutgoingRequest(headers); + req.SetMethod(Method.Get()); + + var uri = new Uri(url); + req.SetScheme(uri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase) ? Scheme.Https() : Scheme.Http()); + req.SetAuthority(uri.Authority); + req.SetPathWithQuery(uri.PathAndQuery); + + RequestOptions? options = null; + var future = OutgoingHandlerInterop.Handle(req, options); + + IncomingResponse? incoming = null; + const int timeoutMs = 5000; // total budget + var sw = System.Diagnostics.Stopwatch.StartNew(); + int delay = 10; // start with 10ms, exponential backoff up to 250ms + while (sw.ElapsedMilliseconds < timeoutMs) + { + var resultOpt = future.Get(); + if (resultOpt != null) + { + var outer = resultOpt.Value; + if (outer.IsOk) + { + var inner = outer.AsOk; + if (inner.IsOk) + { + incoming = inner.AsOk; + } + else + { + var err = inner.AsErr; + return $"{{\"error\":\"http-transport\",\"code\":\"{err.Tag}\"}}"; + } + } + break; + } + System.Threading.Thread.Sleep(delay); + delay = Math.Min(delay * 2, 250); + } + + if (incoming == null) + { + return $"{{\"error\":\"timeout\",\"elapsedMs\":{sw.ElapsedMilliseconds}}}"; + } + + int status = incoming.Status(); + string body = string.Empty; + try + { + var bodyRes = incoming.Consume(); + var stream = bodyRes.Stream(); + var bytes = new System.Collections.Generic.List(); + while (true) + { + var chunk = stream.Read(1024); + if (chunk.Length == 0) + break; + bytes.AddRange(chunk); + } + body = System.Text.Encoding.UTF8.GetString(bytes.ToArray()); + stream.Dispose(); + bodyRes.Dispose(); + } + finally + { + incoming.Dispose(); + future.Dispose(); + } + + if (status >= 200 && status < 300) return body; + return $"{{\"error\":\"http-status\",\"status\":{status},\"body\":{EscapeForJson(body)} }}"; + } + catch (Exception ex) + { + return $"{{\"error\":\"exception\",\"message\":\"{Escape(ex.Message)}\"}}"; + } } - public static string ToUpper(string input) + private static string Escape(string s) => s.Replace("\\", "\\\\").Replace("\"", "\\\""); + private static string EscapeForJson(string s) { - return input.ToUpperInvariant(); + return "\"" + Escape(s) + "\""; } } diff --git a/samples/calculator/Adder/calculator.wit b/samples/calculator/Adder/calculator.wit deleted file mode 100644 index 9f4bdc0..0000000 --- a/samples/calculator/Adder/calculator.wit +++ /dev/null @@ -1,14 +0,0 @@ -package example:calculator; - -interface operations { - add: func(left: s32, right: s32) -> s32; - to-upper: func(input: string) -> string; -} - -world computer { - export operations; -} - -world hostapp { - import operations; -} diff --git a/samples/calculator/Adder/generated/wit/Computer.cs b/samples/calculator/Adder/generated/wit/Computer.cs new file mode 100644 index 0000000..b5c948b --- /dev/null +++ b/samples/calculator/Adder/generated/wit/Computer.cs @@ -0,0 +1,139 @@ +// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! +// +#nullable enable +using System.Runtime.InteropServices; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +namespace ComputerWorld { + + public interface IComputerWorld { + } + + public readonly struct None {} + + [StructLayout(LayoutKind.Sequential)] + public readonly struct Result + { + public readonly byte Tag; + private readonly object value; + + private Result(byte tag, object value) + { + Tag = tag; + this.value = value; + } + + public static Result Ok(TOk ok) + { + return new Result(Tags.Ok, ok!); + } + + public static Result Err(TErr err) + { + return new Result(Tags.Err, err!); + } + + public bool IsOk => Tag == Tags.Ok; + public bool IsErr => Tag == Tags.Err; + + public TOk AsOk + { + get + { + if (Tag == Tags.Ok) + { + return (TOk)value; + } + + throw new ArgumentException("expected k, got " + Tag); + } + } + + public TErr AsErr + { + get + { + if (Tag == Tags.Err) + { + return (TErr)value; + } + + throw new ArgumentException("expected Err, got " + Tag); + } + } + + public class Tags + { + public const byte Ok = 0; + public const byte Err = 1; + } + } + + public class Option { + private static Option none = new (); + + private Option() + { + HasValue = false; + } + + public Option(T v) + { + HasValue = true; + Value = v; + } + + public static Option None => none; + + [MemberNotNullWhen(true, nameof(Value))] + public bool HasValue { get; } + + public T? Value { get; } + } + + public class WitException: Exception { + public object Value { get; } + public uint NestingLevel { get; } + + public WitException(object v, uint level) + { + Value = v; + NestingLevel = level; + } + } + + public class WitException: WitException { + public T TypedValue { get { return (T)this.Value;} } + + public WitException(T v, uint level) : base(v!, level) + { + } + } + + public static class InteropReturnArea + { + [InlineArray(2)] + [StructLayout(LayoutKind.Sequential, Pack = 4)] + internal struct ReturnArea + { + private uint buffer; + + internal unsafe nint AddressOfReturnArea() + { + return (nint)Unsafe.AsPointer(ref buffer); + } + } + + [ThreadStatic] + [FixedAddressValueType] + internal static ReturnArea returnArea = default; + } + + namespace exports { + + public static class ComputerWorld + { + } + } + +} diff --git a/samples/calculator/Adder/generated/wit/ComputerWorld.wit.exports.example.calculator.IOperations.cs b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.exports.example.calculator.IOperations.cs new file mode 100644 index 0000000..dc52bcb --- /dev/null +++ b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.exports.example.calculator.IOperations.cs @@ -0,0 +1,14 @@ +// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! +// +#nullable enable + +namespace ComputerWorld.wit.exports.example.calculator; + +public interface IOperations { + static abstract int Add(int left, int right); + + static abstract string ToUpper(string input); + + static abstract string GetRepo(string owner, string name); + +} diff --git a/samples/calculator/Adder/generated/wit/ComputerWorld.wit.exports.example.calculator.OperationsInterop.cs b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.exports.example.calculator.OperationsInterop.cs new file mode 100644 index 0000000..c9c99c3 --- /dev/null +++ b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.exports.example.calculator.OperationsInterop.cs @@ -0,0 +1,72 @@ +// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! +// +#nullable enable + +using System.Text; +using System.Runtime.InteropServices; + +namespace ComputerWorld.wit.exports.example.calculator +{ + public static class OperationsInterop { + + [UnmanagedCallersOnly(EntryPoint = "example:calculator/operations#add")] + public static unsafe int wasmExportAdd(int p0, int p1) { + + int ret; + ret = OperationsImpl.Add((p0), (p1)); + return ret; + + } + + [UnmanagedCallersOnly(EntryPoint = "example:calculator/operations#to-upper")] + public static unsafe nint wasmExportToUpper(nint p0, int p1) { + + string ret; + ret = OperationsImpl.ToUpper((Encoding.UTF8.GetString((byte*)p0, p1))); + + var ptr = InteropReturnArea.returnArea.AddressOfReturnArea(); + + var stringSpan = ret.AsSpan(); + var length = Encoding.UTF8.GetByteCount(stringSpan); + var strPtr = NativeMemory.Alloc((nuint)length); + Encoding.UTF8.GetBytes(stringSpan, new Span(strPtr, length)); + + BitConverter.TryWriteBytes(new Span((void*)(ptr + 4), 4), length); + BitConverter.TryWriteBytes(new Span((void*)(ptr + 0), 4), (int)strPtr); + return ptr; + + } + + [UnmanagedCallersOnly(EntryPoint = "cabi_post_example:calculator/operations#to-upper")] + public static unsafe void cabi_post_wasmExportToUpper(nint p0) { + NativeMemory.Free((void*)BitConverter.ToInt32(new Span((void*)(p0 + 0), 4))); + + } + + [UnmanagedCallersOnly(EntryPoint = "example:calculator/operations#get-repo")] + public static unsafe nint wasmExportGetRepo(nint p0, int p1, nint p2, int p3) { + + string ret; + ret = OperationsImpl.GetRepo((Encoding.UTF8.GetString((byte*)p0, p1)), (Encoding.UTF8.GetString((byte*)p2, p3))); + + var ptr = InteropReturnArea.returnArea.AddressOfReturnArea(); + + var stringSpan = ret.AsSpan(); + var length = Encoding.UTF8.GetByteCount(stringSpan); + var strPtr = NativeMemory.Alloc((nuint)length); + Encoding.UTF8.GetBytes(stringSpan, new Span(strPtr, length)); + + BitConverter.TryWriteBytes(new Span((void*)(ptr + 4), 4), length); + BitConverter.TryWriteBytes(new Span((void*)(ptr + 0), 4), (int)strPtr); + return ptr; + + } + + [UnmanagedCallersOnly(EntryPoint = "cabi_post_example:calculator/operations#get-repo")] + public static unsafe void cabi_post_wasmExportGetRepo(nint p0) { + NativeMemory.Free((void*)BitConverter.ToInt32(new Span((void*)(p0 + 0), 4))); + + } + + } +} diff --git a/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop.cs b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop.cs new file mode 100644 index 0000000..a746475 --- /dev/null +++ b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop.cs @@ -0,0 +1,66 @@ +// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! +// +#nullable enable + +using System.Runtime.InteropServices; + +namespace ComputerWorld.wit.imports.wasi.clocks.v0_2_0 +{ + public static class MonotonicClockInterop { + + internal static class NowWasmInterop + { + [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "now"), WasmImportLinkage] + internal static extern long wasmImportNow(); + } + + public static unsafe ulong Now() + { + var result = NowWasmInterop.wasmImportNow(); + return unchecked((ulong)(result)); + + } + + internal static class ResolutionWasmInterop + { + [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "resolution"), WasmImportLinkage] + internal static extern long wasmImportResolution(); + } + + public static unsafe ulong Resolution() + { + var result = ResolutionWasmInterop.wasmImportResolution(); + return unchecked((ulong)(result)); + + } + + internal static class SubscribeInstantWasmInterop + { + [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "subscribe-instant"), WasmImportLinkage] + internal static extern int wasmImportSubscribeInstant(long p0); + } + + public static unsafe global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable SubscribeInstant(ulong when) + { + var result = SubscribeInstantWasmInterop.wasmImportSubscribeInstant(unchecked((long)(when))); + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result)); + return resource; + + } + + internal static class SubscribeDurationWasmInterop + { + [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "subscribe-duration"), WasmImportLinkage] + internal static extern int wasmImportSubscribeDuration(long p0); + } + + public static unsafe global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable SubscribeDuration(ulong when) + { + var result = SubscribeDurationWasmInterop.wasmImportSubscribeDuration(unchecked((long)(when))); + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result)); + return resource; + + } + + } +} diff --git a/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.cs b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.cs new file mode 100644 index 0000000..cfdc156 --- /dev/null +++ b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.cs @@ -0,0 +1,6090 @@ +// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! +// +#nullable enable + +using System.Runtime.InteropServices; +using System.Text; + +namespace ComputerWorld.wit.imports.wasi.http.v0_2_0; + +public interface ITypes { + + /** + * This type corresponds to HTTP standard Methods. + */ + + public class Method { + public readonly byte Tag; + private readonly object? value; + + private Method(byte tag, object? value) { + this.Tag = tag; + this.value = value; + } + + public static Method Get() { + return new Method(Tags.Get, null); + } + + public static Method Head() { + return new Method(Tags.Head, null); + } + + public static Method Post() { + return new Method(Tags.Post, null); + } + + public static Method Put() { + return new Method(Tags.Put, null); + } + + public static Method Delete() { + return new Method(Tags.Delete, null); + } + + public static Method Connect() { + return new Method(Tags.Connect, null); + } + + public static Method Options() { + return new Method(Tags.Options, null); + } + + public static Method Trace() { + return new Method(Tags.Trace, null); + } + + public static Method Patch() { + return new Method(Tags.Patch, null); + } + + public static Method Other(string other) { + return new Method(Tags.Other, other); + } + + public string AsOther + { + get + { + if (Tag == Tags.Other) + return (string)value!; + else + throw new ArgumentException("expected Other, got " + Tag); + } + } + + public class Tags { + public const byte Get = 0; + public const byte Head = 1; + public const byte Post = 2; + public const byte Put = 3; + public const byte Delete = 4; + public const byte Connect = 5; + public const byte Options = 6; + public const byte Trace = 7; + public const byte Patch = 8; + public const byte Other = 9; + } + } + + /** + * This type corresponds to HTTP standard Related Schemes. + */ + + public class Scheme { + public readonly byte Tag; + private readonly object? value; + + private Scheme(byte tag, object? value) { + this.Tag = tag; + this.value = value; + } + + public static Scheme Http() { + return new Scheme(Tags.Http, null); + } + + public static Scheme Https() { + return new Scheme(Tags.Https, null); + } + + public static Scheme Other(string other) { + return new Scheme(Tags.Other, other); + } + + public string AsOther + { + get + { + if (Tag == Tags.Other) + return (string)value!; + else + throw new ArgumentException("expected Other, got " + Tag); + } + } + + public class Tags { + public const byte Http = 0; + public const byte Https = 1; + public const byte Other = 2; + } + } + + /** + * Defines the case payload type for `DNS-error` above: + */ + + public class DnsErrorPayload { + public readonly string? rcode; + public readonly ushort? infoCode; + + public DnsErrorPayload(string? rcode, ushort? infoCode) { + this.rcode = rcode; + this.infoCode = infoCode; + } + } + + /** + * Defines the case payload type for `TLS-alert-received` above: + */ + + public class TlsAlertReceivedPayload { + public readonly byte? alertId; + public readonly string? alertMessage; + + public TlsAlertReceivedPayload(byte? alertId, string? alertMessage) { + this.alertId = alertId; + this.alertMessage = alertMessage; + } + } + + /** + * Defines the case payload type for `HTTP-response-{header,trailer}-size` above: + */ + + public class FieldSizePayload { + public readonly string? fieldName; + public readonly uint? fieldSize; + + public FieldSizePayload(string? fieldName, uint? fieldSize) { + this.fieldName = fieldName; + this.fieldSize = fieldSize; + } + } + + /** + * These cases are inspired by the IANA HTTP Proxy Error Types: + * https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types + */ + + public class ErrorCode { + public readonly byte Tag; + private readonly object? value; + + private ErrorCode(byte tag, object? value) { + this.Tag = tag; + this.value = value; + } + + public static ErrorCode DnsTimeout() { + return new ErrorCode(Tags.DnsTimeout, null); + } + + public static ErrorCode DnsError(DnsErrorPayload dnsError) { + return new ErrorCode(Tags.DnsError, dnsError); + } + + public static ErrorCode DestinationNotFound() { + return new ErrorCode(Tags.DestinationNotFound, null); + } + + public static ErrorCode DestinationUnavailable() { + return new ErrorCode(Tags.DestinationUnavailable, null); + } + + public static ErrorCode DestinationIpProhibited() { + return new ErrorCode(Tags.DestinationIpProhibited, null); + } + + public static ErrorCode DestinationIpUnroutable() { + return new ErrorCode(Tags.DestinationIpUnroutable, null); + } + + public static ErrorCode ConnectionRefused() { + return new ErrorCode(Tags.ConnectionRefused, null); + } + + public static ErrorCode ConnectionTerminated() { + return new ErrorCode(Tags.ConnectionTerminated, null); + } + + public static ErrorCode ConnectionTimeout() { + return new ErrorCode(Tags.ConnectionTimeout, null); + } + + public static ErrorCode ConnectionReadTimeout() { + return new ErrorCode(Tags.ConnectionReadTimeout, null); + } + + public static ErrorCode ConnectionWriteTimeout() { + return new ErrorCode(Tags.ConnectionWriteTimeout, null); + } + + public static ErrorCode ConnectionLimitReached() { + return new ErrorCode(Tags.ConnectionLimitReached, null); + } + + public static ErrorCode TlsProtocolError() { + return new ErrorCode(Tags.TlsProtocolError, null); + } + + public static ErrorCode TlsCertificateError() { + return new ErrorCode(Tags.TlsCertificateError, null); + } + + public static ErrorCode TlsAlertReceived(TlsAlertReceivedPayload tlsAlertReceived) { + return new ErrorCode(Tags.TlsAlertReceived, tlsAlertReceived); + } + + public static ErrorCode HttpRequestDenied() { + return new ErrorCode(Tags.HttpRequestDenied, null); + } + + public static ErrorCode HttpRequestLengthRequired() { + return new ErrorCode(Tags.HttpRequestLengthRequired, null); + } + + public static ErrorCode HttpRequestBodySize(ulong? httpRequestBodySize) { + return new ErrorCode(Tags.HttpRequestBodySize, httpRequestBodySize); + } + + public static ErrorCode HttpRequestMethodInvalid() { + return new ErrorCode(Tags.HttpRequestMethodInvalid, null); + } + + public static ErrorCode HttpRequestUriInvalid() { + return new ErrorCode(Tags.HttpRequestUriInvalid, null); + } + + public static ErrorCode HttpRequestUriTooLong() { + return new ErrorCode(Tags.HttpRequestUriTooLong, null); + } + + public static ErrorCode HttpRequestHeaderSectionSize(uint? httpRequestHeaderSectionSize) { + return new ErrorCode(Tags.HttpRequestHeaderSectionSize, httpRequestHeaderSectionSize); + } + + public static ErrorCode HttpRequestHeaderSize(FieldSizePayload? httpRequestHeaderSize) { + return new ErrorCode(Tags.HttpRequestHeaderSize, httpRequestHeaderSize); + } + + public static ErrorCode HttpRequestTrailerSectionSize(uint? httpRequestTrailerSectionSize) { + return new ErrorCode(Tags.HttpRequestTrailerSectionSize, httpRequestTrailerSectionSize); + } + + public static ErrorCode HttpRequestTrailerSize(FieldSizePayload httpRequestTrailerSize) { + return new ErrorCode(Tags.HttpRequestTrailerSize, httpRequestTrailerSize); + } + + public static ErrorCode HttpResponseIncomplete() { + return new ErrorCode(Tags.HttpResponseIncomplete, null); + } + + public static ErrorCode HttpResponseHeaderSectionSize(uint? httpResponseHeaderSectionSize) { + return new ErrorCode(Tags.HttpResponseHeaderSectionSize, httpResponseHeaderSectionSize); + } + + public static ErrorCode HttpResponseHeaderSize(FieldSizePayload httpResponseHeaderSize) { + return new ErrorCode(Tags.HttpResponseHeaderSize, httpResponseHeaderSize); + } + + public static ErrorCode HttpResponseBodySize(ulong? httpResponseBodySize) { + return new ErrorCode(Tags.HttpResponseBodySize, httpResponseBodySize); + } + + public static ErrorCode HttpResponseTrailerSectionSize(uint? httpResponseTrailerSectionSize) { + return new ErrorCode(Tags.HttpResponseTrailerSectionSize, httpResponseTrailerSectionSize); + } + + public static ErrorCode HttpResponseTrailerSize(FieldSizePayload httpResponseTrailerSize) { + return new ErrorCode(Tags.HttpResponseTrailerSize, httpResponseTrailerSize); + } + + public static ErrorCode HttpResponseTransferCoding(string? httpResponseTransferCoding) { + return new ErrorCode(Tags.HttpResponseTransferCoding, httpResponseTransferCoding); + } + + public static ErrorCode HttpResponseContentCoding(string? httpResponseContentCoding) { + return new ErrorCode(Tags.HttpResponseContentCoding, httpResponseContentCoding); + } + + public static ErrorCode HttpResponseTimeout() { + return new ErrorCode(Tags.HttpResponseTimeout, null); + } + + public static ErrorCode HttpUpgradeFailed() { + return new ErrorCode(Tags.HttpUpgradeFailed, null); + } + + public static ErrorCode HttpProtocolError() { + return new ErrorCode(Tags.HttpProtocolError, null); + } + + public static ErrorCode LoopDetected() { + return new ErrorCode(Tags.LoopDetected, null); + } + + public static ErrorCode ConfigurationError() { + return new ErrorCode(Tags.ConfigurationError, null); + } + + public static ErrorCode InternalError(string? internalError) { + return new ErrorCode(Tags.InternalError, internalError); + } + + public DnsErrorPayload AsDnsError + { + get + { + if (Tag == Tags.DnsError) + return (DnsErrorPayload)value!; + else + throw new ArgumentException("expected DnsError, got " + Tag); + } + } + + public TlsAlertReceivedPayload AsTlsAlertReceived + { + get + { + if (Tag == Tags.TlsAlertReceived) + return (TlsAlertReceivedPayload)value!; + else + throw new ArgumentException("expected TlsAlertReceived, got " + Tag); + } + } + + public ulong? AsHttpRequestBodySize + { + get + { + if (Tag == Tags.HttpRequestBodySize) + return (ulong?)value!; + else + throw new ArgumentException("expected HttpRequestBodySize, got " + Tag); + } + } + + public uint? AsHttpRequestHeaderSectionSize + { + get + { + if (Tag == Tags.HttpRequestHeaderSectionSize) + return (uint?)value!; + else + throw new ArgumentException("expected HttpRequestHeaderSectionSize, got " + Tag); + } + } + + public FieldSizePayload? AsHttpRequestHeaderSize + { + get + { + if (Tag == Tags.HttpRequestHeaderSize) + return (FieldSizePayload?)value!; + else + throw new ArgumentException("expected HttpRequestHeaderSize, got " + Tag); + } + } + + public uint? AsHttpRequestTrailerSectionSize + { + get + { + if (Tag == Tags.HttpRequestTrailerSectionSize) + return (uint?)value!; + else + throw new ArgumentException("expected HttpRequestTrailerSectionSize, got " + Tag); + } + } + + public FieldSizePayload AsHttpRequestTrailerSize + { + get + { + if (Tag == Tags.HttpRequestTrailerSize) + return (FieldSizePayload)value!; + else + throw new ArgumentException("expected HttpRequestTrailerSize, got " + Tag); + } + } + + public uint? AsHttpResponseHeaderSectionSize + { + get + { + if (Tag == Tags.HttpResponseHeaderSectionSize) + return (uint?)value!; + else + throw new ArgumentException("expected HttpResponseHeaderSectionSize, got " + Tag); + } + } + + public FieldSizePayload AsHttpResponseHeaderSize + { + get + { + if (Tag == Tags.HttpResponseHeaderSize) + return (FieldSizePayload)value!; + else + throw new ArgumentException("expected HttpResponseHeaderSize, got " + Tag); + } + } + + public ulong? AsHttpResponseBodySize + { + get + { + if (Tag == Tags.HttpResponseBodySize) + return (ulong?)value!; + else + throw new ArgumentException("expected HttpResponseBodySize, got " + Tag); + } + } + + public uint? AsHttpResponseTrailerSectionSize + { + get + { + if (Tag == Tags.HttpResponseTrailerSectionSize) + return (uint?)value!; + else + throw new ArgumentException("expected HttpResponseTrailerSectionSize, got " + Tag); + } + } + + public FieldSizePayload AsHttpResponseTrailerSize + { + get + { + if (Tag == Tags.HttpResponseTrailerSize) + return (FieldSizePayload)value!; + else + throw new ArgumentException("expected HttpResponseTrailerSize, got " + Tag); + } + } + + public string? AsHttpResponseTransferCoding + { + get + { + if (Tag == Tags.HttpResponseTransferCoding) + return (string?)value!; + else + throw new ArgumentException("expected HttpResponseTransferCoding, got " + Tag); + } + } + + public string? AsHttpResponseContentCoding + { + get + { + if (Tag == Tags.HttpResponseContentCoding) + return (string?)value!; + else + throw new ArgumentException("expected HttpResponseContentCoding, got " + Tag); + } + } + + public string? AsInternalError + { + get + { + if (Tag == Tags.InternalError) + return (string?)value!; + else + throw new ArgumentException("expected InternalError, got " + Tag); + } + } + + public class Tags { + public const byte DnsTimeout = 0; + public const byte DnsError = 1; + public const byte DestinationNotFound = 2; + public const byte DestinationUnavailable = 3; + public const byte DestinationIpProhibited = 4; + public const byte DestinationIpUnroutable = 5; + public const byte ConnectionRefused = 6; + public const byte ConnectionTerminated = 7; + public const byte ConnectionTimeout = 8; + public const byte ConnectionReadTimeout = 9; + public const byte ConnectionWriteTimeout = 10; + public const byte ConnectionLimitReached = 11; + public const byte TlsProtocolError = 12; + public const byte TlsCertificateError = 13; + public const byte TlsAlertReceived = 14; + public const byte HttpRequestDenied = 15; + public const byte HttpRequestLengthRequired = 16; + public const byte HttpRequestBodySize = 17; + public const byte HttpRequestMethodInvalid = 18; + public const byte HttpRequestUriInvalid = 19; + public const byte HttpRequestUriTooLong = 20; + public const byte HttpRequestHeaderSectionSize = 21; + public const byte HttpRequestHeaderSize = 22; + public const byte HttpRequestTrailerSectionSize = 23; + public const byte HttpRequestTrailerSize = 24; + public const byte HttpResponseIncomplete = 25; + public const byte HttpResponseHeaderSectionSize = 26; + public const byte HttpResponseHeaderSize = 27; + public const byte HttpResponseBodySize = 28; + public const byte HttpResponseTrailerSectionSize = 29; + public const byte HttpResponseTrailerSize = 30; + public const byte HttpResponseTransferCoding = 31; + public const byte HttpResponseContentCoding = 32; + public const byte HttpResponseTimeout = 33; + public const byte HttpUpgradeFailed = 34; + public const byte HttpProtocolError = 35; + public const byte LoopDetected = 36; + public const byte ConfigurationError = 37; + public const byte InternalError = 38; + } + } + + /** + * This type enumerates the different kinds of errors that may occur when + * setting or appending to a `fields` resource. + */ + + public class HeaderError { + public readonly byte Tag; + private readonly object? value; + + private HeaderError(byte tag, object? value) { + this.Tag = tag; + this.value = value; + } + + public static HeaderError InvalidSyntax() { + return new HeaderError(Tags.InvalidSyntax, null); + } + + public static HeaderError Forbidden() { + return new HeaderError(Tags.Forbidden, null); + } + + public static HeaderError Immutable() { + return new HeaderError(Tags.Immutable, null); + } + + public class Tags { + public const byte InvalidSyntax = 0; + public const byte Forbidden = 1; + public const byte Immutable = 2; + } + } + + /** + * 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 be + * immutable. In an immutable fields, the `set`, `append`, and `delete` + * operations will fail with `header-error.immutable`. + */ + + public class Fields: IDisposable { + internal int Handle { get; set; } + + public readonly record struct THandle(int Handle); + + public Fields(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]fields"), WasmImportLinkage] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static class ConstructorWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[constructor]fields"), WasmImportLinkage] + internal static extern int wasmImportConstructor(); + } + + public unsafe Fields() + { + var result = ConstructorWasmInterop.wasmImportConstructor(); + this.Handle = result; + + } + + internal static class FromListWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[static]fields.from-list"), WasmImportLinkage] + internal static extern void wasmImportFromList(nint p0, int p1, nint p2); + } + + public static unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields FromList(List<(string, byte[])> entries) + { + var cleanups = new List(); + + void* address; + if ((16 * entries.Count) < 1024) { + var retArea = stackalloc uint[(4*entries.Count)+1]; + address = (void*)(((int)retArea) + (4 - 1) & -4); + } + else + { + var bufferSize = 16 * (nuint)entries.Count; + address = NativeMemory.AlignedAlloc(bufferSize, 4); + cleanups.Add(() => NativeMemory.AlignedFree(address)); + } + + for (int index = 0; index < entries.Count; ++index) { + (string, byte[]) element = entries[index]; + int basePtr = (int)address + (index * 16); + + var utf8Bytes = Encoding.UTF8.GetBytes(element.Item1); + var length = utf8Bytes.Length; + var gcHandle = GCHandle.Alloc(utf8Bytes, GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + BitConverter.TryWriteBytes(new Span((void*)(basePtr + 4), 4), length); + BitConverter.TryWriteBytes(new Span((void*)(basePtr + 0), 4), strPtr.ToInt32()); + + var gcHandle0 = GCHandle.Alloc(element.Item2, GCHandleType.Pinned); + var listPtr = gcHandle0.AddrOfPinnedObject(); + cleanups.Add(()=> gcHandle0.Free()); + BitConverter.TryWriteBytes(new Span((void*)(basePtr + 12), 4), (element.Item2).Length); + BitConverter.TryWriteBytes(new Span((void*)(basePtr + 8), 4), (nint)listPtr); + + } + + var retArea1 = stackalloc uint[2+1]; + var ptr = ((int)retArea1) + (4 - 1) & -4; + FromListWasmInterop.wasmImportFromList((int)address, entries.Count, ptr); + + Result lifted12; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)))); + + lifted12 = Result.Ok(resource); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError lifted; + + switch (new Span((void*)(ptr + 4), 1)[0]) { + case 0: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.InvalidSyntax(); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.Forbidden(); + break; + } + case 2: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.Immutable(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); + } + + lifted12 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + if (lifted12.IsOk) + { + var tmp = lifted12.AsOk; + return tmp; + } + else + { + throw new WitException(lifted12.AsErr!, 0); + } + + } + + internal static class GetWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]fields.get"), WasmImportLinkage] + internal static extern void wasmImportGet(int p0, nint p1, int p2, nint p3); + } + + public unsafe List Get(string name) + { + var cleanups = new List(); + var handle = this.Handle; + + var utf8Bytes = Encoding.UTF8.GetBytes(name); + var length = utf8Bytes.Length; + var gcHandle = GCHandle.Alloc(utf8Bytes, GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + var retArea = stackalloc uint[2+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + GetWasmInterop.wasmImportGet(handle, strPtr.ToInt32(), length, ptr); + + var array0 = new List(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4))); + for (int index = 0; index < BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)); ++index) { + nint basePtr = BitConverter.ToInt32(new Span((void*)(ptr + 0), 4)) + (index * 8); + + var array = new byte[BitConverter.ToInt32(new Span((void*)(basePtr + 4), 4))]; + new Span((void*)(BitConverter.ToInt32(new Span((void*)(basePtr + 0), 4))), BitConverter.ToInt32(new Span((void*)(basePtr + 4), 4))).CopyTo(new Span(array)); + + array0.Add(array); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + return array0; + + } + + internal static class HasWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]fields.has"), WasmImportLinkage] + internal static extern int wasmImportHas(int p0, nint p1, int p2); + } + + public unsafe bool Has(string name) + { + var cleanups = new List(); + var handle = this.Handle; + + var utf8Bytes = Encoding.UTF8.GetBytes(name); + var length = utf8Bytes.Length; + var gcHandle = GCHandle.Alloc(utf8Bytes, GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + var result = HasWasmInterop.wasmImportHas(handle, strPtr.ToInt32(), length); + + foreach (var cleanup in cleanups) + { + cleanup(); + } + return (result != 0); + + } + + internal static class SetWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]fields.set"), WasmImportLinkage] + internal static extern void wasmImportSet(int p0, nint p1, int p2, nint p3, int p4, nint p5); + } + + public unsafe void Set(string name, List value) + { + var cleanups = new List(); + var handle = this.Handle; + + var utf8Bytes = Encoding.UTF8.GetBytes(name); + var length = utf8Bytes.Length; + var gcHandle = GCHandle.Alloc(utf8Bytes, GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + void* address; + if ((8 * value.Count) < 1024) { + var retArea = stackalloc uint[(2*value.Count)+1]; + address = (void*)(((int)retArea) + (4 - 1) & -4); + } + else + { + var bufferSize = 8 * (nuint)value.Count; + address = NativeMemory.AlignedAlloc(bufferSize, 4); + cleanups.Add(() => NativeMemory.AlignedFree(address)); + } + + for (int index = 0; index < value.Count; ++index) { + byte[] element = value[index]; + int basePtr = (int)address + (index * 8); + + var gcHandle0 = GCHandle.Alloc(element, GCHandleType.Pinned); + var listPtr = gcHandle0.AddrOfPinnedObject(); + cleanups.Add(()=> gcHandle0.Free()); + BitConverter.TryWriteBytes(new Span((void*)(basePtr + 4), 4), (element).Length); + BitConverter.TryWriteBytes(new Span((void*)(basePtr + 0), 4), (nint)listPtr); + + } + + var retArea1 = stackalloc byte[2+1]; + var ptr = ((int)retArea1) + (1 - 1) & -1; + SetWasmInterop.wasmImportSet(handle, strPtr.ToInt32(), length, (int)address, value.Count, ptr); + + Result lifted12; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted12 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError lifted; + + switch (new Span((void*)(ptr + 1), 1)[0]) { + case 0: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.InvalidSyntax(); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.Forbidden(); + break; + } + case 2: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.Immutable(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 1), 1)[0]}"); + } + + lifted12 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + if (lifted12.IsOk) + { + var tmp = lifted12.AsOk; + return ; + } + else + { + throw new WitException(lifted12.AsErr!, 0); + } + + } + + internal static class DeleteWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]fields.delete"), WasmImportLinkage] + internal static extern void wasmImportDelete(int p0, nint p1, int p2, nint p3); + } + + public unsafe void Delete(string name) + { + var cleanups = new List(); + var handle = this.Handle; + + var utf8Bytes = Encoding.UTF8.GetBytes(name); + var length = utf8Bytes.Length; + var gcHandle = GCHandle.Alloc(utf8Bytes, GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + var retArea = stackalloc byte[2+1]; + var ptr = ((int)retArea) + (1 - 1) & -1; + DeleteWasmInterop.wasmImportDelete(handle, strPtr.ToInt32(), length, ptr); + + Result lifted8; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted8 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError lifted; + + switch (new Span((void*)(ptr + 1), 1)[0]) { + case 0: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.InvalidSyntax(); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.Forbidden(); + break; + } + case 2: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.Immutable(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 1), 1)[0]}"); + } + + lifted8 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + if (lifted8.IsOk) + { + var tmp = lifted8.AsOk; + return ; + } + else + { + throw new WitException(lifted8.AsErr!, 0); + } + + } + + internal static class AppendWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]fields.append"), WasmImportLinkage] + internal static extern void wasmImportAppend(int p0, nint p1, int p2, nint p3, int p4, nint p5); + } + + public unsafe void Append(string name, byte[] value) + { + var cleanups = new List(); + var handle = this.Handle; + + var utf8Bytes = Encoding.UTF8.GetBytes(name); + var length = utf8Bytes.Length; + var gcHandle = GCHandle.Alloc(utf8Bytes, GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + var gcHandle0 = GCHandle.Alloc(value, GCHandleType.Pinned); + var listPtr = gcHandle0.AddrOfPinnedObject(); + cleanups.Add(()=> gcHandle0.Free()); + + var retArea = stackalloc byte[2+1]; + var ptr = ((int)retArea) + (1 - 1) & -1; + AppendWasmInterop.wasmImportAppend(handle, strPtr.ToInt32(), length, (nint)listPtr, (value).Length, ptr); + + Result lifted9; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted9 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError lifted; + + switch (new Span((void*)(ptr + 1), 1)[0]) { + case 0: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.InvalidSyntax(); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.Forbidden(); + break; + } + case 2: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.Immutable(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 1), 1)[0]}"); + } + + lifted9 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + if (lifted9.IsOk) + { + var tmp = lifted9.AsOk; + return ; + } + else + { + throw new WitException(lifted9.AsErr!, 0); + } + + } + + public unsafe void Append(string name, Span value) + { + var cleanups = new List(); + fixed (void* listPtr = value) + { + var handle = this.Handle; + + var utf8Bytes = Encoding.UTF8.GetBytes(name); + var length = utf8Bytes.Length; + var gcHandle = GCHandle.Alloc(utf8Bytes, GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + var retArea = stackalloc byte[2+1]; + var ptr = ((int)retArea) + (1 - 1) & -1; + AppendWasmInterop.wasmImportAppend(handle, strPtr.ToInt32(), length, (nint)listPtr, (value).Length, ptr); + + Result lifted9; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted9 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError lifted; + + switch (new Span((void*)(ptr + 1), 1)[0]) { + case 0: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.InvalidSyntax(); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.Forbidden(); + break; + } + case 2: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.Immutable(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 1), 1)[0]}"); + } + + lifted9 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + if (lifted9.IsOk) + { + var tmp = lifted9.AsOk; + return ; + } + else + { + throw new WitException(lifted9.AsErr!, 0); + } + } + + } + + public unsafe void Append(string name, Memory value) + { + var cleanups = new List(); + fixed (void* listPtr = value.Span) + { + var handle = this.Handle; + + var utf8Bytes = Encoding.UTF8.GetBytes(name); + var length = utf8Bytes.Length; + var gcHandle = GCHandle.Alloc(utf8Bytes, GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + var retArea = stackalloc byte[2+1]; + var ptr = ((int)retArea) + (1 - 1) & -1; + AppendWasmInterop.wasmImportAppend(handle, strPtr.ToInt32(), length, (nint)listPtr, (value).Length, ptr); + + Result lifted9; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted9 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError lifted; + + switch (new Span((void*)(ptr + 1), 1)[0]) { + case 0: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.InvalidSyntax(); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.Forbidden(); + break; + } + case 2: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.Immutable(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 1), 1)[0]}"); + } + + lifted9 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + if (lifted9.IsOk) + { + var tmp = lifted9.AsOk; + return ; + } + else + { + throw new WitException(lifted9.AsErr!, 0); + } + } + + } + + internal static class EntriesWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]fields.entries"), WasmImportLinkage] + internal static extern void wasmImportEntries(int p0, nint p1); + } + + public unsafe List<(string, byte[])> Entries() + { + var handle = this.Handle; + + var retArea = stackalloc uint[2+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + EntriesWasmInterop.wasmImportEntries(handle, ptr); + + var array0 = new List<(string, byte[])>(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4))); + for (int index = 0; index < BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)); ++index) { + nint basePtr = BitConverter.ToInt32(new Span((void*)(ptr + 0), 4)) + (index * 16); + + var array = new byte[BitConverter.ToInt32(new Span((void*)(basePtr + 12), 4))]; + new Span((void*)(BitConverter.ToInt32(new Span((void*)(basePtr + 8), 4))), BitConverter.ToInt32(new Span((void*)(basePtr + 12), 4))).CopyTo(new Span(array)); + + array0.Add((Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(basePtr + 0), 4)), BitConverter.ToInt32(new Span((void*)(basePtr + 4), 4))), array)); + } + return array0; + + } + + internal static class CloneWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]fields.clone"), WasmImportLinkage] + internal static extern int wasmImportClone(int p0); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields Clone() + { + var handle = this.Handle; + var result = CloneWasmInterop.wasmImportClone(handle); + var resource = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(result)); + return resource; + + } + + } + + /** + * Represents an incoming HTTP Request. + */ + + public class IncomingRequest: IDisposable { + internal int Handle { get; set; } + + public readonly record struct THandle(int Handle); + + public IncomingRequest(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]incoming-request"), WasmImportLinkage] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static class MethodWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-request.method"), WasmImportLinkage] + internal static extern void wasmImportMethod(int p0, nint p1); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method Method() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + MethodWasmInterop.wasmImportMethod(handle, ptr); + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method lifted; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Get(); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Head(); + break; + } + case 2: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Post(); + break; + } + case 3: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Put(); + break; + } + case 4: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Delete(); + break; + } + case 5: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Connect(); + break; + } + case 6: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Options(); + break; + } + case 7: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Trace(); + break; + } + case 8: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Patch(); + break; + } + case 9: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Other(Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + return lifted; + + } + + internal static class PathWithQueryWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-request.path-with-query"), WasmImportLinkage] + internal static extern void wasmImportPathWithQuery(int p0, nint p1); + } + + public unsafe string? PathWithQuery() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + PathWithQueryWasmInterop.wasmImportPathWithQuery(handle, ptr); + + string? lifted; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + lifted = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 8), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0])); + } + return lifted; + + } + + internal static class SchemeWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-request.scheme"), WasmImportLinkage] + internal static extern void wasmImportScheme(int p0, nint p1); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme? Scheme() + { + var handle = this.Handle; + + var retArea = stackalloc uint[4+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + SchemeWasmInterop.wasmImportScheme(handle, ptr); + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme? lifted8; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + lifted8 = null; + break; + } + + case 1: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme lifted; + + switch (new Span((void*)(ptr + 4), 1)[0]) { + case 0: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.Http(); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.Https(); + break; + } + case 2: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.Other(Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 12), 4)))); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); + } + + lifted8 = lifted; + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0])); + } + return lifted8; + + } + + internal static class AuthorityWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-request.authority"), WasmImportLinkage] + internal static extern void wasmImportAuthority(int p0, nint p1); + } + + public unsafe string? Authority() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + AuthorityWasmInterop.wasmImportAuthority(handle, ptr); + + string? lifted; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + lifted = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 8), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0])); + } + return lifted; + + } + + internal static class HeadersWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-request.headers"), WasmImportLinkage] + internal static extern int wasmImportHeaders(int p0); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields Headers() + { + var handle = this.Handle; + var result = HeadersWasmInterop.wasmImportHeaders(handle); + var resource = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(result)); + return resource; + + } + + internal static class ConsumeWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-request.consume"), WasmImportLinkage] + internal static extern void wasmImportConsume(int p0, nint p1); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody Consume() + { + var handle = this.Handle; + + var retArea = stackalloc uint[2+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + ConsumeWasmInterop.wasmImportConsume(handle, ptr); + + Result lifted; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)))); + + lifted = Result.Ok(resource); + break; + } + case 1: { + + lifted = Result.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return tmp; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + } + + /** + * Represents an outgoing HTTP Request. + */ + + public class OutgoingRequest: IDisposable { + internal int Handle { get; set; } + + public readonly record struct THandle(int Handle); + + public OutgoingRequest(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]outgoing-request"), WasmImportLinkage] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static class ConstructorWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[constructor]outgoing-request"), WasmImportLinkage] + internal static extern int wasmImportConstructor(int p0); + } + + public unsafe OutgoingRequest(global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields headers) + { + var handle = headers.Handle; + headers.Handle = 0; + var result = ConstructorWasmInterop.wasmImportConstructor(handle); + this.Handle = result; + + } + + internal static class BodyWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.body"), WasmImportLinkage] + internal static extern void wasmImportBody(int p0, nint p1); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingBody Body() + { + var handle = this.Handle; + + var retArea = stackalloc uint[2+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + BodyWasmInterop.wasmImportBody(handle, ptr); + + Result lifted; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingBody(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingBody.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)))); + + lifted = Result.Ok(resource); + break; + } + case 1: { + + lifted = Result.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return tmp; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal static class MethodWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.method"), WasmImportLinkage] + internal static extern void wasmImportMethod(int p0, nint p1); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method Method() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + MethodWasmInterop.wasmImportMethod(handle, ptr); + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method lifted; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Get(); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Head(); + break; + } + case 2: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Post(); + break; + } + case 3: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Put(); + break; + } + case 4: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Delete(); + break; + } + case 5: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Connect(); + break; + } + case 6: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Options(); + break; + } + case 7: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Trace(); + break; + } + case 8: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Patch(); + break; + } + case 9: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.Other(Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + return lifted; + + } + + internal static class SetMethodWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.set-method"), WasmImportLinkage] + internal static extern int wasmImportSetMethod(int p0, int p1, nint p2, int p3); + } + + public unsafe void SetMethod(global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method method) + { + var cleanups = new List(); + var handle = this.Handle; + + int lowered; + nint lowered27; + int lowered28; + + switch (method.Tag) { + case 0: { + + lowered = 0; + lowered27 = 0; + lowered28 = 0; + + break; + } + case 1: { + + lowered = 1; + lowered27 = 0; + lowered28 = 0; + + break; + } + case 2: { + + lowered = 2; + lowered27 = 0; + lowered28 = 0; + + break; + } + case 3: { + + lowered = 3; + lowered27 = 0; + lowered28 = 0; + + break; + } + case 4: { + + lowered = 4; + lowered27 = 0; + lowered28 = 0; + + break; + } + case 5: { + + lowered = 5; + lowered27 = 0; + lowered28 = 0; + + break; + } + case 6: { + + lowered = 6; + lowered27 = 0; + lowered28 = 0; + + break; + } + case 7: { + + lowered = 7; + lowered27 = 0; + lowered28 = 0; + + break; + } + case 8: { + + lowered = 8; + lowered27 = 0; + lowered28 = 0; + + break; + } + case 9: { + string payload26 = method.AsOther; + + var utf8Bytes = Encoding.UTF8.GetBytes(payload26); + var length = utf8Bytes.Length; + var gcHandle = GCHandle.Alloc(utf8Bytes, GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + lowered = 9; + lowered27 = strPtr.ToInt32(); + lowered28 = length; + + break; + } + + default: throw new ArgumentException($"invalid discriminant: {method}"); + } + var result = SetMethodWasmInterop.wasmImportSetMethod(handle, lowered, lowered27, lowered28); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {result}"); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return ; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal static class PathWithQueryWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.path-with-query"), WasmImportLinkage] + internal static extern void wasmImportPathWithQuery(int p0, nint p1); + } + + public unsafe string? PathWithQuery() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + PathWithQueryWasmInterop.wasmImportPathWithQuery(handle, ptr); + + string? lifted; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + lifted = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 8), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0])); + } + return lifted; + + } + + internal static class SetPathWithQueryWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.set-path-with-query"), WasmImportLinkage] + internal static extern int wasmImportSetPathWithQuery(int p0, int p1, nint p2, int p3); + } + + public unsafe void SetPathWithQuery(string? pathWithQuery) + { + var cleanups = new List(); + var handle = this.Handle; + + int lowered; + nint lowered3; + int lowered4; + + if (pathWithQuery != null) { + var payload2 = (string) pathWithQuery; + + var utf8Bytes = Encoding.UTF8.GetBytes(payload2); + var length = utf8Bytes.Length; + var gcHandle = GCHandle.Alloc(utf8Bytes, GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + lowered = 1; + lowered3 = strPtr.ToInt32(); + lowered4 = length; + + } else { + + lowered = 0; + lowered3 = 0; + lowered4 = 0; + + } + var result = SetPathWithQueryWasmInterop.wasmImportSetPathWithQuery(handle, lowered, lowered3, lowered4); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {result}"); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return ; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal static class SchemeWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.scheme"), WasmImportLinkage] + internal static extern void wasmImportScheme(int p0, nint p1); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme? Scheme() + { + var handle = this.Handle; + + var retArea = stackalloc uint[4+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + SchemeWasmInterop.wasmImportScheme(handle, ptr); + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme? lifted8; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + lifted8 = null; + break; + } + + case 1: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme lifted; + + switch (new Span((void*)(ptr + 4), 1)[0]) { + case 0: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.Http(); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.Https(); + break; + } + case 2: { + + lifted = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.Other(Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 12), 4)))); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); + } + + lifted8 = lifted; + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0])); + } + return lifted8; + + } + + internal static class SetSchemeWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.set-scheme"), WasmImportLinkage] + internal static extern int wasmImportSetScheme(int p0, int p1, int p2, nint p3, int p4); + } + + public unsafe void SetScheme(global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme? scheme) + { + var cleanups = new List(); + var handle = this.Handle; + + int lowered14; + int lowered15; + nint lowered16; + int lowered17; + + if (scheme != null) { + var payload2 = (global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme) scheme; + + int lowered; + nint lowered12; + int lowered13; + + switch (payload2.Tag) { + case 0: { + + lowered = 0; + lowered12 = 0; + lowered13 = 0; + + break; + } + case 1: { + + lowered = 1; + lowered12 = 0; + lowered13 = 0; + + break; + } + case 2: { + string payload11 = payload2.AsOther; + + var utf8Bytes = Encoding.UTF8.GetBytes(payload11); + var length = utf8Bytes.Length; + var gcHandle = GCHandle.Alloc(utf8Bytes, GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + lowered = 2; + lowered12 = strPtr.ToInt32(); + lowered13 = length; + + break; + } + + default: throw new ArgumentException($"invalid discriminant: {payload2}"); + } + + lowered14 = 1; + lowered15 = lowered; + lowered16 = lowered12; + lowered17 = lowered13; + + } else { + + lowered14 = 0; + lowered15 = 0; + lowered16 = 0; + lowered17 = 0; + + } + var result = SetSchemeWasmInterop.wasmImportSetScheme(handle, lowered14, lowered15, lowered16, lowered17); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {result}"); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return ; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal static class AuthorityWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.authority"), WasmImportLinkage] + internal static extern void wasmImportAuthority(int p0, nint p1); + } + + public unsafe string? Authority() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + AuthorityWasmInterop.wasmImportAuthority(handle, ptr); + + string? lifted; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + lifted = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 8), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0])); + } + return lifted; + + } + + internal static class SetAuthorityWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.set-authority"), WasmImportLinkage] + internal static extern int wasmImportSetAuthority(int p0, int p1, nint p2, int p3); + } + + public unsafe void SetAuthority(string? authority) + { + var cleanups = new List(); + var handle = this.Handle; + + int lowered; + nint lowered3; + int lowered4; + + if (authority != null) { + var payload2 = (string) authority; + + var utf8Bytes = Encoding.UTF8.GetBytes(payload2); + var length = utf8Bytes.Length; + var gcHandle = GCHandle.Alloc(utf8Bytes, GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + lowered = 1; + lowered3 = strPtr.ToInt32(); + lowered4 = length; + + } else { + + lowered = 0; + lowered3 = 0; + lowered4 = 0; + + } + var result = SetAuthorityWasmInterop.wasmImportSetAuthority(handle, lowered, lowered3, lowered4); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {result}"); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return ; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal static class HeadersWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.headers"), WasmImportLinkage] + internal static extern int wasmImportHeaders(int p0); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields Headers() + { + var handle = this.Handle; + var result = HeadersWasmInterop.wasmImportHeaders(handle); + var resource = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(result)); + return resource; + + } + + } + + /** + * 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`. + */ + + public class RequestOptions: IDisposable { + internal int Handle { get; set; } + + public readonly record struct THandle(int Handle); + + public RequestOptions(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]request-options"), WasmImportLinkage] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static class ConstructorWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[constructor]request-options"), WasmImportLinkage] + internal static extern int wasmImportConstructor(); + } + + public unsafe RequestOptions() + { + var result = ConstructorWasmInterop.wasmImportConstructor(); + this.Handle = result; + + } + + internal static class ConnectTimeoutWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]request-options.connect-timeout"), WasmImportLinkage] + internal static extern void wasmImportConnectTimeout(int p0, nint p1); + } + + public unsafe ulong? ConnectTimeout() + { + var handle = this.Handle; + + var retArea = stackalloc ulong[2+1]; + var ptr = ((int)retArea) + (8 - 1) & -8; + ConnectTimeoutWasmInterop.wasmImportConnectTimeout(handle, ptr); + + ulong? lifted; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + lifted = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 8), 8)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0])); + } + return lifted; + + } + + internal static class SetConnectTimeoutWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]request-options.set-connect-timeout"), WasmImportLinkage] + internal static extern int wasmImportSetConnectTimeout(int p0, int p1, long p2); + } + + public unsafe void SetConnectTimeout(ulong? duration) + { + var handle = this.Handle; + + int lowered; + long lowered3; + + if (duration != null) { + var payload2 = (ulong) duration; + + lowered = 1; + lowered3 = unchecked((long)(payload2)); + + } else { + + lowered = 0; + lowered3 = 0L; + + } + var result = SetConnectTimeoutWasmInterop.wasmImportSetConnectTimeout(handle, lowered, lowered3); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {result}"); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return ; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal static class FirstByteTimeoutWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]request-options.first-byte-timeout"), WasmImportLinkage] + internal static extern void wasmImportFirstByteTimeout(int p0, nint p1); + } + + public unsafe ulong? FirstByteTimeout() + { + var handle = this.Handle; + + var retArea = stackalloc ulong[2+1]; + var ptr = ((int)retArea) + (8 - 1) & -8; + FirstByteTimeoutWasmInterop.wasmImportFirstByteTimeout(handle, ptr); + + ulong? lifted; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + lifted = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 8), 8)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0])); + } + return lifted; + + } + + internal static class SetFirstByteTimeoutWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]request-options.set-first-byte-timeout"), WasmImportLinkage] + internal static extern int wasmImportSetFirstByteTimeout(int p0, int p1, long p2); + } + + public unsafe void SetFirstByteTimeout(ulong? duration) + { + var handle = this.Handle; + + int lowered; + long lowered3; + + if (duration != null) { + var payload2 = (ulong) duration; + + lowered = 1; + lowered3 = unchecked((long)(payload2)); + + } else { + + lowered = 0; + lowered3 = 0L; + + } + var result = SetFirstByteTimeoutWasmInterop.wasmImportSetFirstByteTimeout(handle, lowered, lowered3); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {result}"); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return ; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal static class BetweenBytesTimeoutWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]request-options.between-bytes-timeout"), WasmImportLinkage] + internal static extern void wasmImportBetweenBytesTimeout(int p0, nint p1); + } + + public unsafe ulong? BetweenBytesTimeout() + { + var handle = this.Handle; + + var retArea = stackalloc ulong[2+1]; + var ptr = ((int)retArea) + (8 - 1) & -8; + BetweenBytesTimeoutWasmInterop.wasmImportBetweenBytesTimeout(handle, ptr); + + ulong? lifted; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + lifted = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 8), 8)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0])); + } + return lifted; + + } + + internal static class SetBetweenBytesTimeoutWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]request-options.set-between-bytes-timeout"), WasmImportLinkage] + internal static extern int wasmImportSetBetweenBytesTimeout(int p0, int p1, long p2); + } + + public unsafe void SetBetweenBytesTimeout(ulong? duration) + { + var handle = this.Handle; + + int lowered; + long lowered3; + + if (duration != null) { + var payload2 = (ulong) duration; + + lowered = 1; + lowered3 = unchecked((long)(payload2)); + + } else { + + lowered = 0; + lowered3 = 0L; + + } + var result = SetBetweenBytesTimeoutWasmInterop.wasmImportSetBetweenBytesTimeout(handle, lowered, lowered3); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {result}"); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return ; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + } + + /** + * 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`. + */ + + public class ResponseOutparam: IDisposable { + internal int Handle { get; set; } + + public readonly record struct THandle(int Handle); + + public ResponseOutparam(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]response-outparam"), WasmImportLinkage] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static class SetWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[static]response-outparam.set"), WasmImportLinkage] + internal static extern void wasmImportSet(int p0, int p1, int p2, int p3, long p4, nint p5, nint p6, int p7, int p8); + } + + public static unsafe void Set(global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ResponseOutparam param, Result response) + { + var cleanups = new List(); + var handle = param.Handle; + param.Handle = 0; + + int lowered348; + int lowered349; + int lowered350; + long lowered351; + nint lowered352; + nint lowered353; + int lowered354; + int lowered355; + + switch (response.Tag) { + case 0: { + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingResponse payload = response.AsOk; + var handle0 = payload.Handle; + payload.Handle = 0; + + lowered348 = 0; + lowered349 = handle0; + lowered350 = 0; + lowered351 = 0L; + lowered352 = 0; + lowered353 = 0; + lowered354 = 0; + lowered355 = 0; + + break; + } + case 1: { + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode payload3 = response.AsErr; + + int lowered341; + int lowered342; + long lowered343; + nint lowered344; + nint lowered345; + int lowered346; + int lowered347; + + switch (payload3.Tag) { + case 0: { + + lowered341 = 0; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 1: { + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.DnsErrorPayload payload9 = payload3.AsDnsError; + + int lowered; + nint lowered16; + int lowered17; + + if (payload9.rcode != null) { + var payload15 = (string) payload9.rcode; + + var utf8Bytes = Encoding.UTF8.GetBytes(payload15); + var length = utf8Bytes.Length; + var gcHandle = GCHandle.Alloc(utf8Bytes, GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + lowered = 1; + lowered16 = strPtr.ToInt32(); + lowered17 = length; + + } else { + + lowered = 0; + lowered16 = 0; + lowered17 = 0; + + } + + int lowered24; + int lowered25; + + if (payload9.infoCode != null) { + var payload23 = (ushort) payload9.infoCode; + + lowered24 = 1; + lowered25 = payload23; + + } else { + + lowered24 = 0; + lowered25 = 0; + + } + + lowered341 = 1; + lowered342 = lowered; + lowered343 = (long) (lowered16); + lowered344 = lowered17; + lowered345 = lowered24; + lowered346 = lowered25; + lowered347 = 0; + + break; + } + case 2: { + + lowered341 = 2; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 3: { + + lowered341 = 3; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 4: { + + lowered341 = 4; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 5: { + + lowered341 = 5; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 6: { + + lowered341 = 6; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 7: { + + lowered341 = 7; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 8: { + + lowered341 = 8; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 9: { + + lowered341 = 9; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 10: { + + lowered341 = 10; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 11: { + + lowered341 = 11; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 12: { + + lowered341 = 12; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 13: { + + lowered341 = 13; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 14: { + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.TlsAlertReceivedPayload payload64 = payload3.AsTlsAlertReceived; + + int lowered71; + int lowered72; + + if (payload64.alertId != null) { + var payload70 = (byte) payload64.alertId; + + lowered71 = 1; + lowered72 = payload70; + + } else { + + lowered71 = 0; + lowered72 = 0; + + } + + int lowered83; + nint lowered84; + int lowered85; + + if (payload64.alertMessage != null) { + var payload78 = (string) payload64.alertMessage; + + var utf8Bytes80 = Encoding.UTF8.GetBytes(payload78); + var length81 = utf8Bytes80.Length; + var gcHandle82 = GCHandle.Alloc(utf8Bytes80, GCHandleType.Pinned); + var strPtr79 = gcHandle82.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle82.Free()); + + lowered83 = 1; + lowered84 = strPtr79.ToInt32(); + lowered85 = length81; + + } else { + + lowered83 = 0; + lowered84 = 0; + lowered85 = 0; + + } + + lowered341 = 14; + lowered342 = lowered71; + lowered343 = (long) (lowered72); + lowered344 = lowered83; + lowered345 = lowered84; + lowered346 = lowered85; + lowered347 = 0; + + break; + } + case 15: { + + lowered341 = 15; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 16: { + + lowered341 = 16; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 17: { + ulong? payload94 = payload3.AsHttpRequestBodySize; + + int lowered101; + long lowered102; + + if (payload94 != null) { + var payload100 = (ulong) payload94; + + lowered101 = 1; + lowered102 = unchecked((long)(payload100)); + + } else { + + lowered101 = 0; + lowered102 = 0L; + + } + + lowered341 = 17; + lowered342 = lowered101; + lowered343 = lowered102; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 18: { + + lowered341 = 18; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 19: { + + lowered341 = 19; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 20: { + + lowered341 = 20; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 21: { + uint? payload114 = payload3.AsHttpRequestHeaderSectionSize; + + int lowered121; + int lowered122; + + if (payload114 != null) { + var payload120 = (uint) payload114; + + lowered121 = 1; + lowered122 = unchecked((int)(payload120)); + + } else { + + lowered121 = 0; + lowered122 = 0; + + } + + lowered341 = 21; + lowered342 = lowered121; + lowered343 = (long) (lowered122); + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 22: { + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload? payload125 = payload3.AsHttpRequestHeaderSize; + + int lowered153; + int lowered154; + nint lowered155; + int lowered156; + int lowered157; + int lowered158; + + if (payload125 != null) { + var payload131 = (global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload) payload125; + + int lowered142; + nint lowered143; + int lowered144; + + if (payload131.fieldName != null) { + var payload137 = (string) payload131.fieldName; + + var utf8Bytes139 = Encoding.UTF8.GetBytes(payload137); + var length140 = utf8Bytes139.Length; + var gcHandle141 = GCHandle.Alloc(utf8Bytes139, GCHandleType.Pinned); + var strPtr138 = gcHandle141.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle141.Free()); + + lowered142 = 1; + lowered143 = strPtr138.ToInt32(); + lowered144 = length140; + + } else { + + lowered142 = 0; + lowered143 = 0; + lowered144 = 0; + + } + + int lowered151; + int lowered152; + + if (payload131.fieldSize != null) { + var payload150 = (uint) payload131.fieldSize; + + lowered151 = 1; + lowered152 = unchecked((int)(payload150)); + + } else { + + lowered151 = 0; + lowered152 = 0; + + } + + lowered153 = 1; + lowered154 = lowered142; + lowered155 = lowered143; + lowered156 = lowered144; + lowered157 = lowered151; + lowered158 = lowered152; + + } else { + + lowered153 = 0; + lowered154 = 0; + lowered155 = 0; + lowered156 = 0; + lowered157 = 0; + lowered158 = 0; + + } + + lowered341 = 22; + lowered342 = lowered153; + lowered343 = (long) (lowered154); + lowered344 = lowered155; + lowered345 = lowered156; + lowered346 = lowered157; + lowered347 = lowered158; + + break; + } + case 23: { + uint? payload161 = payload3.AsHttpRequestTrailerSectionSize; + + int lowered168; + int lowered169; + + if (payload161 != null) { + var payload167 = (uint) payload161; + + lowered168 = 1; + lowered169 = unchecked((int)(payload167)); + + } else { + + lowered168 = 0; + lowered169 = 0; + + } + + lowered341 = 23; + lowered342 = lowered168; + lowered343 = (long) (lowered169); + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 24: { + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload payload172 = payload3.AsHttpRequestTrailerSize; + + int lowered183; + nint lowered184; + int lowered185; + + if (payload172.fieldName != null) { + var payload178 = (string) payload172.fieldName; + + var utf8Bytes180 = Encoding.UTF8.GetBytes(payload178); + var length181 = utf8Bytes180.Length; + var gcHandle182 = GCHandle.Alloc(utf8Bytes180, GCHandleType.Pinned); + var strPtr179 = gcHandle182.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle182.Free()); + + lowered183 = 1; + lowered184 = strPtr179.ToInt32(); + lowered185 = length181; + + } else { + + lowered183 = 0; + lowered184 = 0; + lowered185 = 0; + + } + + int lowered192; + int lowered193; + + if (payload172.fieldSize != null) { + var payload191 = (uint) payload172.fieldSize; + + lowered192 = 1; + lowered193 = unchecked((int)(payload191)); + + } else { + + lowered192 = 0; + lowered193 = 0; + + } + + lowered341 = 24; + lowered342 = lowered183; + lowered343 = (long) (lowered184); + lowered344 = lowered185; + lowered345 = lowered192; + lowered346 = lowered193; + lowered347 = 0; + + break; + } + case 25: { + + lowered341 = 25; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 26: { + uint? payload199 = payload3.AsHttpResponseHeaderSectionSize; + + int lowered206; + int lowered207; + + if (payload199 != null) { + var payload205 = (uint) payload199; + + lowered206 = 1; + lowered207 = unchecked((int)(payload205)); + + } else { + + lowered206 = 0; + lowered207 = 0; + + } + + lowered341 = 26; + lowered342 = lowered206; + lowered343 = (long) (lowered207); + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 27: { + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload payload210 = payload3.AsHttpResponseHeaderSize; + + int lowered221; + nint lowered222; + int lowered223; + + if (payload210.fieldName != null) { + var payload216 = (string) payload210.fieldName; + + var utf8Bytes218 = Encoding.UTF8.GetBytes(payload216); + var length219 = utf8Bytes218.Length; + var gcHandle220 = GCHandle.Alloc(utf8Bytes218, GCHandleType.Pinned); + var strPtr217 = gcHandle220.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle220.Free()); + + lowered221 = 1; + lowered222 = strPtr217.ToInt32(); + lowered223 = length219; + + } else { + + lowered221 = 0; + lowered222 = 0; + lowered223 = 0; + + } + + int lowered230; + int lowered231; + + if (payload210.fieldSize != null) { + var payload229 = (uint) payload210.fieldSize; + + lowered230 = 1; + lowered231 = unchecked((int)(payload229)); + + } else { + + lowered230 = 0; + lowered231 = 0; + + } + + lowered341 = 27; + lowered342 = lowered221; + lowered343 = (long) (lowered222); + lowered344 = lowered223; + lowered345 = lowered230; + lowered346 = lowered231; + lowered347 = 0; + + break; + } + case 28: { + ulong? payload234 = payload3.AsHttpResponseBodySize; + + int lowered241; + long lowered242; + + if (payload234 != null) { + var payload240 = (ulong) payload234; + + lowered241 = 1; + lowered242 = unchecked((long)(payload240)); + + } else { + + lowered241 = 0; + lowered242 = 0L; + + } + + lowered341 = 28; + lowered342 = lowered241; + lowered343 = lowered242; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 29: { + uint? payload245 = payload3.AsHttpResponseTrailerSectionSize; + + int lowered252; + int lowered253; + + if (payload245 != null) { + var payload251 = (uint) payload245; + + lowered252 = 1; + lowered253 = unchecked((int)(payload251)); + + } else { + + lowered252 = 0; + lowered253 = 0; + + } + + lowered341 = 29; + lowered342 = lowered252; + lowered343 = (long) (lowered253); + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 30: { + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload payload256 = payload3.AsHttpResponseTrailerSize; + + int lowered267; + nint lowered268; + int lowered269; + + if (payload256.fieldName != null) { + var payload262 = (string) payload256.fieldName; + + var utf8Bytes264 = Encoding.UTF8.GetBytes(payload262); + var length265 = utf8Bytes264.Length; + var gcHandle266 = GCHandle.Alloc(utf8Bytes264, GCHandleType.Pinned); + var strPtr263 = gcHandle266.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle266.Free()); + + lowered267 = 1; + lowered268 = strPtr263.ToInt32(); + lowered269 = length265; + + } else { + + lowered267 = 0; + lowered268 = 0; + lowered269 = 0; + + } + + int lowered276; + int lowered277; + + if (payload256.fieldSize != null) { + var payload275 = (uint) payload256.fieldSize; + + lowered276 = 1; + lowered277 = unchecked((int)(payload275)); + + } else { + + lowered276 = 0; + lowered277 = 0; + + } + + lowered341 = 30; + lowered342 = lowered267; + lowered343 = (long) (lowered268); + lowered344 = lowered269; + lowered345 = lowered276; + lowered346 = lowered277; + lowered347 = 0; + + break; + } + case 31: { + string? payload280 = payload3.AsHttpResponseTransferCoding; + + int lowered291; + nint lowered292; + int lowered293; + + if (payload280 != null) { + var payload286 = (string) payload280; + + var utf8Bytes288 = Encoding.UTF8.GetBytes(payload286); + var length289 = utf8Bytes288.Length; + var gcHandle290 = GCHandle.Alloc(utf8Bytes288, GCHandleType.Pinned); + var strPtr287 = gcHandle290.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle290.Free()); + + lowered291 = 1; + lowered292 = strPtr287.ToInt32(); + lowered293 = length289; + + } else { + + lowered291 = 0; + lowered292 = 0; + lowered293 = 0; + + } + + lowered341 = 31; + lowered342 = lowered291; + lowered343 = (long) (lowered292); + lowered344 = lowered293; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 32: { + string? payload296 = payload3.AsHttpResponseContentCoding; + + int lowered307; + nint lowered308; + int lowered309; + + if (payload296 != null) { + var payload302 = (string) payload296; + + var utf8Bytes304 = Encoding.UTF8.GetBytes(payload302); + var length305 = utf8Bytes304.Length; + var gcHandle306 = GCHandle.Alloc(utf8Bytes304, GCHandleType.Pinned); + var strPtr303 = gcHandle306.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle306.Free()); + + lowered307 = 1; + lowered308 = strPtr303.ToInt32(); + lowered309 = length305; + + } else { + + lowered307 = 0; + lowered308 = 0; + lowered309 = 0; + + } + + lowered341 = 32; + lowered342 = lowered307; + lowered343 = (long) (lowered308); + lowered344 = lowered309; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 33: { + + lowered341 = 33; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 34: { + + lowered341 = 34; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 35: { + + lowered341 = 35; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 36: { + + lowered341 = 36; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 37: { + + lowered341 = 37; + lowered342 = 0; + lowered343 = 0L; + lowered344 = 0; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + case 38: { + string? payload327 = payload3.AsInternalError; + + int lowered338; + nint lowered339; + int lowered340; + + if (payload327 != null) { + var payload333 = (string) payload327; + + var utf8Bytes335 = Encoding.UTF8.GetBytes(payload333); + var length336 = utf8Bytes335.Length; + var gcHandle337 = GCHandle.Alloc(utf8Bytes335, GCHandleType.Pinned); + var strPtr334 = gcHandle337.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle337.Free()); + + lowered338 = 1; + lowered339 = strPtr334.ToInt32(); + lowered340 = length336; + + } else { + + lowered338 = 0; + lowered339 = 0; + lowered340 = 0; + + } + + lowered341 = 38; + lowered342 = lowered338; + lowered343 = (long) (lowered339); + lowered344 = lowered340; + lowered345 = 0; + lowered346 = 0; + lowered347 = 0; + + break; + } + + default: throw new ArgumentException($"invalid discriminant: {payload3}"); + } + + lowered348 = 1; + lowered349 = lowered341; + lowered350 = lowered342; + lowered351 = lowered343; + lowered352 = lowered344; + lowered353 = lowered345; + lowered354 = lowered346; + lowered355 = lowered347; + + break; + } + + default: throw new ArgumentException($"invalid discriminant: {response}"); + } + SetWasmInterop.wasmImportSet(handle, lowered348, lowered349, lowered350, lowered351, lowered352, lowered353, lowered354, lowered355); + + foreach (var cleanup in cleanups) + { + cleanup(); + } + + } + + } + + /** + * Represents an incoming HTTP Response. + */ + + public class IncomingResponse: IDisposable { + internal int Handle { get; set; } + + public readonly record struct THandle(int Handle); + + public IncomingResponse(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]incoming-response"), WasmImportLinkage] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static class StatusWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-response.status"), WasmImportLinkage] + internal static extern int wasmImportStatus(int p0); + } + + public unsafe ushort Status() + { + var handle = this.Handle; + var result = StatusWasmInterop.wasmImportStatus(handle); + return ((ushort)result); + + } + + internal static class HeadersWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-response.headers"), WasmImportLinkage] + internal static extern int wasmImportHeaders(int p0); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields Headers() + { + var handle = this.Handle; + var result = HeadersWasmInterop.wasmImportHeaders(handle); + var resource = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(result)); + return resource; + + } + + internal static class ConsumeWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-response.consume"), WasmImportLinkage] + internal static extern void wasmImportConsume(int p0, nint p1); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody Consume() + { + var handle = this.Handle; + + var retArea = stackalloc uint[2+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + ConsumeWasmInterop.wasmImportConsume(handle, ptr); + + Result lifted; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)))); + + lifted = Result.Ok(resource); + break; + } + case 1: { + + lifted = Result.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return tmp; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + } + + /** + * 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. + */ + + public class IncomingBody: IDisposable { + internal int Handle { get; set; } + + public readonly record struct THandle(int Handle); + + public IncomingBody(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]incoming-body"), WasmImportLinkage] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static class StreamWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-body.stream"), WasmImportLinkage] + internal static extern void wasmImportStream(int p0, nint p1); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.InputStream Stream() + { + var handle = this.Handle; + + var retArea = stackalloc uint[2+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + StreamWasmInterop.wasmImportStream(handle, ptr); + + Result lifted; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.InputStream(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.InputStream.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)))); + + lifted = Result.Ok(resource); + break; + } + case 1: { + + lifted = Result.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return tmp; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal static class FinishWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[static]incoming-body.finish"), WasmImportLinkage] + internal static extern int wasmImportFinish(int p0); + } + + public static unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FutureTrailers Finish(global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody @this) + { + var handle = @this.Handle; + @this.Handle = 0; + var result = FinishWasmInterop.wasmImportFinish(handle); + var resource = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FutureTrailers(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FutureTrailers.THandle(result)); + return resource; + + } + + } + + /** + * Represents a future which may eventaully 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. + */ + + public class FutureTrailers: IDisposable { + internal int Handle { get; set; } + + public readonly record struct THandle(int Handle); + + public FutureTrailers(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]future-trailers"), WasmImportLinkage] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static class SubscribeWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]future-trailers.subscribe"), WasmImportLinkage] + internal static extern int wasmImportSubscribe(int p0); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable Subscribe() + { + var handle = this.Handle; + var result = SubscribeWasmInterop.wasmImportSubscribe(handle); + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result)); + return resource; + + } + + internal static class GetWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]future-trailers.get"), WasmImportLinkage] + internal static extern void wasmImportGet(int p0, nint p1); + } + + public unsafe Result, None>? Get() + { + var handle = this.Handle; + + var retArea = stackalloc ulong[7+1]; + var ptr = ((int)retArea) + (8 - 1) & -8; + GetWasmInterop.wasmImportGet(handle, ptr); + + Result, None>? lifted205; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + lifted205 = null; + break; + } + + case 1: { + + Result, None> lifted204; + + switch (new Span((void*)(ptr + 8), 1)[0]) { + case 0: { + + Result lifted201; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields? lifted; + + switch (new Span((void*)(ptr + 24), 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + var resource = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 28), 4)))); + + lifted = resource; + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 24), 1)[0])); + } + + lifted201 = Result.Ok(lifted); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode lifted200; + + switch (new Span((void*)(ptr + 24), 1)[0]) { + case 0: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DnsTimeout(); + break; + } + case 1: { + + string? lifted20; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted20 = null; + break; + } + + case 1: { + + lifted20 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + ushort? lifted25; + + switch (new Span((void*)(ptr + 44), 1)[0]) { + case 0: { + lifted25 = null; + break; + } + + case 1: { + + lifted25 = ((ushort)BitConverter.ToUInt16(new Span((void*)(ptr + 46), 2))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 44), 1)[0])); + } + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DnsError(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.DnsErrorPayload ( + lifted20, lifted25)); + break; + } + case 2: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationNotFound(); + break; + } + case 3: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationUnavailable(); + break; + } + case 4: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationIpProhibited(); + break; + } + case 5: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationIpUnroutable(); + break; + } + case 6: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionRefused(); + break; + } + case 7: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionTerminated(); + break; + } + case 8: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionTimeout(); + break; + } + case 9: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionReadTimeout(); + break; + } + case 10: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionWriteTimeout(); + break; + } + case 11: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionLimitReached(); + break; + } + case 12: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.TlsProtocolError(); + break; + } + case 13: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.TlsCertificateError(); + break; + } + case 14: { + + byte? lifted56; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted56 = null; + break; + } + + case 1: { + + lifted56 = ((byte)new Span((void*)(ptr + 33), 1)[0]); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + string? lifted61; + + switch (new Span((void*)(ptr + 36), 1)[0]) { + case 0: { + lifted61 = null; + break; + } + + case 1: { + + lifted61 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 40), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 44), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 36), 1)[0])); + } + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.TlsAlertReceived(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.TlsAlertReceivedPayload ( + lifted56, lifted61)); + break; + } + case 15: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestDenied(); + break; + } + case 16: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestLengthRequired(); + break; + } + case 17: { + + ulong? lifted72; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted72 = null; + break; + } + + case 1: { + + lifted72 = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 40), 8)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestBodySize(lifted72); + break; + } + case 18: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestMethodInvalid(); + break; + } + case 19: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestUriInvalid(); + break; + } + case 20: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestUriTooLong(); + break; + } + case 21: { + + uint? lifted85; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted85 = null; + break; + } + + case 1: { + + lifted85 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestHeaderSectionSize(lifted85); + break; + } + case 22: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload? lifted102; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted102 = null; + break; + } + + case 1: { + + string? lifted96; + + switch (new Span((void*)(ptr + 36), 1)[0]) { + case 0: { + lifted96 = null; + break; + } + + case 1: { + + lifted96 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 40), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 44), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 36), 1)[0])); + } + + uint? lifted101; + + switch (new Span((void*)(ptr + 48), 1)[0]) { + case 0: { + lifted101 = null; + break; + } + + case 1: { + + lifted101 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 52), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 48), 1)[0])); + } + + lifted102 = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted96, lifted101); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestHeaderSize(lifted102); + break; + } + case 23: { + + uint? lifted109; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted109 = null; + break; + } + + case 1: { + + lifted109 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestTrailerSectionSize(lifted109); + break; + } + case 24: { + + string? lifted116; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted116 = null; + break; + } + + case 1: { + + lifted116 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + uint? lifted121; + + switch (new Span((void*)(ptr + 44), 1)[0]) { + case 0: { + lifted121 = null; + break; + } + + case 1: { + + lifted121 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 48), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 44), 1)[0])); + } + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestTrailerSize(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted116, lifted121)); + break; + } + case 25: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseIncomplete(); + break; + } + case 26: { + + uint? lifted130; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted130 = null; + break; + } + + case 1: { + + lifted130 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseHeaderSectionSize(lifted130); + break; + } + case 27: { + + string? lifted137; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted137 = null; + break; + } + + case 1: { + + lifted137 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + uint? lifted142; + + switch (new Span((void*)(ptr + 44), 1)[0]) { + case 0: { + lifted142 = null; + break; + } + + case 1: { + + lifted142 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 48), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 44), 1)[0])); + } + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseHeaderSize(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted137, lifted142)); + break; + } + case 28: { + + ulong? lifted149; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted149 = null; + break; + } + + case 1: { + + lifted149 = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 40), 8)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseBodySize(lifted149); + break; + } + case 29: { + + uint? lifted156; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted156 = null; + break; + } + + case 1: { + + lifted156 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTrailerSectionSize(lifted156); + break; + } + case 30: { + + string? lifted163; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted163 = null; + break; + } + + case 1: { + + lifted163 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + uint? lifted168; + + switch (new Span((void*)(ptr + 44), 1)[0]) { + case 0: { + lifted168 = null; + break; + } + + case 1: { + + lifted168 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 48), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 44), 1)[0])); + } + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTrailerSize(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted163, lifted168)); + break; + } + case 31: { + + string? lifted175; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted175 = null; + break; + } + + case 1: { + + lifted175 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTransferCoding(lifted175); + break; + } + case 32: { + + string? lifted182; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted182 = null; + break; + } + + case 1: { + + lifted182 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseContentCoding(lifted182); + break; + } + case 33: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTimeout(); + break; + } + case 34: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpUpgradeFailed(); + break; + } + case 35: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpProtocolError(); + break; + } + case 36: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.LoopDetected(); + break; + } + case 37: { + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConfigurationError(); + break; + } + case 38: { + + string? lifted199; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted199 = null; + break; + } + + case 1: { + + lifted199 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted200 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.InternalError(lifted199); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 24), 1)[0]}"); + } + + lifted201 = Result.Err(lifted200); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 16), 1)[0]}"); + } + + lifted204 = Result, None>.Ok(lifted201); + break; + } + case 1: { + + lifted204 = Result, None>.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 8), 1)[0]}"); + } + + lifted205 = lifted204; + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0])); + } + return lifted205; + + } + + } + + /** + * Represents an outgoing HTTP Response. + */ + + public class OutgoingResponse: IDisposable { + internal int Handle { get; set; } + + public readonly record struct THandle(int Handle); + + public OutgoingResponse(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]outgoing-response"), WasmImportLinkage] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static class ConstructorWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[constructor]outgoing-response"), WasmImportLinkage] + internal static extern int wasmImportConstructor(int p0); + } + + public unsafe OutgoingResponse(global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields headers) + { + var handle = headers.Handle; + headers.Handle = 0; + var result = ConstructorWasmInterop.wasmImportConstructor(handle); + this.Handle = result; + + } + + internal static class StatusCodeWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-response.status-code"), WasmImportLinkage] + internal static extern int wasmImportStatusCode(int p0); + } + + public unsafe ushort StatusCode() + { + var handle = this.Handle; + var result = StatusCodeWasmInterop.wasmImportStatusCode(handle); + return ((ushort)result); + + } + + internal static class SetStatusCodeWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-response.set-status-code"), WasmImportLinkage] + internal static extern int wasmImportSetStatusCode(int p0, int p1); + } + + public unsafe void SetStatusCode(ushort statusCode) + { + var handle = this.Handle; + var result = SetStatusCodeWasmInterop.wasmImportSetStatusCode(handle, statusCode); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {result}"); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return ; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal static class HeadersWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-response.headers"), WasmImportLinkage] + internal static extern int wasmImportHeaders(int p0); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields Headers() + { + var handle = this.Handle; + var result = HeadersWasmInterop.wasmImportHeaders(handle); + var resource = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(result)); + return resource; + + } + + internal static class BodyWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-response.body"), WasmImportLinkage] + internal static extern void wasmImportBody(int p0, nint p1); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingBody Body() + { + var handle = this.Handle; + + var retArea = stackalloc uint[2+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + BodyWasmInterop.wasmImportBody(handle, ptr); + + Result lifted; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingBody(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingBody.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)))); + + lifted = Result.Ok(resource); + break; + } + case 1: { + + lifted = Result.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return tmp; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + } + + /** + * 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 occured. The implementation should propogate 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. + */ + + public class OutgoingBody: IDisposable { + internal int Handle { get; set; } + + public readonly record struct THandle(int Handle); + + public OutgoingBody(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]outgoing-body"), WasmImportLinkage] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static class WriteWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-body.write"), WasmImportLinkage] + internal static extern void wasmImportWrite(int p0, nint p1); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.OutputStream Write() + { + var handle = this.Handle; + + var retArea = stackalloc uint[2+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + WriteWasmInterop.wasmImportWrite(handle, ptr); + + Result lifted; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.OutputStream(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.OutputStream.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)))); + + lifted = Result.Ok(resource); + break; + } + case 1: { + + lifted = Result.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return tmp; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal static class FinishWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[static]outgoing-body.finish"), WasmImportLinkage] + internal static extern void wasmImportFinish(int p0, int p1, int p2, nint p3); + } + + public static unsafe void Finish(global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingBody @this, global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields? trailers) + { + var handle = @this.Handle; + @this.Handle = 0; + + int lowered; + int lowered4; + + if (trailers != null) { + var payload2 = (global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields) trailers; + var handle3 = payload2.Handle; + payload2.Handle = 0; + + lowered = 1; + lowered4 = handle3; + + } else { + + lowered = 0; + lowered4 = 0; + + } + + var retArea = stackalloc ulong[5+1]; + var ptr = ((int)retArea) + (8 - 1) & -8; + FinishWasmInterop.wasmImportFinish(handle, lowered, lowered4, ptr); + + Result lifted197; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted197 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode lifted196; + + switch (new Span((void*)(ptr + 8), 1)[0]) { + case 0: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DnsTimeout(); + break; + } + case 1: { + + string? lifted; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + lifted = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + ushort? lifted21; + + switch (new Span((void*)(ptr + 28), 1)[0]) { + case 0: { + lifted21 = null; + break; + } + + case 1: { + + lifted21 = ((ushort)BitConverter.ToUInt16(new Span((void*)(ptr + 30), 2))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 28), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DnsError(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.DnsErrorPayload ( + lifted, lifted21)); + break; + } + case 2: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationNotFound(); + break; + } + case 3: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationUnavailable(); + break; + } + case 4: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationIpProhibited(); + break; + } + case 5: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationIpUnroutable(); + break; + } + case 6: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionRefused(); + break; + } + case 7: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionTerminated(); + break; + } + case 8: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionTimeout(); + break; + } + case 9: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionReadTimeout(); + break; + } + case 10: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionWriteTimeout(); + break; + } + case 11: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionLimitReached(); + break; + } + case 12: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.TlsProtocolError(); + break; + } + case 13: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.TlsCertificateError(); + break; + } + case 14: { + + byte? lifted52; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted52 = null; + break; + } + + case 1: { + + lifted52 = ((byte)new Span((void*)(ptr + 17), 1)[0]); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + string? lifted57; + + switch (new Span((void*)(ptr + 20), 1)[0]) { + case 0: { + lifted57 = null; + break; + } + + case 1: { + + lifted57 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 24), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 28), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 20), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.TlsAlertReceived(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.TlsAlertReceivedPayload ( + lifted52, lifted57)); + break; + } + case 15: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestDenied(); + break; + } + case 16: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestLengthRequired(); + break; + } + case 17: { + + ulong? lifted68; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted68 = null; + break; + } + + case 1: { + + lifted68 = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 24), 8)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestBodySize(lifted68); + break; + } + case 18: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestMethodInvalid(); + break; + } + case 19: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestUriInvalid(); + break; + } + case 20: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestUriTooLong(); + break; + } + case 21: { + + uint? lifted81; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted81 = null; + break; + } + + case 1: { + + lifted81 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestHeaderSectionSize(lifted81); + break; + } + case 22: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload? lifted98; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted98 = null; + break; + } + + case 1: { + + string? lifted92; + + switch (new Span((void*)(ptr + 20), 1)[0]) { + case 0: { + lifted92 = null; + break; + } + + case 1: { + + lifted92 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 24), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 28), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 20), 1)[0])); + } + + uint? lifted97; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted97 = null; + break; + } + + case 1: { + + lifted97 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted98 = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted92, lifted97); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestHeaderSize(lifted98); + break; + } + case 23: { + + uint? lifted105; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted105 = null; + break; + } + + case 1: { + + lifted105 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestTrailerSectionSize(lifted105); + break; + } + case 24: { + + string? lifted112; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted112 = null; + break; + } + + case 1: { + + lifted112 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + uint? lifted117; + + switch (new Span((void*)(ptr + 28), 1)[0]) { + case 0: { + lifted117 = null; + break; + } + + case 1: { + + lifted117 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 32), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 28), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestTrailerSize(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted112, lifted117)); + break; + } + case 25: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseIncomplete(); + break; + } + case 26: { + + uint? lifted126; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted126 = null; + break; + } + + case 1: { + + lifted126 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseHeaderSectionSize(lifted126); + break; + } + case 27: { + + string? lifted133; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted133 = null; + break; + } + + case 1: { + + lifted133 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + uint? lifted138; + + switch (new Span((void*)(ptr + 28), 1)[0]) { + case 0: { + lifted138 = null; + break; + } + + case 1: { + + lifted138 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 32), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 28), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseHeaderSize(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted133, lifted138)); + break; + } + case 28: { + + ulong? lifted145; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted145 = null; + break; + } + + case 1: { + + lifted145 = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 24), 8)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseBodySize(lifted145); + break; + } + case 29: { + + uint? lifted152; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted152 = null; + break; + } + + case 1: { + + lifted152 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTrailerSectionSize(lifted152); + break; + } + case 30: { + + string? lifted159; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted159 = null; + break; + } + + case 1: { + + lifted159 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + uint? lifted164; + + switch (new Span((void*)(ptr + 28), 1)[0]) { + case 0: { + lifted164 = null; + break; + } + + case 1: { + + lifted164 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 32), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 28), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTrailerSize(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted159, lifted164)); + break; + } + case 31: { + + string? lifted171; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted171 = null; + break; + } + + case 1: { + + lifted171 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTransferCoding(lifted171); + break; + } + case 32: { + + string? lifted178; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted178 = null; + break; + } + + case 1: { + + lifted178 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseContentCoding(lifted178); + break; + } + case 33: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTimeout(); + break; + } + case 34: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpUpgradeFailed(); + break; + } + case 35: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpProtocolError(); + break; + } + case 36: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.LoopDetected(); + break; + } + case 37: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConfigurationError(); + break; + } + case 38: { + + string? lifted195; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted195 = null; + break; + } + + case 1: { + + lifted195 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.InternalError(lifted195); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 8), 1)[0]}"); + } + + lifted197 = Result.Err(lifted196); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted197.IsOk) + { + var tmp = lifted197.AsOk; + return ; + } + else + { + throw new WitException(lifted197.AsErr!, 0); + } + + } + + } + + /** + * Represents a future which may eventaully 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. + */ + + public class FutureIncomingResponse: IDisposable { + internal int Handle { get; set; } + + public readonly record struct THandle(int Handle); + + public FutureIncomingResponse(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]future-incoming-response"), WasmImportLinkage] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static class SubscribeWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]future-incoming-response.subscribe"), WasmImportLinkage] + internal static extern int wasmImportSubscribe(int p0); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable Subscribe() + { + var handle = this.Handle; + var result = SubscribeWasmInterop.wasmImportSubscribe(handle); + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result)); + return resource; + + } + + internal static class GetWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]future-incoming-response.get"), WasmImportLinkage] + internal static extern void wasmImportGet(int p0, nint p1); + } + + public unsafe Result, None>? Get() + { + var handle = this.Handle; + + var retArea = stackalloc ulong[7+1]; + var ptr = ((int)retArea) + (8 - 1) & -8; + GetWasmInterop.wasmImportGet(handle, ptr); + + Result, None>? lifted200; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + lifted200 = null; + break; + } + + case 1: { + + Result, None> lifted199; + + switch (new Span((void*)(ptr + 8), 1)[0]) { + case 0: { + + Result lifted196; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingResponse(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingResponse.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 24), 4)))); + + lifted196 = Result.Ok(resource); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode lifted195; + + switch (new Span((void*)(ptr + 24), 1)[0]) { + case 0: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DnsTimeout(); + break; + } + case 1: { + + string? lifted; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + lifted = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + ushort? lifted20; + + switch (new Span((void*)(ptr + 44), 1)[0]) { + case 0: { + lifted20 = null; + break; + } + + case 1: { + + lifted20 = ((ushort)BitConverter.ToUInt16(new Span((void*)(ptr + 46), 2))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 44), 1)[0])); + } + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DnsError(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.DnsErrorPayload ( + lifted, lifted20)); + break; + } + case 2: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationNotFound(); + break; + } + case 3: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationUnavailable(); + break; + } + case 4: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationIpProhibited(); + break; + } + case 5: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationIpUnroutable(); + break; + } + case 6: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionRefused(); + break; + } + case 7: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionTerminated(); + break; + } + case 8: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionTimeout(); + break; + } + case 9: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionReadTimeout(); + break; + } + case 10: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionWriteTimeout(); + break; + } + case 11: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionLimitReached(); + break; + } + case 12: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.TlsProtocolError(); + break; + } + case 13: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.TlsCertificateError(); + break; + } + case 14: { + + byte? lifted51; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted51 = null; + break; + } + + case 1: { + + lifted51 = ((byte)new Span((void*)(ptr + 33), 1)[0]); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + string? lifted56; + + switch (new Span((void*)(ptr + 36), 1)[0]) { + case 0: { + lifted56 = null; + break; + } + + case 1: { + + lifted56 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 40), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 44), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 36), 1)[0])); + } + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.TlsAlertReceived(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.TlsAlertReceivedPayload ( + lifted51, lifted56)); + break; + } + case 15: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestDenied(); + break; + } + case 16: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestLengthRequired(); + break; + } + case 17: { + + ulong? lifted67; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted67 = null; + break; + } + + case 1: { + + lifted67 = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 40), 8)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestBodySize(lifted67); + break; + } + case 18: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestMethodInvalid(); + break; + } + case 19: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestUriInvalid(); + break; + } + case 20: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestUriTooLong(); + break; + } + case 21: { + + uint? lifted80; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted80 = null; + break; + } + + case 1: { + + lifted80 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestHeaderSectionSize(lifted80); + break; + } + case 22: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload? lifted97; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted97 = null; + break; + } + + case 1: { + + string? lifted91; + + switch (new Span((void*)(ptr + 36), 1)[0]) { + case 0: { + lifted91 = null; + break; + } + + case 1: { + + lifted91 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 40), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 44), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 36), 1)[0])); + } + + uint? lifted96; + + switch (new Span((void*)(ptr + 48), 1)[0]) { + case 0: { + lifted96 = null; + break; + } + + case 1: { + + lifted96 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 52), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 48), 1)[0])); + } + + lifted97 = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted91, lifted96); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestHeaderSize(lifted97); + break; + } + case 23: { + + uint? lifted104; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted104 = null; + break; + } + + case 1: { + + lifted104 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestTrailerSectionSize(lifted104); + break; + } + case 24: { + + string? lifted111; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted111 = null; + break; + } + + case 1: { + + lifted111 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + uint? lifted116; + + switch (new Span((void*)(ptr + 44), 1)[0]) { + case 0: { + lifted116 = null; + break; + } + + case 1: { + + lifted116 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 48), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 44), 1)[0])); + } + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestTrailerSize(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted111, lifted116)); + break; + } + case 25: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseIncomplete(); + break; + } + case 26: { + + uint? lifted125; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted125 = null; + break; + } + + case 1: { + + lifted125 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseHeaderSectionSize(lifted125); + break; + } + case 27: { + + string? lifted132; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted132 = null; + break; + } + + case 1: { + + lifted132 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + uint? lifted137; + + switch (new Span((void*)(ptr + 44), 1)[0]) { + case 0: { + lifted137 = null; + break; + } + + case 1: { + + lifted137 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 48), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 44), 1)[0])); + } + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseHeaderSize(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted132, lifted137)); + break; + } + case 28: { + + ulong? lifted144; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted144 = null; + break; + } + + case 1: { + + lifted144 = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 40), 8)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseBodySize(lifted144); + break; + } + case 29: { + + uint? lifted151; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted151 = null; + break; + } + + case 1: { + + lifted151 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTrailerSectionSize(lifted151); + break; + } + case 30: { + + string? lifted158; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted158 = null; + break; + } + + case 1: { + + lifted158 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + uint? lifted163; + + switch (new Span((void*)(ptr + 44), 1)[0]) { + case 0: { + lifted163 = null; + break; + } + + case 1: { + + lifted163 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 48), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 44), 1)[0])); + } + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTrailerSize(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted158, lifted163)); + break; + } + case 31: { + + string? lifted170; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted170 = null; + break; + } + + case 1: { + + lifted170 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTransferCoding(lifted170); + break; + } + case 32: { + + string? lifted177; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted177 = null; + break; + } + + case 1: { + + lifted177 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseContentCoding(lifted177); + break; + } + case 33: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTimeout(); + break; + } + case 34: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpUpgradeFailed(); + break; + } + case 35: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpProtocolError(); + break; + } + case 36: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.LoopDetected(); + break; + } + case 37: { + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConfigurationError(); + break; + } + case 38: { + + string? lifted194; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted194 = null; + break; + } + + case 1: { + + lifted194 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted195 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.InternalError(lifted194); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 24), 1)[0]}"); + } + + lifted196 = Result.Err(lifted195); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 16), 1)[0]}"); + } + + lifted199 = Result, None>.Ok(lifted196); + break; + } + case 1: { + + lifted199 = Result, None>.Err(new global::ComputerWorld.None()); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 8), 1)[0]}"); + } + + lifted200 = lifted199; + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0])); + } + return lifted200; + + } + + } + +} diff --git a/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.http.v0_2_0.OutgoingHandlerInterop.cs b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.http.v0_2_0.OutgoingHandlerInterop.cs new file mode 100644 index 0000000..4c0b0bc --- /dev/null +++ b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.http.v0_2_0.OutgoingHandlerInterop.cs @@ -0,0 +1,657 @@ +// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! +// +#nullable enable + +using System.Runtime.InteropServices; +using System.Text; + +namespace ComputerWorld.wit.imports.wasi.http.v0_2_0 +{ + public static class OutgoingHandlerInterop { + + internal static class HandleWasmInterop + { + [DllImport("wasi:http/outgoing-handler@0.2.0", EntryPoint = "handle"), WasmImportLinkage] + internal static extern void wasmImportHandle(int p0, int p1, int p2, nint p3); + } + + public static unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FutureIncomingResponse Handle(global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingRequest request, global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.RequestOptions? options) + { + var handle = request.Handle; + request.Handle = 0; + + int lowered; + int lowered4; + + if (options != null) { + var payload2 = (global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.RequestOptions) options; + var handle3 = payload2.Handle; + payload2.Handle = 0; + + lowered = 1; + lowered4 = handle3; + + } else { + + lowered = 0; + lowered4 = 0; + + } + + var retArea = stackalloc ulong[5+1]; + var ptr = ((int)retArea) + (8 - 1) & -8; + HandleWasmInterop.wasmImportHandle(handle, lowered, lowered4, ptr); + + Result lifted197; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FutureIncomingResponse(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FutureIncomingResponse.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); + + lifted197 = Result.Ok(resource); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode lifted196; + + switch (new Span((void*)(ptr + 8), 1)[0]) { + case 0: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DnsTimeout(); + break; + } + case 1: { + + string? lifted; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + lifted = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + ushort? lifted21; + + switch (new Span((void*)(ptr + 28), 1)[0]) { + case 0: { + lifted21 = null; + break; + } + + case 1: { + + lifted21 = ((ushort)BitConverter.ToUInt16(new Span((void*)(ptr + 30), 2))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 28), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DnsError(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.DnsErrorPayload ( + lifted, lifted21)); + break; + } + case 2: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationNotFound(); + break; + } + case 3: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationUnavailable(); + break; + } + case 4: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationIpProhibited(); + break; + } + case 5: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationIpUnroutable(); + break; + } + case 6: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionRefused(); + break; + } + case 7: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionTerminated(); + break; + } + case 8: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionTimeout(); + break; + } + case 9: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionReadTimeout(); + break; + } + case 10: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionWriteTimeout(); + break; + } + case 11: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionLimitReached(); + break; + } + case 12: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.TlsProtocolError(); + break; + } + case 13: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.TlsCertificateError(); + break; + } + case 14: { + + byte? lifted52; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted52 = null; + break; + } + + case 1: { + + lifted52 = ((byte)new Span((void*)(ptr + 17), 1)[0]); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + string? lifted57; + + switch (new Span((void*)(ptr + 20), 1)[0]) { + case 0: { + lifted57 = null; + break; + } + + case 1: { + + lifted57 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 24), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 28), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 20), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.TlsAlertReceived(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.TlsAlertReceivedPayload ( + lifted52, lifted57)); + break; + } + case 15: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestDenied(); + break; + } + case 16: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestLengthRequired(); + break; + } + case 17: { + + ulong? lifted68; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted68 = null; + break; + } + + case 1: { + + lifted68 = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 24), 8)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestBodySize(lifted68); + break; + } + case 18: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestMethodInvalid(); + break; + } + case 19: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestUriInvalid(); + break; + } + case 20: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestUriTooLong(); + break; + } + case 21: { + + uint? lifted81; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted81 = null; + break; + } + + case 1: { + + lifted81 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestHeaderSectionSize(lifted81); + break; + } + case 22: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload? lifted98; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted98 = null; + break; + } + + case 1: { + + string? lifted92; + + switch (new Span((void*)(ptr + 20), 1)[0]) { + case 0: { + lifted92 = null; + break; + } + + case 1: { + + lifted92 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 24), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 28), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 20), 1)[0])); + } + + uint? lifted97; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted97 = null; + break; + } + + case 1: { + + lifted97 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted98 = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted92, lifted97); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestHeaderSize(lifted98); + break; + } + case 23: { + + uint? lifted105; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted105 = null; + break; + } + + case 1: { + + lifted105 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestTrailerSectionSize(lifted105); + break; + } + case 24: { + + string? lifted112; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted112 = null; + break; + } + + case 1: { + + lifted112 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + uint? lifted117; + + switch (new Span((void*)(ptr + 28), 1)[0]) { + case 0: { + lifted117 = null; + break; + } + + case 1: { + + lifted117 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 32), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 28), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestTrailerSize(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted112, lifted117)); + break; + } + case 25: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseIncomplete(); + break; + } + case 26: { + + uint? lifted126; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted126 = null; + break; + } + + case 1: { + + lifted126 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseHeaderSectionSize(lifted126); + break; + } + case 27: { + + string? lifted133; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted133 = null; + break; + } + + case 1: { + + lifted133 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + uint? lifted138; + + switch (new Span((void*)(ptr + 28), 1)[0]) { + case 0: { + lifted138 = null; + break; + } + + case 1: { + + lifted138 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 32), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 28), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseHeaderSize(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted133, lifted138)); + break; + } + case 28: { + + ulong? lifted145; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted145 = null; + break; + } + + case 1: { + + lifted145 = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 24), 8)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseBodySize(lifted145); + break; + } + case 29: { + + uint? lifted152; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted152 = null; + break; + } + + case 1: { + + lifted152 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTrailerSectionSize(lifted152); + break; + } + case 30: { + + string? lifted159; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted159 = null; + break; + } + + case 1: { + + lifted159 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + uint? lifted164; + + switch (new Span((void*)(ptr + 28), 1)[0]) { + case 0: { + lifted164 = null; + break; + } + + case 1: { + + lifted164 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 32), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 28), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTrailerSize(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted159, lifted164)); + break; + } + case 31: { + + string? lifted171; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted171 = null; + break; + } + + case 1: { + + lifted171 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTransferCoding(lifted171); + break; + } + case 32: { + + string? lifted178; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted178 = null; + break; + } + + case 1: { + + lifted178 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseContentCoding(lifted178); + break; + } + case 33: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTimeout(); + break; + } + case 34: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpUpgradeFailed(); + break; + } + case 35: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpProtocolError(); + break; + } + case 36: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.LoopDetected(); + break; + } + case 37: { + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConfigurationError(); + break; + } + case 38: { + + string? lifted195; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted195 = null; + break; + } + + case 1: { + + lifted195 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted196 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.InternalError(lifted195); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 8), 1)[0]}"); + } + + lifted197 = Result.Err(lifted196); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted197.IsOk) + { + var tmp = lifted197.AsOk; + return tmp; + } + else + { + throw new WitException(lifted197.AsErr!, 0); + } + + } + + } +} diff --git a/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.http.v0_2_0.TypesInterop.cs b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.http.v0_2_0.TypesInterop.cs new file mode 100644 index 0000000..2301685 --- /dev/null +++ b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.http.v0_2_0.TypesInterop.cs @@ -0,0 +1,629 @@ +// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! +// +#nullable enable + +using System.Runtime.InteropServices; +using System.Text; + +namespace ComputerWorld.wit.imports.wasi.http.v0_2_0 +{ + public static class TypesInterop { + + internal static class HttpErrorCodeWasmInterop + { + [DllImport("wasi:http/types@0.2.0", EntryPoint = "http-error-code"), WasmImportLinkage] + internal static extern void wasmImportHttpErrorCode(int p0, nint p1); + } + + public static unsafe global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode? HttpErrorCode(global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error err) + { + var handle = err.Handle; + + var retArea = stackalloc ulong[5+1]; + var ptr = ((int)retArea) + (8 - 1) & -8; + HttpErrorCodeWasmInterop.wasmImportHttpErrorCode(handle, ptr); + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode? lifted190; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + lifted190 = null; + break; + } + + case 1: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode lifted189; + + switch (new Span((void*)(ptr + 8), 1)[0]) { + case 0: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DnsTimeout(); + break; + } + case 1: { + + string? lifted; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + lifted = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + ushort? lifted14; + + switch (new Span((void*)(ptr + 28), 1)[0]) { + case 0: { + lifted14 = null; + break; + } + + case 1: { + + lifted14 = ((ushort)BitConverter.ToUInt16(new Span((void*)(ptr + 30), 2))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 28), 1)[0])); + } + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DnsError(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.DnsErrorPayload ( + lifted, lifted14)); + break; + } + case 2: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationNotFound(); + break; + } + case 3: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationUnavailable(); + break; + } + case 4: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationIpProhibited(); + break; + } + case 5: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.DestinationIpUnroutable(); + break; + } + case 6: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionRefused(); + break; + } + case 7: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionTerminated(); + break; + } + case 8: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionTimeout(); + break; + } + case 9: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionReadTimeout(); + break; + } + case 10: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionWriteTimeout(); + break; + } + case 11: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConnectionLimitReached(); + break; + } + case 12: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.TlsProtocolError(); + break; + } + case 13: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.TlsCertificateError(); + break; + } + case 14: { + + byte? lifted45; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted45 = null; + break; + } + + case 1: { + + lifted45 = ((byte)new Span((void*)(ptr + 17), 1)[0]); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + string? lifted50; + + switch (new Span((void*)(ptr + 20), 1)[0]) { + case 0: { + lifted50 = null; + break; + } + + case 1: { + + lifted50 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 24), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 28), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 20), 1)[0])); + } + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.TlsAlertReceived(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.TlsAlertReceivedPayload ( + lifted45, lifted50)); + break; + } + case 15: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestDenied(); + break; + } + case 16: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestLengthRequired(); + break; + } + case 17: { + + ulong? lifted61; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted61 = null; + break; + } + + case 1: { + + lifted61 = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 24), 8)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestBodySize(lifted61); + break; + } + case 18: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestMethodInvalid(); + break; + } + case 19: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestUriInvalid(); + break; + } + case 20: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestUriTooLong(); + break; + } + case 21: { + + uint? lifted74; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted74 = null; + break; + } + + case 1: { + + lifted74 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestHeaderSectionSize(lifted74); + break; + } + case 22: { + + global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload? lifted91; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted91 = null; + break; + } + + case 1: { + + string? lifted85; + + switch (new Span((void*)(ptr + 20), 1)[0]) { + case 0: { + lifted85 = null; + break; + } + + case 1: { + + lifted85 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 24), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 28), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 20), 1)[0])); + } + + uint? lifted90; + + switch (new Span((void*)(ptr + 32), 1)[0]) { + case 0: { + lifted90 = null; + break; + } + + case 1: { + + lifted90 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0])); + } + + lifted91 = new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted85, lifted90); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestHeaderSize(lifted91); + break; + } + case 23: { + + uint? lifted98; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted98 = null; + break; + } + + case 1: { + + lifted98 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestTrailerSectionSize(lifted98); + break; + } + case 24: { + + string? lifted105; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted105 = null; + break; + } + + case 1: { + + lifted105 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + uint? lifted110; + + switch (new Span((void*)(ptr + 28), 1)[0]) { + case 0: { + lifted110 = null; + break; + } + + case 1: { + + lifted110 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 32), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 28), 1)[0])); + } + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpRequestTrailerSize(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted105, lifted110)); + break; + } + case 25: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseIncomplete(); + break; + } + case 26: { + + uint? lifted119; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted119 = null; + break; + } + + case 1: { + + lifted119 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseHeaderSectionSize(lifted119); + break; + } + case 27: { + + string? lifted126; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted126 = null; + break; + } + + case 1: { + + lifted126 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + uint? lifted131; + + switch (new Span((void*)(ptr + 28), 1)[0]) { + case 0: { + lifted131 = null; + break; + } + + case 1: { + + lifted131 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 32), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 28), 1)[0])); + } + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseHeaderSize(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted126, lifted131)); + break; + } + case 28: { + + ulong? lifted138; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted138 = null; + break; + } + + case 1: { + + lifted138 = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 24), 8)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseBodySize(lifted138); + break; + } + case 29: { + + uint? lifted145; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted145 = null; + break; + } + + case 1: { + + lifted145 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTrailerSectionSize(lifted145); + break; + } + case 30: { + + string? lifted152; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted152 = null; + break; + } + + case 1: { + + lifted152 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + uint? lifted157; + + switch (new Span((void*)(ptr + 28), 1)[0]) { + case 0: { + lifted157 = null; + break; + } + + case 1: { + + lifted157 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 32), 4)))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 28), 1)[0])); + } + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTrailerSize(new global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( + lifted152, lifted157)); + break; + } + case 31: { + + string? lifted164; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted164 = null; + break; + } + + case 1: { + + lifted164 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTransferCoding(lifted164); + break; + } + case 32: { + + string? lifted171; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted171 = null; + break; + } + + case 1: { + + lifted171 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseContentCoding(lifted171); + break; + } + case 33: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpResponseTimeout(); + break; + } + case 34: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpUpgradeFailed(); + break; + } + case 35: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.HttpProtocolError(); + break; + } + case 36: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.LoopDetected(); + break; + } + case 37: { + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.ConfigurationError(); + break; + } + case 38: { + + string? lifted188; + + switch (new Span((void*)(ptr + 16), 1)[0]) { + case 0: { + lifted188 = null; + break; + } + + case 1: { + + lifted188 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 20), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 24), 4))); + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 16), 1)[0])); + } + + lifted189 = global::ComputerWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.InternalError(lifted188); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 8), 1)[0]}"); + } + + lifted190 = lifted189; + break; + } + + default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0])); + } + return lifted190; + + } + + } +} diff --git a/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.ErrorInterop.cs b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.ErrorInterop.cs new file mode 100644 index 0000000..3972823 --- /dev/null +++ b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.ErrorInterop.cs @@ -0,0 +1,10 @@ +// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! +// +#nullable enable + +namespace ComputerWorld.wit.imports.wasi.io.v0_2_0 +{ + public static class ErrorInterop { + + } +} diff --git a/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.cs b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.cs new file mode 100644 index 0000000..6358709 --- /dev/null +++ b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.cs @@ -0,0 +1,54 @@ +// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! +// +#nullable enable + +using System.Runtime.InteropServices; +using System.Text; + +namespace ComputerWorld.wit.imports.wasi.io.v0_2_0; + +public interface IError { + + public class Error: IDisposable { + internal int Handle { get; set; } + + public readonly record struct THandle(int Handle); + + public Error(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [DllImport("wasi:io/error@0.2.0", EntryPoint = "[resource-drop]error"), WasmImportLinkage] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static class ToDebugStringWasmInterop + { + [DllImport("wasi:io/error@0.2.0", EntryPoint = "[method]error.to-debug-string"), WasmImportLinkage] + internal static extern void wasmImportToDebugString(int p0, nint p1); + } + + public unsafe string ToDebugString() + { + var handle = this.Handle; + + var retArea = stackalloc uint[2+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + ToDebugStringWasmInterop.wasmImportToDebugString(handle, ptr); + return Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 0), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 4), 4))); + + } + + } + +} diff --git a/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.cs b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.cs new file mode 100644 index 0000000..200aec5 --- /dev/null +++ b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.cs @@ -0,0 +1,63 @@ +// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! +// +#nullable enable + +using System.Runtime.InteropServices; + +namespace ComputerWorld.wit.imports.wasi.io.v0_2_0; + +public interface IPoll { + + public class Pollable: IDisposable { + internal int Handle { get; set; } + + public readonly record struct THandle(int Handle); + + public Pollable(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [DllImport("wasi:io/poll@0.2.0", EntryPoint = "[resource-drop]pollable"), WasmImportLinkage] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static class ReadyWasmInterop + { + [DllImport("wasi:io/poll@0.2.0", EntryPoint = "[method]pollable.ready"), WasmImportLinkage] + internal static extern int wasmImportReady(int p0); + } + + public unsafe bool Ready() + { + var handle = this.Handle; + var result = ReadyWasmInterop.wasmImportReady(handle); + return (result != 0); + + } + + internal static class BlockWasmInterop + { + [DllImport("wasi:io/poll@0.2.0", EntryPoint = "[method]pollable.block"), WasmImportLinkage] + internal static extern void wasmImportBlock(int p0); + } + + public unsafe void Block() + { + var handle = this.Handle; + BlockWasmInterop.wasmImportBlock(handle); + + } + + } + +} diff --git a/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.cs b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.cs new file mode 100644 index 0000000..607e80a --- /dev/null +++ b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.cs @@ -0,0 +1,1161 @@ +// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! +// +#nullable enable + +using System.Runtime.InteropServices; + +namespace ComputerWorld.wit.imports.wasi.io.v0_2_0; + +public interface IStreams { + + public class StreamError { + public readonly byte Tag; + private readonly object? value; + + private StreamError(byte tag, object? value) { + this.Tag = tag; + this.value = value; + } + + public static StreamError LastOperationFailed(global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error lastOperationFailed) { + return new StreamError(Tags.LastOperationFailed, lastOperationFailed); + } + + public static StreamError Closed() { + return new StreamError(Tags.Closed, null); + } + + public global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error AsLastOperationFailed + { + get + { + if (Tag == Tags.LastOperationFailed) + return (global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error)value!; + else + throw new ArgumentException("expected LastOperationFailed, got " + Tag); + } + } + + public class Tags { + public const byte LastOperationFailed = 0; + public const byte Closed = 1; + } + } + + public class InputStream: IDisposable { + internal int Handle { get; set; } + + public readonly record struct THandle(int Handle); + + public InputStream(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[resource-drop]input-stream"), WasmImportLinkage] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static class ReadWasmInterop + { + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]input-stream.read"), WasmImportLinkage] + internal static extern void wasmImportRead(int p0, long p1, nint p2); + } + + public unsafe byte[] Read(ulong len) + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + ReadWasmInterop.wasmImportRead(handle, unchecked((long)(len)), ptr); + + Result lifted6; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + var array = new byte[BitConverter.ToInt32(new Span((void*)(ptr + 8), 4))]; + new Span((void*)(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4))), BitConverter.ToInt32(new Span((void*)(ptr + 8), 4))).CopyTo(new Span(array)); + + lifted6 = Result.Ok(array); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 4), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return tmp; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal static class BlockingReadWasmInterop + { + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]input-stream.blocking-read"), WasmImportLinkage] + internal static extern void wasmImportBlockingRead(int p0, long p1, nint p2); + } + + public unsafe byte[] BlockingRead(ulong len) + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + BlockingReadWasmInterop.wasmImportBlockingRead(handle, unchecked((long)(len)), ptr); + + Result lifted6; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + var array = new byte[BitConverter.ToInt32(new Span((void*)(ptr + 8), 4))]; + new Span((void*)(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4))), BitConverter.ToInt32(new Span((void*)(ptr + 8), 4))).CopyTo(new Span(array)); + + lifted6 = Result.Ok(array); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 4), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return tmp; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal static class SkipWasmInterop + { + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]input-stream.skip"), WasmImportLinkage] + internal static extern void wasmImportSkip(int p0, long p1, nint p2); + } + + public unsafe ulong Skip(ulong len) + { + var handle = this.Handle; + + var retArea = stackalloc ulong[2+1]; + var ptr = ((int)retArea) + (8 - 1) & -8; + SkipWasmInterop.wasmImportSkip(handle, unchecked((long)(len)), ptr); + + Result lifted6; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted6 = Result.Ok(unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 8), 8))))); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 8), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 12), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 8), 1)[0]}"); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return tmp; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal static class BlockingSkipWasmInterop + { + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]input-stream.blocking-skip"), WasmImportLinkage] + internal static extern void wasmImportBlockingSkip(int p0, long p1, nint p2); + } + + public unsafe ulong BlockingSkip(ulong len) + { + var handle = this.Handle; + + var retArea = stackalloc ulong[2+1]; + var ptr = ((int)retArea) + (8 - 1) & -8; + BlockingSkipWasmInterop.wasmImportBlockingSkip(handle, unchecked((long)(len)), ptr); + + Result lifted6; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted6 = Result.Ok(unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 8), 8))))); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 8), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 12), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 8), 1)[0]}"); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return tmp; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal static class SubscribeWasmInterop + { + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]input-stream.subscribe"), WasmImportLinkage] + internal static extern int wasmImportSubscribe(int p0); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable Subscribe() + { + var handle = this.Handle; + var result = SubscribeWasmInterop.wasmImportSubscribe(handle); + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result)); + return resource; + + } + + } + + public class OutputStream: IDisposable { + internal int Handle { get; set; } + + public readonly record struct THandle(int Handle); + + public OutputStream(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[resource-drop]output-stream"), WasmImportLinkage] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static class CheckWriteWasmInterop + { + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]output-stream.check-write"), WasmImportLinkage] + internal static extern void wasmImportCheckWrite(int p0, nint p1); + } + + public unsafe ulong CheckWrite() + { + var handle = this.Handle; + + var retArea = stackalloc ulong[2+1]; + var ptr = ((int)retArea) + (8 - 1) & -8; + CheckWriteWasmInterop.wasmImportCheckWrite(handle, ptr); + + Result lifted6; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted6 = Result.Ok(unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 8), 8))))); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 8), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 12), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 8), 1)[0]}"); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return tmp; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal static class WriteWasmInterop + { + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]output-stream.write"), WasmImportLinkage] + internal static extern void wasmImportWrite(int p0, nint p1, int p2, nint p3); + } + + public unsafe void Write(byte[] contents) + { + var cleanups = new List(); + var handle = this.Handle; + + var gcHandle = GCHandle.Alloc(contents, GCHandleType.Pinned); + var listPtr = gcHandle.AddrOfPinnedObject(); + cleanups.Add(()=> gcHandle.Free()); + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + WriteWasmInterop.wasmImportWrite(handle, (nint)listPtr, (contents).Length, ptr); + + Result lifted6; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 4), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + public unsafe void Write(Span contents) + { + fixed (void* listPtr = contents) + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + WriteWasmInterop.wasmImportWrite(handle, (nint)listPtr, (contents).Length, ptr); + + Result lifted6; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 4), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + } + + } + + public unsafe void Write(Memory contents) + { + fixed (void* listPtr = contents.Span) + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + WriteWasmInterop.wasmImportWrite(handle, (nint)listPtr, (contents).Length, ptr); + + Result lifted6; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 4), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + } + + } + + internal static class BlockingWriteAndFlushWasmInterop + { + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]output-stream.blocking-write-and-flush"), WasmImportLinkage] + internal static extern void wasmImportBlockingWriteAndFlush(int p0, nint p1, int p2, nint p3); + } + + public unsafe void BlockingWriteAndFlush(byte[] contents) + { + var cleanups = new List(); + var handle = this.Handle; + + var gcHandle = GCHandle.Alloc(contents, GCHandleType.Pinned); + var listPtr = gcHandle.AddrOfPinnedObject(); + cleanups.Add(()=> gcHandle.Free()); + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + BlockingWriteAndFlushWasmInterop.wasmImportBlockingWriteAndFlush(handle, (nint)listPtr, (contents).Length, ptr); + + Result lifted6; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 4), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + public unsafe void BlockingWriteAndFlush(Span contents) + { + fixed (void* listPtr = contents) + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + BlockingWriteAndFlushWasmInterop.wasmImportBlockingWriteAndFlush(handle, (nint)listPtr, (contents).Length, ptr); + + Result lifted6; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 4), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + } + + } + + public unsafe void BlockingWriteAndFlush(Memory contents) + { + fixed (void* listPtr = contents.Span) + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + BlockingWriteAndFlushWasmInterop.wasmImportBlockingWriteAndFlush(handle, (nint)listPtr, (contents).Length, ptr); + + Result lifted6; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 4), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + } + + } + + internal static class FlushWasmInterop + { + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]output-stream.flush"), WasmImportLinkage] + internal static extern void wasmImportFlush(int p0, nint p1); + } + + public unsafe void Flush() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + FlushWasmInterop.wasmImportFlush(handle, ptr); + + Result lifted6; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 4), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal static class BlockingFlushWasmInterop + { + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]output-stream.blocking-flush"), WasmImportLinkage] + internal static extern void wasmImportBlockingFlush(int p0, nint p1); + } + + public unsafe void BlockingFlush() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + BlockingFlushWasmInterop.wasmImportBlockingFlush(handle, ptr); + + Result lifted6; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 4), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal static class SubscribeWasmInterop + { + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]output-stream.subscribe"), WasmImportLinkage] + internal static extern int wasmImportSubscribe(int p0); + } + + public unsafe global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable Subscribe() + { + var handle = this.Handle; + var result = SubscribeWasmInterop.wasmImportSubscribe(handle); + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result)); + return resource; + + } + + internal static class WriteZeroesWasmInterop + { + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]output-stream.write-zeroes"), WasmImportLinkage] + internal static extern void wasmImportWriteZeroes(int p0, long p1, nint p2); + } + + public unsafe void WriteZeroes(ulong len) + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + WriteZeroesWasmInterop.wasmImportWriteZeroes(handle, unchecked((long)(len)), ptr); + + Result lifted6; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 4), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal static class BlockingWriteZeroesAndFlushWasmInterop + { + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]output-stream.blocking-write-zeroes-and-flush"), WasmImportLinkage] + internal static extern void wasmImportBlockingWriteZeroesAndFlush(int p0, long p1, nint p2); + } + + public unsafe void BlockingWriteZeroesAndFlush(ulong len) + { + var handle = this.Handle; + + var retArea = stackalloc uint[3+1]; + var ptr = ((int)retArea) + (4 - 1) & -4; + BlockingWriteZeroesAndFlushWasmInterop.wasmImportBlockingWriteZeroesAndFlush(handle, unchecked((long)(len)), ptr); + + Result lifted6; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::ComputerWorld.None()); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 4), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal static class SpliceWasmInterop + { + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]output-stream.splice"), WasmImportLinkage] + internal static extern void wasmImportSplice(int p0, int p1, long p2, nint p3); + } + + public unsafe ulong Splice(global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.InputStream src, ulong len) + { + var handle = this.Handle; + var handle0 = src.Handle; + + var retArea = stackalloc ulong[2+1]; + var ptr = ((int)retArea) + (8 - 1) & -8; + SpliceWasmInterop.wasmImportSplice(handle, handle0, unchecked((long)(len)), ptr); + + Result lifted7; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted7 = Result.Ok(unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 8), 8))))); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 8), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 12), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 8), 1)[0]}"); + } + + lifted7 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted7.IsOk) + { + var tmp = lifted7.AsOk; + return tmp; + } + else + { + throw new WitException(lifted7.AsErr!, 0); + } + + } + + internal static class BlockingSpliceWasmInterop + { + [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]output-stream.blocking-splice"), WasmImportLinkage] + internal static extern void wasmImportBlockingSplice(int p0, int p1, long p2, nint p3); + } + + public unsafe ulong BlockingSplice(global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.InputStream src, ulong len) + { + var handle = this.Handle; + var handle0 = src.Handle; + + var retArea = stackalloc ulong[2+1]; + var ptr = ((int)retArea) + (8 - 1) & -8; + BlockingSpliceWasmInterop.wasmImportBlockingSplice(handle, handle0, unchecked((long)(len)), ptr); + + Result lifted7; + + switch (new Span((void*)(ptr + 0), 1)[0]) { + case 0: { + + lifted7 = Result.Ok(unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 8), 8))))); + break; + } + case 1: { + + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; + + switch (new Span((void*)(ptr + 8), 1)[0]) { + case 0: { + var resource = new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 12), 4)))); + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.Closed(); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 8), 1)[0]}"); + } + + lifted7 = Result.Err(lifted); + break; + } + + default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); + } + if (lifted7.IsOk) + { + var tmp = lifted7.AsOk; + return tmp; + } + else + { + throw new WitException(lifted7.AsErr!, 0); + } + + } + + } + +} diff --git a/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.PollInterop.cs b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.PollInterop.cs new file mode 100644 index 0000000..d90dbe4 --- /dev/null +++ b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.PollInterop.cs @@ -0,0 +1,57 @@ +// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! +// +#nullable enable + +using System.Runtime.InteropServices; + +namespace ComputerWorld.wit.imports.wasi.io.v0_2_0 +{ + public static class PollInterop { + + internal static class PollWasmInterop + { + [DllImport("wasi:io/poll@0.2.0", EntryPoint = "poll"), WasmImportLinkage] + internal static extern void wasmImportPoll(nint p0, int p1, nint p2); + } + + public static unsafe uint[] Poll(List @in) + { + var cleanups = new List(); + + void* address; + if ((4 * @in.Count) < 1024) { + var retArea = stackalloc uint[(1*@in.Count)+1]; + address = (void*)(((int)retArea) + (4 - 1) & -4); + } + else + { + var bufferSize = 4 * (nuint)@in.Count; + address = NativeMemory.AlignedAlloc(bufferSize, 4); + cleanups.Add(() => NativeMemory.AlignedFree(address)); + } + + for (int index = 0; index < @in.Count; ++index) { + global::ComputerWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable element = @in[index]; + int basePtr = (int)address + (index * 4); + var handle = element.Handle; + BitConverter.TryWriteBytes(new Span((void*)(basePtr + 0), 4), handle); + + } + + var retArea0 = stackalloc uint[2+1]; + var ptr = ((int)retArea0) + (4 - 1) & -4; + PollWasmInterop.wasmImportPoll((int)address, @in.Count, ptr); + + var array = new uint[BitConverter.ToInt32(new Span((void*)(ptr + 4), 4))]; + new Span((void*)(BitConverter.ToInt32(new Span((void*)(ptr + 0), 4))), BitConverter.ToInt32(new Span((void*)(ptr + 4), 4))).CopyTo(new Span(array)); + + foreach (var cleanup in cleanups) + { + cleanup(); + } + return array; + + } + + } +} diff --git a/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.StreamsInterop.cs b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.StreamsInterop.cs new file mode 100644 index 0000000..45f3ce3 --- /dev/null +++ b/samples/calculator/Adder/generated/wit/ComputerWorld.wit.imports.wasi.io.v0_2_0.StreamsInterop.cs @@ -0,0 +1,10 @@ +// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! +// +#nullable enable + +namespace ComputerWorld.wit.imports.wasi.io.v0_2_0 +{ + public static class StreamsInterop { + + } +} diff --git a/samples/calculator/Adder/generated/wit/ComputerWorld_component_type.wit b/samples/calculator/Adder/generated/wit/ComputerWorld_component_type.wit new file mode 100644 index 0000000..28b3a8a --- /dev/null +++ b/samples/calculator/Adder/generated/wit/ComputerWorld_component_type.wit @@ -0,0 +1,276 @@ +package example:calculator; + +interface operations { + add: func(left: s32, right: s32) -> s32; + + to-upper: func(input: string) -> string; + + get-repo: func(owner: string, name: string) -> string; +} + +world computer { + import wasi:io/poll@0.2.0; + import wasi:clocks/monotonic-clock@0.2.0; + import wasi:io/error@0.2.0; + import wasi:io/streams@0.2.0; + import wasi:http/types@0.2.0; + import wasi:http/outgoing-handler@0.2.0; + + export operations; +} +package wasi:io@0.2.0 { + interface poll { + resource pollable { + ready: func() -> bool; + block: func(); + } + + poll: func(in: list>) -> list; + } + interface error { + resource error { + to-debug-string: func() -> string; + } + } + interface streams { + use error.{error}; + use poll.{pollable}; + + variant stream-error { + last-operation-failed(error), + closed, + } + + resource input-stream { + read: func(len: u64) -> result, stream-error>; + blocking-read: func(len: u64) -> result, stream-error>; + skip: func(len: u64) -> result; + blocking-skip: func(len: u64) -> result; + subscribe: func() -> pollable; + } + + resource output-stream { + check-write: func() -> result; + write: func(contents: list) -> result<_, stream-error>; + blocking-write-and-flush: func(contents: list) -> result<_, stream-error>; + flush: func() -> result<_, stream-error>; + blocking-flush: func() -> result<_, stream-error>; + subscribe: func() -> pollable; + write-zeroes: func(len: u64) -> result<_, stream-error>; + blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error>; + splice: func(src: borrow, len: u64) -> result; + blocking-splice: func(src: borrow, len: u64) -> result; + } + } +} + + +package wasi:clocks@0.2.0 { + interface monotonic-clock { + use wasi:io/poll@0.2.0.{pollable}; + + type instant = u64; + + type duration = u64; + + now: func() -> instant; + + resolution: func() -> duration; + + subscribe-instant: func(when: instant) -> pollable; + + subscribe-duration: func(when: duration) -> pollable; + } +} + + +package wasi:http@0.2.0 { + interface types { + use wasi:clocks/monotonic-clock@0.2.0.{duration}; + use wasi:io/streams@0.2.0.{input-stream, output-stream}; + use wasi:io/error@0.2.0.{error as io-error}; + use wasi:io/poll@0.2.0.{pollable}; + + variant method { + get, + head, + post, + put, + delete, + connect, + options, + trace, + patch, + other(string), + } + + variant scheme { + HTTP, + HTTPS, + other(string), + } + + record DNS-error-payload { + rcode: option, + info-code: option, + } + + record TLS-alert-received-payload { + alert-id: option, + alert-message: option, + } + + record field-size-payload { + field-name: option, + field-size: option, + } + + 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, + internal-error(option), + } + + variant header-error { + invalid-syntax, + forbidden, + immutable, + } + + type field-key = string; + + type field-value = list; + + resource fields { + constructor(); + from-list: static func(entries: list>) -> result; + get: func(name: field-key) -> list; + has: func(name: field-key) -> bool; + set: func(name: field-key, value: list) -> result<_, header-error>; + delete: func(name: field-key) -> result<_, header-error>; + append: func(name: field-key, value: field-value) -> result<_, header-error>; + entries: func() -> list>; + clone: func() -> fields; + } + + type headers = fields; + + type trailers = fields; + + resource incoming-request { + method: func() -> method; + path-with-query: func() -> option; + scheme: func() -> option; + authority: func() -> option; + headers: func() -> headers; + consume: func() -> result; + } + + resource outgoing-request { + constructor(headers: headers); + body: func() -> result; + method: func() -> method; + set-method: func(method: method) -> result; + path-with-query: func() -> option; + set-path-with-query: func(path-with-query: option) -> result; + scheme: func() -> option; + set-scheme: func(scheme: option) -> result; + authority: func() -> option; + set-authority: func(authority: option) -> result; + headers: func() -> headers; + } + + resource request-options { + constructor(); + connect-timeout: func() -> option; + set-connect-timeout: func(duration: option) -> result; + first-byte-timeout: func() -> option; + set-first-byte-timeout: func(duration: option) -> result; + between-bytes-timeout: func() -> option; + set-between-bytes-timeout: func(duration: option) -> result; + } + + resource response-outparam { + set: static func(param: response-outparam, response: result); + } + + type status-code = u16; + + resource incoming-response { + status: func() -> status-code; + headers: func() -> headers; + consume: func() -> result; + } + + resource incoming-body { + %stream: func() -> result; + finish: static func(this: incoming-body) -> future-trailers; + } + + resource future-trailers { + subscribe: func() -> pollable; + get: func() -> option, error-code>>>; + } + + resource outgoing-response { + constructor(headers: headers); + status-code: func() -> status-code; + set-status-code: func(status-code: status-code) -> result; + headers: func() -> headers; + body: func() -> result; + } + + resource outgoing-body { + write: func() -> result; + finish: static func(this: outgoing-body, trailers: option) -> result<_, error-code>; + } + + resource future-incoming-response { + subscribe: func() -> pollable; + get: func() -> option>>; + } + + http-error-code: func(err: borrow) -> option; + } + interface outgoing-handler { + use types.{outgoing-request, request-options, future-incoming-response, error-code}; + + handle: func(request: outgoing-request, options: option) -> result; + } +} diff --git a/samples/calculator/Adder/generated/wit/ComputerWorld_wasm_import_linkage_attribute.cs b/samples/calculator/Adder/generated/wit/ComputerWorld_wasm_import_linkage_attribute.cs new file mode 100644 index 0000000..d0aa7d6 --- /dev/null +++ b/samples/calculator/Adder/generated/wit/ComputerWorld_wasm_import_linkage_attribute.cs @@ -0,0 +1,11 @@ +// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! +// +#nullable enable + +#if !NET9_0_OR_GREATER +// temporarily add this attribute until it is available in dotnet 9 +namespace System.Runtime.InteropServices +{ + internal partial class WasmImportLinkageAttribute : Attribute {} +} +#endif diff --git a/samples/calculator/Adder/generated/wit/lastbuild.txt b/samples/calculator/Adder/generated/wit/lastbuild.txt new file mode 100644 index 0000000..e69de29 diff --git a/samples/calculator/Adder/policy.yaml b/samples/calculator/Adder/policy.yaml new file mode 100644 index 0000000..50b9e49 --- /dev/null +++ b/samples/calculator/Adder/policy.yaml @@ -0,0 +1,6 @@ +version: "1.0" +description: "Permission policy for calculator sample GitHub repo metadata fetch" +permissions: + network: + allow: + - host: "api.github.com" diff --git a/samples/calculator/Adder/wit/calculator.wit b/samples/calculator/Adder/wit/calculator.wit new file mode 100644 index 0000000..92788e4 --- /dev/null +++ b/samples/calculator/Adder/wit/calculator.wit @@ -0,0 +1,16 @@ +package example:calculator; + +interface operations { + add: func(left: s32, right: s32) -> s32; + to-upper: func(input: string) -> string; + get-repo: func(owner: string, name: string) -> string; +} + +world computer { + import wasi:http/outgoing-handler@0.2.0; + export operations; +} + +world hostapp { + import operations; +} diff --git a/samples/calculator/Adder/wit/deps/wasi-cli-0.2.0/package.wit b/samples/calculator/Adder/wit/deps/wasi-cli-0.2.0/package.wit new file mode 100644 index 0000000..8deef32 --- /dev/null +++ b/samples/calculator/Adder/wit/deps/wasi-cli-0.2.0/package.wit @@ -0,0 +1,20 @@ +package wasi:cli@0.2.0; + +interface stdout { + use wasi:io/streams@0.2.0.{output-stream}; + + get-stdout: func() -> output-stream; +} + +interface stderr { + use wasi:io/streams@0.2.0.{output-stream}; + + get-stderr: func() -> output-stream; +} + +interface stdin { + use wasi:io/streams@0.2.0.{input-stream}; + + get-stdin: func() -> input-stream; +} + diff --git a/samples/calculator/Adder/wit/deps/wasi-clocks-0.2.0/package.wit b/samples/calculator/Adder/wit/deps/wasi-clocks-0.2.0/package.wit new file mode 100644 index 0000000..9e0ba3d --- /dev/null +++ b/samples/calculator/Adder/wit/deps/wasi-clocks-0.2.0/package.wit @@ -0,0 +1,29 @@ +package wasi:clocks@0.2.0; + +interface monotonic-clock { + use wasi:io/poll@0.2.0.{pollable}; + + type instant = u64; + + type duration = u64; + + now: func() -> instant; + + resolution: func() -> duration; + + subscribe-instant: func(when: instant) -> pollable; + + subscribe-duration: func(when: duration) -> pollable; +} + +interface wall-clock { + record datetime { + seconds: u64, + nanoseconds: u32, + } + + now: func() -> datetime; + + resolution: func() -> datetime; +} + diff --git a/samples/calculator/Adder/wit/deps/wasi-http-0.2.0/package.wit b/samples/calculator/Adder/wit/deps/wasi-http-0.2.0/package.wit new file mode 100644 index 0000000..11f7ff4 --- /dev/null +++ b/samples/calculator/Adder/wit/deps/wasi-http-0.2.0/package.wit @@ -0,0 +1,571 @@ +package wasi:http@0.2.0; + +/// 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. +interface types { + use wasi:clocks/monotonic-clock@0.2.0.{duration}; + use wasi:io/streams@0.2.0.{input-stream, output-stream}; + use wasi:io/error@0.2.0.{error as io-error}; + use wasi:io/poll@0.2.0.{pollable}; + + /// This type corresponds to HTTP standard Methods. + variant method { + get, + head, + post, + put, + delete, + connect, + options, + trace, + patch, + other(string), + } + + /// This type corresponds to HTTP standard Related Schemes. + variant scheme { + HTTP, + HTTPS, + other(string), + } + + /// Defines the case payload type for `DNS-error` above: + record DNS-error-payload { + rcode: option, + info-code: option, + } + + /// Defines the case payload type for `TLS-alert-received` above: + record TLS-alert-received-payload { + alert-id: option, + alert-message: option, + } + + /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: + record field-size-payload { + field-name: option, + field-size: option, + } + + /// These cases are inspired by the IANA HTTP Proxy Error Types: + /// https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types + 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. + variant header-error { + /// This error indicates that a `field-key` 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-key` 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. + type field-key = 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 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 be + /// immutable. In an immutable fields, the `set`, `append`, and `delete` + /// operations will fail with `header-error.immutable`. + 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 key-value pair in the Fields. Keys + /// which have multiple values are represented by multiple entries in this + /// list with the same key. + /// + /// The tuple is a pair of the field key, represented as a string, and + /// Value, represented as a list of bytes. In a valid Fields, all keys + /// 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, or if a header was forbidden. + from-list: static func(entries: list>) -> result; + /// Get all of the values corresponding to a key. If the key is not present + /// in this `fields`, an empty list is returned. However, if the key is + /// present but empty, this is represented by a list with one or more + /// empty field-values present. + get: func(name: field-key) -> list; + /// Returns `true` when the key is present in this `fields`. If the key is + /// syntactically invalid, `false` is returned. + has: func(name: field-key) -> bool; + /// Set all of the values for a key. Clears any existing values for that + /// key, if they have been set. + /// + /// Fails with `header-error.immutable` if the `fields` are immutable. + set: func(name: field-key, value: list) -> result<_, header-error>; + /// Delete all values for a key. Does nothing if no values for the key + /// exist. + /// + /// Fails with `header-error.immutable` if the `fields` are immutable. + delete: func(name: field-key) -> result<_, header-error>; + /// Append a value for a key. Does not change or delete any existing + /// values for that key. + /// + /// Fails with `header-error.immutable` if the `fields` are immutable. + append: func(name: field-key, value: field-value) -> result<_, header-error>; + /// Retrieve the full set of keys and values in the Fields. Like the + /// constructor, the list represents each key-value pair. + /// + /// The outer list represents each key-value pair in the Fields. Keys + /// which have multiple values are represented by multiple entries in this + /// list with the same key. + entries: func() -> list>; + /// Make a deep copy of the Fields. Equivelant in behavior to calling the + /// `fields` constructor on the return value of `entries`. The resulting + /// `fields` is mutable. + clone: func() -> fields; + } + + /// Headers is an alias for Fields. + type headers = fields; + + /// Trailers is an alias for Fields. + type trailers = fields; + + /// Represents an incoming HTTP Request. + resource incoming-request { + /// Returns the method of the incoming request. + method: func() -> method; + /// Returns the path with query parameters from the request, as a string. + path-with-query: func() -> option; + /// Returns the protocol scheme from the request. + scheme: func() -> option; + /// Returns the authority from the request, if it was present. + 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. + headers: func() -> headers; + /// Gives the `incoming-body` associated with this request. Will only + /// return success at most once, and subsequent calls will return error. + consume: func() -> result; + } + + /// Represents an outgoing HTTP Request. + 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`. + 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. + body: func() -> result; + /// Get the Method for the Request. + 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. + 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. + 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 HTTP Authority for the Request. 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. + authority: func() -> option; + /// Set the HTTP Authority for the Request. 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 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 transfered to + /// another component by e.g. `outgoing-handler.handle`. + 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`. + resource request-options { + /// Construct a default `request-options` value. + constructor(); + /// The timeout for the initial connect to the HTTP Server. + 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. + set-connect-timeout: func(duration: option) -> result; + /// The timeout for receiving the first byte of the Response body. + 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. + set-first-byte-timeout: func(duration: option) -> result; + /// The timeout for receiving subsequent chunks of bytes in the Response + /// body stream. + 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. + 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`. + resource response-outparam { + /// 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. + set: static func(param: response-outparam, response: result); + } + + /// This type corresponds to the HTTP standard Status Code. + type status-code = u16; + + /// Represents an incoming HTTP Response. + resource incoming-response { + /// Returns the status code from the incoming response. + 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. + headers: func() -> headers; + /// Returns the incoming body. May be called at most once. Returns error + /// if called additional times. + 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. + 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. + %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. + finish: static func(this: incoming-body) -> future-trailers; + } + + /// Represents a future which may eventaully 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. + resource future-trailers { + /// Returns a pollable which becomes ready when either the trailers have + /// been received, or an error has occured. When this pollable is ready, + /// the `get` method will return `some`. + subscribe: func() -> pollable; + /// Returns the contents of the trailers, or an error which occured, + /// 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 occured 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. + get: func() -> option, error-code>>>; + } + + /// Represents an outgoing HTTP Response. + 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. + constructor(headers: headers); + /// Get the HTTP Status Code for the Response. + 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 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 transfered to + /// another component by e.g. `outgoing-handler.handle`. + 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. + 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 occured. The implementation should propogate 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. + 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. + 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. + finish: static func(this: outgoing-body, trailers: option) -> result<_, error-code>; + } + + /// Represents a future which may eventaully 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. + resource future-incoming-response { + /// Returns a pollable which becomes ready when either the Response has + /// been received, or an error has occured. When this pollable is ready, + /// the `get` method will return `some`. + 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 recieved successfully, or that an error + /// occured. Errors may also occur while consuming the response body, + /// but those will be reported by the `incoming-body` and its + /// `output-stream` child. + 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. + 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. +interface incoming-handler { + 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. + 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. +interface outgoing-handler { + 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`. + handle: func(request: outgoing-request, options: option) -> result; +} + +/// 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. +world proxy { + import wasi:random/random@0.2.0; + import wasi:io/error@0.2.0; + import wasi:io/poll@0.2.0; + import wasi:io/streams@0.2.0; + import wasi:cli/stdout@0.2.0; + import wasi:cli/stderr@0.2.0; + import wasi:cli/stdin@0.2.0; + import wasi:clocks/monotonic-clock@0.2.0; + import types; + import outgoing-handler; + import wasi:clocks/wall-clock@0.2.0; + + export incoming-handler; +} diff --git a/samples/calculator/Adder/wit/deps/wasi-io-0.2.0/package.wit b/samples/calculator/Adder/wit/deps/wasi-io-0.2.0/package.wit new file mode 100644 index 0000000..962734d --- /dev/null +++ b/samples/calculator/Adder/wit/deps/wasi-io-0.2.0/package.wit @@ -0,0 +1,48 @@ +package wasi:io@0.2.0; + +interface poll { + resource pollable { + ready: func() -> bool; + block: func(); + } + + poll: func(in: list>) -> list; +} + +interface error { + resource error { + to-debug-string: func() -> string; + } +} + +interface streams { + use error.{error}; + use poll.{pollable}; + + variant stream-error { + last-operation-failed(error), + closed, + } + + resource input-stream { + read: func(len: u64) -> result, stream-error>; + blocking-read: func(len: u64) -> result, stream-error>; + skip: func(len: u64) -> result; + blocking-skip: func(len: u64) -> result; + subscribe: func() -> pollable; + } + + resource output-stream { + check-write: func() -> result; + write: func(contents: list) -> result<_, stream-error>; + blocking-write-and-flush: func(contents: list) -> result<_, stream-error>; + flush: func() -> result<_, stream-error>; + blocking-flush: func() -> result<_, stream-error>; + subscribe: func() -> pollable; + write-zeroes: func(len: u64) -> result<_, stream-error>; + blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error>; + splice: func(src: borrow, len: u64) -> result; + blocking-splice: func(src: borrow, len: u64) -> result; + } +} + diff --git a/samples/calculator/Adder/wit/deps/wasi-random-0.2.0/package.wit b/samples/calculator/Adder/wit/deps/wasi-random-0.2.0/package.wit new file mode 100644 index 0000000..4132731 --- /dev/null +++ b/samples/calculator/Adder/wit/deps/wasi-random-0.2.0/package.wit @@ -0,0 +1,8 @@ +package wasi:random@0.2.0; + +interface random { + get-random-bytes: func(len: u64) -> list; + + get-random-u64: func() -> u64; +} + diff --git a/samples/calculator/Adder/wkg.lock b/samples/calculator/Adder/wkg.lock new file mode 100644 index 0000000..c9637ea --- /dev/null +++ b/samples/calculator/Adder/wkg.lock @@ -0,0 +1,12 @@ +# This file is automatically generated. +# It is not intended for manual editing. +version = 1 + +[[packages]] +name = "wasi:http" +registry = "wasi.dev" + +[[packages.versions]] +requirement = "=0.2.0" +version = "0.2.0" +digest = "sha256:5a568e6e2d60c1ce51220e1833cdd5b88db9f615720edc762a9b4a6f36b383bd" diff --git a/samples/calculator/CalculatorComposed/CalculatorComposed.csproj b/samples/calculator/CalculatorComposed/CalculatorComposed.csproj index 786cffc..8eb4783 100644 --- a/samples/calculator/CalculatorComposed/CalculatorComposed.csproj +++ b/samples/calculator/CalculatorComposed/CalculatorComposed.csproj @@ -19,7 +19,8 @@ ../CalculatorHost/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/CalculatorHost.wasm - ../Adder/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/adder.wasm + + ../Adder/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/adder2.wasm diff --git a/samples/calculator/CalculatorHost/CalculatorHost.csproj b/samples/calculator/CalculatorHost/CalculatorHost.csproj index ab2c1a8..603dd73 100644 --- a/samples/calculator/CalculatorHost/CalculatorHost.csproj +++ b/samples/calculator/CalculatorHost/CalculatorHost.csproj @@ -18,7 +18,8 @@ - + + diff --git a/samples/calculator/CalculatorHost/Program.cs b/samples/calculator/CalculatorHost/Program.cs index 9c5a12f..b276037 100644 --- a/samples/calculator/CalculatorHost/Program.cs +++ b/samples/calculator/CalculatorHost/Program.cs @@ -6,3 +6,15 @@ Console.WriteLine($"{left} + {right} = {result}"); Console.WriteLine(OperationsInterop.ToUpper("Hello, World!")); + +// Invoke GetRepo for a known repository (no environment variables required) +const string repoOwner = "bytecodealliance"; +const string repoName = "componentize-dotnet"; +try { + var repoJson = OperationsInterop.GetRepo(repoOwner, repoName); + Console.WriteLine("GetRepo JSON:"); + Console.WriteLine(string.IsNullOrEmpty(repoJson) ? "" : repoJson); +} catch (Exception ex) { + Console.Error.WriteLine($"GetRepo failed: {ex.Message}"); + Environment.ExitCode = 1; // propagate failure so outer script can detect +} diff --git a/samples/calculator/run.ps1 b/samples/calculator/run.ps1 new file mode 100644 index 0000000..1a6f15d --- /dev/null +++ b/samples/calculator/run.ps1 @@ -0,0 +1,23 @@ +# builds and runs the calculator sample +set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' +# requires wasmtime with wasi and http support +# winget install --id BytecodeAlliance.Wasmtime +# +# Optional: set GITHUB_OWNER and GITHUB_REPO to fetch a specific repository's JSON metadata. +# Defaults (if unset): bytecodealliance / componentize-dotnet + +# Build the component projects (Adder provides the implementation; CalculatorComposed composes host + adder) +Write-Host "Building Adder..." -ForegroundColor Cyan +dotnet build $PSScriptRoot\Adder | Write-Host +Write-Host "Building CalculatorComposed (will compose wasm)..." -ForegroundColor Cyan +dotnet build $PSScriptRoot\CalculatorComposed | Write-Host +if (-not (Test-Path "$PSScriptRoot\CalculatorComposed\dist\calculator.wasm")) { + Write-Error "Composition failed: dist/calculator.wasm not found" +} + +# Run with wasmtime (needs http since GetRepo performs an outbound HTTP GET) +$wasm = "$PSScriptRoot\CalculatorComposed\dist\calculator.wasm" +Write-Host "Running component: $wasm" -ForegroundColor Green +wasmtime --wasi http $wasm +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }