diff --git a/eng/AcquireWasiSdk.targets b/eng/AcquireWasiSdk.targets index 51c0e62ef45d97..16590baeb74974 100644 --- a/eng/AcquireWasiSdk.targets +++ b/eng/AcquireWasiSdk.targets @@ -7,7 +7,7 @@ --> - <_WasiSdkVersion>25.0 + <_WasiSdkVersion>33.0 <_RuntimeLocalWasiSdkPath>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'wasi-sdk')) diff --git a/eng/native/gen-buildsys.cmd b/eng/native/gen-buildsys.cmd index 2ab07a1db1345b..be24e7f106a0ae 100644 --- a/eng/native/gen-buildsys.cmd +++ b/eng/native/gen-buildsys.cmd @@ -70,7 +70,7 @@ if /i "%__Arch%" == "wasm" ( set "WASI_SDK_PATH=%__repoRoot%\artifacts\wasi-sdk" ) set __CmakeGenerator=Ninja - set __ExtraCmakeParams=%__ExtraCmakeParams% -DCLR_CMAKE_TARGET_OS=wasi "-DCMAKE_TOOLCHAIN_FILE=!WASI_SDK_PATH!/share/cmake/wasi-sdk-p2.cmake" "-DCMAKE_CROSSCOMPILING_EMULATOR=node --experimental-wasm-bigint --experimental-wasi-unstable-preview1" + set __ExtraCmakeParams=%__ExtraCmakeParams% -DCLR_CMAKE_TARGET_OS=wasi "-DCMAKE_TOOLCHAIN_FILE=!WASI_SDK_PATH!/share/cmake/wasi-sdk-p2.cmake" ) ) else ( set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_SYSTEM_VERSION=10.0" diff --git a/eng/native/gen-buildsys.sh b/eng/native/gen-buildsys.sh index 8eb73ef7ac2dbf..d9a2b6ccb90823 100755 --- a/eng/native/gen-buildsys.sh +++ b/eng/native/gen-buildsys.sh @@ -115,7 +115,7 @@ if [[ "$host_arch" == "wasm" ]]; then exit 1 fi fi - cmake_extra_defines_wasm=("-DCLR_CMAKE_TARGET_OS=wasi" "-DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk-p2.cmake" "-DCMAKE_CROSSCOMPILING_EMULATOR=node --experimental-wasm-bigint --experimental-wasi-unstable-preview1") + cmake_extra_defines_wasm=("-DCLR_CMAKE_TARGET_OS=wasi" "-DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk-p2.cmake") else echo "target_os was not specified" exit 1 diff --git a/eng/testing/tests.wasi.targets b/eng/testing/tests.wasi.targets index 5c53d1db11d186..ec824fe2f52f3d 100644 --- a/eng/testing/tests.wasi.targets +++ b/eng/testing/tests.wasi.targets @@ -50,6 +50,7 @@ <_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--wasi --engine-arg=tcp <_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--wasi --engine-arg=udp <_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--wasi --engine-arg=allow-ip-name-lookup + <_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--wasi --engine-arg=hostcall-fuel=4294967295 <_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--env --engine-arg=DOTNET_WASI_PRINT_EXIT_CODE=1 <_XHarnessArgs Condition="'$(WasmXHarnessArgsCli)' != ''" >$(_XHarnessArgs) $(WasmXHarnessArgsCli) @@ -87,6 +88,13 @@ true + + true + PrepareForWasiBuildApp;$(WasmNestedPublishAppDependsOn) diff --git a/src/libraries/Common/src/Interop/Wasi/System.Native/Interop.SocketEvent.cs b/src/libraries/Common/src/Interop/Wasi/System.Native/Interop.SocketEvent.cs index 2e8742bc4c7708..5cbffad3de78e5 100644 --- a/src/libraries/Common/src/Interop/Wasi/System.Native/Interop.SocketEvent.cs +++ b/src/libraries/Common/src/Interop/Wasi/System.Native/Interop.SocketEvent.cs @@ -20,6 +20,9 @@ internal enum SocketEvents : int } [LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetWasiSocketDescriptor")] - internal static unsafe partial Error GetWasiSocketDescriptor(IntPtr socket, IntPtr* entry); + internal static unsafe partial Error GetWasiSocketDescriptor(IntPtr socket, IntPtr* entry, int* socketType); + + [LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_WasiSubscribeSocketPollable")] + internal static partial int WasiSubscribeSocketPollable(int kind, int handle); } } diff --git a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Authentication.cs b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Authentication.cs index 7e3b1b0fbb1c7a..0e9ad347e1a915 100644 --- a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Authentication.cs +++ b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Authentication.cs @@ -45,6 +45,7 @@ public HttpClientHandler_Authentication_Test(ITestOutputHelper output) : base(ou [Theory] [MemberData(nameof(Authentication_SocketsHttpHandler_TestData))] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI HttpHandler does not support authentication")] public async Task SocketsHttpHandler_Authentication_Succeeds(string authenticateHeader, bool result) { await HttpClientHandler_Authentication_Succeeds(authenticateHeader, result); @@ -106,6 +107,7 @@ public static IEnumerable Authentication_SocketsHttpHandler_TestData() [Theory] [MemberData(nameof(Authentication_TestData))] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI HttpHandler does not support authentication")] public async Task HttpClientHandler_Authentication_Succeeds(string authenticateHeader, bool result) { if (PlatformDetection.IsWindowsNanoServer) @@ -132,6 +134,7 @@ await TestHelper.WhenAllCompletedOrAnyFailedWithTimeout(TestHelper.PassingTestTi [InlineData("WWW-Authenticate: Basic realm=\"hello\"\r\nWWW-Authenticate: Basic realm=\"hello\"\r\n")] [InlineData("WWW-Authenticate: Digest realm=\"hello\", nonce=\"hello\", algorithm=MD5\r\nWWW-Authenticate: Digest realm=\"hello\", nonce=\"hello\", algorithm=MD5\r\n")] [InlineData("WWW-Authenticate: Digest realm=\"hello1\", nonce=\"hello\", algorithm=MD5\r\nWWW-Authenticate: Digest realm=\"hello\", nonce=\"hello\", algorithm=MD5\r\n")] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI HttpHandler does not support authentication")] public async Task HttpClientHandler_MultipleAuthenticateHeaders_WithSameAuth_Succeeds(string authenticateHeader) { if (IsWinHttpHandler) @@ -145,6 +148,7 @@ public async Task HttpClientHandler_MultipleAuthenticateHeaders_WithSameAuth_Suc [Theory] [InlineData("WWW-Authenticate: Basic realm=\"hello\"\r\nWWW-Authenticate: Digest realm=\"hello\", nonce=\"hello\", algorithm=MD5\r\n")] [InlineData("WWW-Authenticate: Digest realm=\"hello\", nonce=\"hello\", algorithm=MD5\r\nWWW-Authenticate: Basic realm=\"hello\"\r\n")] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI HttpHandler does not support authentication")] public async Task HttpClientHandler_MultipleAuthenticateHeaders_Succeeds(string authenticateHeader) { if (PlatformDetection.IsWindowsNanoServer) @@ -164,6 +168,7 @@ await LoopbackServer.CreateServerAsync(async (server, url) => [Theory] [InlineData("WWW-Authenticate: Basic realm=\"hello\"\r\nWWW-Authenticate: NTLM\r\n", "Basic", "Negotiate")] [InlineData("WWW-Authenticate: Basic realm=\"hello\"\r\nWWW-Authenticate: Digest realm=\"hello\", nonce=\"hello\", algorithm=MD5\r\nWWW-Authenticate: NTLM\r\n", "Digest", "Negotiate")] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI HttpHandler does not support authentication")] public async Task HttpClientHandler_MultipleAuthenticateHeaders_PicksSupported(string authenticateHeader, string supportedAuth, string unsupportedAuth) { if (PlatformDetection.IsWindowsNanoServer) @@ -189,6 +194,7 @@ await LoopbackServer.CreateServerAsync(async (server, url) => [Theory] [InlineData("WWW-Authenticate: Basic realm=\"hello\"\r\n")] [InlineData("WWW-Authenticate: Digest realm=\"hello\", nonce=\"testnonce\"\r\n")] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI HttpHandler does not support authentication")] public async Task HttpClientHandler_IncorrectCredentials_Fails(string authenticateHeader) { var options = new LoopbackServer.Options { Domain = Domain, Username = Username, Password = Password }; @@ -226,6 +232,7 @@ public static IEnumerable Authentication_TestData() [InlineData("NTLM")] [InlineData("Kerberos")] [InlineData("Negotiate")] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI HttpHandler does not support PreAuthenticate")] public async Task PreAuthenticate_NoPreviousAuthenticatedRequests_NoCredentialsSent(string? credCacheScheme) { const int NumRequests = 3; @@ -268,6 +275,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => [Theory] [InlineData(null, "WWW-Authenticate: Basic realm=\"hello\"\r\n")] [InlineData("Basic", "WWW-Authenticate: Basic realm=\"hello\"\r\n")] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI HttpHandler does not support PreAuthenticate")] public async Task PreAuthenticate_FirstRequestNoHeaderAndAuthenticates_SecondRequestPreauthenticates(string? credCacheScheme, string authResponse) { await LoopbackServer.CreateClientAndServerAsync(async uri => @@ -360,6 +368,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => [InlineData((HttpStatusCode)508)] // LoopDetected [InlineData((HttpStatusCode)510)] // NotExtended [InlineData((HttpStatusCode)511)] // NetworkAuthenticationRequired + [SkipOnPlatform(TestPlatforms.Wasi, "WASI HttpHandler does not support PreAuthenticate")] public async Task PreAuthenticate_FirstRequestNoHeader_SecondRequestVariousStatusCodes_ThirdRequestPreauthenticates(HttpStatusCode statusCode) { const string AuthResponse = "WWW-Authenticate: Basic realm=\"hello\"\r\n"; @@ -403,6 +412,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => [InlineData("/something/hello.html", "/world.html", false)] [InlineData("/something/hello.html", "/another/", false)] [InlineData("/something/hello.html", "/another/hello.html", false)] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI HttpHandler does not support PreAuthenticate")] public async Task PreAuthenticate_AuthenticatedUrl_ThenTryDifferentUrl_SendsAuthHeaderOnlyIfPrefixMatches( string originalRelativeUri, string secondRelativeUri, bool expectedAuthHeader) { @@ -442,6 +452,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI HttpHandler does not support PreAuthenticate")] public async Task PreAuthenticate_SuccessfulBasicButThenFails_DoesntLoopInfinitely() { await LoopbackServer.CreateClientAndServerAsync(async uri => @@ -480,6 +491,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI HttpHandler does not support PreAuthenticate")] public async Task PreAuthenticate_SuccessfulBasic_ThenDigestChallenged() { if (IsWinHttpHandler) diff --git a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Proxy.cs b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Proxy.cs index 82b67f978bcc3d..6d97144544bf23 100644 --- a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Proxy.cs +++ b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Proxy.cs @@ -27,6 +27,7 @@ public abstract class HttpClientHandler_Proxy_Test : HttpClientHandlerTestBase public HttpClientHandler_Proxy_Test(ITestOutputHelper output) : base(output) { } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI HttpHandler does not support proxy")] public async Task Dispose_HandlerWithProxy_ProxyNotDisposed() { if (IsWinHttpHandler && UseVersion >= HttpVersion20.Value) @@ -655,6 +656,7 @@ await LoopbackServer.CreateClientAndServerAsync(async proxyUri => [Theory] [InlineData(true)] [InlineData(false)] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI HttpHandler does not support proxy")] public async Task ProxyTunnelRequest_UserAgentHeaderAdded(bool addUserAgentHeader) { if (IsWinHttpHandler) diff --git a/src/libraries/System.Net.Http/src/System.Net.Http.csproj b/src/libraries/System.Net.Http/src/System.Net.Http.csproj index 06c5430d2db5c7..f973fa8499005b 100644 --- a/src/libraries/System.Net.Http/src/System.Net.Http.csproj +++ b/src/libraries/System.Net.Http/src/System.Net.Http.csproj @@ -457,16 +457,18 @@ - - - - - - - - - - + + + + + + + + + + + + diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttp.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttp.cs index 3d63d27d73d9cf..50869d93dd0b0f 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttp.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttp.cs @@ -1,24 +1,22 @@ -// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! // #nullable enable + using System; -using System.Runtime.CompilerServices; -using System.Collections; using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; +using System.Collections.Concurrent; +using System.Threading; +using System.Threading.Tasks; namespace WasiHttpWorld { - internal interface IWasiHttpWorld { + internal interface IWasiHttpWorldImports{ } internal readonly struct None {} - [StructLayout(LayoutKind.Sequential)] - internal readonly struct Result + [global::System.Runtime.InteropServices.StructLayoutAttribute(global::System.Runtime.InteropServices.LayoutKind.Sequential)] + internal readonly struct Result { internal readonly byte Tag; private readonly object value; @@ -29,47 +27,54 @@ private Result(byte tag, object value) this.value = value; } - internal static Result ok(Ok ok) + internal static Result Ok(TOk ok) { - return new Result(OK, ok!); + return new Result(Tags.Ok, ok!); } - internal static Result err(Err err) + internal static Result Err(TErr err) { - return new Result(ERR, err!); + return new Result(Tags.Err, err!); } - internal bool IsOk => Tag == OK; - internal bool IsErr => Tag == ERR; + internal bool IsOk => Tag == Tags.Ok; + internal bool IsErr => Tag == Tags.Err; - internal Ok AsOk + internal TOk AsOk { get { - if (Tag == OK) - return (Ok)value; - else - throw new ArgumentException("expected OK, got " + Tag); + if (Tag == Tags.Ok) + { + return (TOk)value; + } + + throw new global::System.ArgumentException("expected k, got " + Tag); } } - internal Err AsErr + internal TErr AsErr { get { - if (Tag == ERR) - return (Err)value; - else - throw new ArgumentException("expected ERR, got " + Tag); + if (Tag == Tags.Err) + { + return (TErr)value; + } + + throw new global::System.ArgumentException("expected Err, got " + Tag); } } - internal const byte OK = 0; - internal const byte ERR = 1; + internal class Tags + { + internal const byte Ok = 0; + internal const byte Err = 1; + } } internal class Option { - private static Option none = new(); + private static Option none = new (); private Option() { @@ -84,24 +89,13 @@ internal Option(T v) internal static Option None => none; - [MemberNotNullWhen(true, nameof(Value))] + [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute(true, nameof(Value))] internal bool HasValue { get; } internal T? Value { get; } } - internal static class InteropString - { - internal static IntPtr FromString(string input, out int length) - { - var utf8Bytes = Encoding.UTF8.GetBytes(input); - length = utf8Bytes.Length; - var gcHandle = GCHandle.Alloc(utf8Bytes, GCHandleType.Pinned); - return gcHandle.AddrOfPinnedObject(); - } - } - - internal class WitException: Exception { + internal class WitException: global::System.Exception { internal object Value { get; } internal uint NestingLevel { get; } @@ -112,10 +106,25 @@ internal WitException(object v, uint level) } } - namespace exports { - internal static class WasiHttpWorld + internal class WitException: WitException { + internal T TypedValue { get { return (T)this.Value;} } + + internal WitException(T v, uint level) : base(v!, level) { } } + internal static class MemoryHelper + { + internal static unsafe void* AlignStackPtr(void* stackAddress, uint alignment) + { + return (void*)(((nint)stackAddress) + ((int)alignment - 1) & -(int)alignment); + } + } + + namespace Imports { + internal partial class WasiHttpWorldImportsInterop : IWasiHttpWorldImports + {} + } + } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpHandler.cs index e4fd54308d9bfe..7f7c66ed2f9970 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpHandler.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpHandler.cs @@ -12,9 +12,9 @@ using System.Threading; using System.Threading.Tasks; using WasiHttpWorld; -using WasiHttpWorld.wit.imports.wasi.http.v0_2_0; -using WasiHttpWorld.wit.imports.wasi.io.v0_2_0; -using static WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes; +using WasiHttpWorld.wit.Imports.wasi.http.v0_2_8; +using WasiHttpWorld.wit.Imports.wasi.io.v0_2_8; +using static WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports; namespace System.Net.Http { @@ -48,7 +48,7 @@ public async Task SendRequestAsync(HttpRequestMessage reque #pragma warning restore CA2025 #pragma warning restore CS4014 - future = OutgoingHandlerInterop.Handle(outgoingRequest, null); + future = IOutgoingHandlerImports.Handle(outgoingRequest, null); using var incomingResponse = await SendRequest(cancellationToken).ConfigureAwait(false); diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpInterop.cs index c99f3281492b0f..0d1c50b93e5798 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpInterop.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpInterop.cs @@ -11,16 +11,16 @@ using System.Threading; using System.Threading.Tasks; using WasiHttpWorld; -using WasiHttpWorld.wit.imports.wasi.http.v0_2_0; -using WasiHttpWorld.wit.imports.wasi.io.v0_2_0; -using static WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes; -using static WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams; +using WasiHttpWorld.wit.Imports.wasi.http.v0_2_8; +using WasiHttpWorld.wit.Imports.wasi.io.v0_2_8; +using static WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports; +using static WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports; namespace System.Net.Http { internal static class WasiHttpInterop { - public static Task RegisterWasiPollable(IPoll.Pollable pollable, CancellationToken cancellationToken) + public static Task RegisterWasiPollable(IPollImports.Pollable pollable, CancellationToken cancellationToken) { var handle = pollable.Handle; @@ -42,34 +42,34 @@ public static Method ConvertMethod(HttpMethod requestMethod) { case "": case "GET": - method = Method.get(); + method = Method.Get(); break; case "HEAD": - method = Method.head(); + method = Method.Head(); break; case "POST": - method = Method.post(); + method = Method.Post(); break; case "PUT": - method = Method.put(); + method = Method.Put(); break; case "DELETE": - method = Method.delete(); + method = Method.Delete(); break; case "CONNECT": - method = Method.connect(); + method = Method.Connect(); break; case "OPTIONS": - method = Method.options(); + method = Method.Options(); break; case "TRACE": - method = Method.trace(); + method = Method.Trace(); break; case "PATCH": - method = Method.patch(); + method = Method.Patch(); break; default: - method = Method.other(requestMethod.Method); + method = Method.Other(requestMethod.Method); break; } return method; @@ -82,13 +82,13 @@ public static Scheme ConvertScheme(Uri uri) { case "": case "http": - scheme = Scheme.http(); + scheme = Scheme.Http(); break; case "https": - scheme = Scheme.https(); + scheme = Scheme.Https(); break; default: - scheme = Scheme.other(uri.Scheme); + scheme = Scheme.Other(uri.Scheme); break; } return scheme; @@ -150,11 +150,11 @@ private static string HeaderErrorToString(HeaderError error) { switch (error.Tag) { - case ITypes.HeaderError.INVALID_SYNTAX: + case HeaderError.Tags.InvalidSyntax: return "INVALID_SYNTAX"; - case ITypes.HeaderError.FORBIDDEN: + case HeaderError.Tags.Forbidden: return "FORBIDDEN"; - case ITypes.HeaderError.IMMUTABLE: + case HeaderError.Tags.Immutable: return "IMMUTABLE"; default: return $"{error.Tag}"; @@ -188,121 +188,121 @@ public static string ErrorCodeToString(ErrorCode code) // TODO: include payload data in result where applicable switch (code.Tag) { - case ErrorCode.DNS_TIMEOUT: + case ErrorCode.Tags.DnsTimeout: return "DNS_TIMEOUT"; - case ErrorCode.DNS_ERROR: + case ErrorCode.Tags.DnsError: return "DNS_ERROR"; - case ErrorCode.DESTINATION_NOT_FOUND: + case ErrorCode.Tags.DestinationNotFound: return "DESTINATION_NOT_FOUND"; - case ErrorCode.DESTINATION_UNAVAILABLE: + case ErrorCode.Tags.DestinationUnavailable: return "DESTINATION_UNAVAILABLE"; - case ErrorCode.DESTINATION_IP_PROHIBITED: + case ErrorCode.Tags.DestinationIpProhibited: return "DESTINATION_IP_PROHIBITED"; - case ErrorCode.DESTINATION_IP_UNROUTABLE: + case ErrorCode.Tags.DestinationIpUnroutable: return "DESTINATION_IP_UNROUTABLE"; - case ErrorCode.CONNECTION_REFUSED: + case ErrorCode.Tags.ConnectionRefused: return "CONNECTION_REFUSED"; - case ErrorCode.CONNECTION_TERMINATED: + case ErrorCode.Tags.ConnectionTerminated: return "CONNECTION_TERMINATED"; - case ErrorCode.CONNECTION_TIMEOUT: + case ErrorCode.Tags.ConnectionTimeout: return "CONNECTION_TIMEOUT"; - case ErrorCode.CONNECTION_READ_TIMEOUT: + case ErrorCode.Tags.ConnectionReadTimeout: return "CONNECTION_READ_TIMEOUT"; - case ErrorCode.CONNECTION_WRITE_TIMEOUT: + case ErrorCode.Tags.ConnectionWriteTimeout: return "CONNECTION_WRITE_TIMEOUT"; - case ErrorCode.CONNECTION_LIMIT_REACHED: + case ErrorCode.Tags.ConnectionLimitReached: return "CONNECTION_LIMIT_REACHED"; - case ErrorCode.TLS_PROTOCOL_ERROR: + case ErrorCode.Tags.TlsProtocolError: return "TLS_PROTOCOL_ERROR"; - case ErrorCode.TLS_CERTIFICATE_ERROR: + case ErrorCode.Tags.TlsCertificateError: return "TLS_CERTIFICATE_ERROR"; - case ErrorCode.TLS_ALERT_RECEIVED: + case ErrorCode.Tags.TlsAlertReceived: return "TLS_ALERT_RECEIVED"; - case ErrorCode.HTTP_REQUEST_DENIED: + case ErrorCode.Tags.HttpRequestDenied: return "HTTP_REQUEST_DENIED"; - case ErrorCode.HTTP_REQUEST_LENGTH_REQUIRED: + case ErrorCode.Tags.HttpRequestLengthRequired: return "HTTP_REQUEST_LENGTH_REQUIRED"; - case ErrorCode.HTTP_REQUEST_BODY_SIZE: + case ErrorCode.Tags.HttpRequestBodySize: return "HTTP_REQUEST_BODY_SIZE"; - case ErrorCode.HTTP_REQUEST_METHOD_INVALID: + case ErrorCode.Tags.HttpRequestMethodInvalid: return "HTTP_REQUEST_METHOD_INVALID"; - case ErrorCode.HTTP_REQUEST_URI_INVALID: + case ErrorCode.Tags.HttpRequestUriInvalid: return "HTTP_REQUEST_URI_INVALID"; - case ErrorCode.HTTP_REQUEST_URI_TOO_LONG: + case ErrorCode.Tags.HttpRequestUriTooLong: return "HTTP_REQUEST_URI_TOO_LONG"; - case ErrorCode.HTTP_REQUEST_HEADER_SECTION_SIZE: + case ErrorCode.Tags.HttpRequestHeaderSectionSize: return "HTTP_REQUEST_HEADER_SECTION_SIZE"; - case ErrorCode.HTTP_REQUEST_HEADER_SIZE: + case ErrorCode.Tags.HttpRequestHeaderSize: return "HTTP_REQUEST_HEADER_SIZE"; - case ErrorCode.HTTP_REQUEST_TRAILER_SECTION_SIZE: + case ErrorCode.Tags.HttpRequestTrailerSectionSize: return "HTTP_REQUEST_TRAILER_SECTION_SIZE"; - case ErrorCode.HTTP_REQUEST_TRAILER_SIZE: + case ErrorCode.Tags.HttpRequestTrailerSize: return "HTTP_REQUEST_TRAILER_SIZE"; - case ErrorCode.HTTP_RESPONSE_INCOMPLETE: + case ErrorCode.Tags.HttpResponseIncomplete: return "HTTP_RESPONSE_INCOMPLETE"; - case ErrorCode.HTTP_RESPONSE_HEADER_SECTION_SIZE: + case ErrorCode.Tags.HttpResponseHeaderSectionSize: return "HTTP_RESPONSE_HEADER_SECTION_SIZE"; - case ErrorCode.HTTP_RESPONSE_HEADER_SIZE: + case ErrorCode.Tags.HttpResponseHeaderSize: return "HTTP_RESPONSE_HEADER_SIZE"; - case ErrorCode.HTTP_RESPONSE_BODY_SIZE: + case ErrorCode.Tags.HttpResponseBodySize: return "HTTP_RESPONSE_BODY_SIZE"; - case ErrorCode.HTTP_RESPONSE_TRAILER_SECTION_SIZE: + case ErrorCode.Tags.HttpResponseTrailerSectionSize: return "HTTP_RESPONSE_TRAILER_SECTION_SIZE"; - case ErrorCode.HTTP_RESPONSE_TRAILER_SIZE: + case ErrorCode.Tags.HttpResponseTrailerSize: return "HTTP_RESPONSE_TRAILER_SIZE"; - case ErrorCode.HTTP_RESPONSE_TRANSFER_CODING: + case ErrorCode.Tags.HttpResponseTransferCoding: return "HTTP_RESPONSE_TRANSFER_CODING"; - case ErrorCode.HTTP_RESPONSE_CONTENT_CODING: + case ErrorCode.Tags.HttpResponseContentCoding: return "HTTP_RESPONSE_CONTENT_CODING"; - case ErrorCode.HTTP_RESPONSE_TIMEOUT: + case ErrorCode.Tags.HttpResponseTimeout: return "HTTP_RESPONSE_TIMEOUT"; - case ErrorCode.HTTP_UPGRADE_FAILED: + case ErrorCode.Tags.HttpUpgradeFailed: return "HTTP_UPGRADE_FAILED"; - case ErrorCode.HTTP_PROTOCOL_ERROR: + case ErrorCode.Tags.HttpProtocolError: return "HTTP_PROTOCOL_ERROR"; - case ErrorCode.LOOP_DETECTED: + case ErrorCode.Tags.LoopDetected: return "LOOP_DETECTED"; - case ErrorCode.CONFIGURATION_ERROR: + case ErrorCode.Tags.ConfigurationError: return "CONFIGURATION_ERROR"; - case ErrorCode.INTERNAL_ERROR: + case ErrorCode.Tags.InternalError: return "INTERNAL_ERROR"; default: diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.clocks.v0_2_8.IMonotonicClockImports.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.clocks.v0_2_8.IMonotonicClockImports.cs new file mode 100644 index 00000000000000..267a47c92e39fc --- /dev/null +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.clocks.v0_2_8.IMonotonicClockImports.cs @@ -0,0 +1,39 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +namespace WasiHttpWorld.wit.Imports.wasi.clocks.v0_2_8; + +internal interface IMonotonicClockImports { + + internal static unsafe ulong Now() + { + var result = MonotonicClockImportsInterop.NowWasmInterop.wasmImportNow(); + return unchecked((ulong)(result)); + + } + + internal static unsafe ulong Resolution() + { + var result = MonotonicClockImportsInterop.ResolutionWasmInterop.wasmImportResolution(); + return unchecked((ulong)(result)); + + } + + internal static unsafe global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable SubscribeInstant(ulong when) + { + var result = MonotonicClockImportsInterop.SubscribeInstantWasmInterop.wasmImportSubscribeInstant(unchecked((long)(when))); + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable.THandle(result)); + return resource; + + } + + internal static unsafe global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable SubscribeDuration(ulong when) + { + var result = MonotonicClockImportsInterop.SubscribeDurationWasmInterop.wasmImportSubscribeDuration(unchecked((long)(when))); + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable.THandle(result)); + return resource; + + } + +} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.clocks.v0_2_8.MonotonicClockImportsInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.clocks.v0_2_8.MonotonicClockImportsInterop.cs new file mode 100644 index 00000000000000..5016f799370b77 --- /dev/null +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.clocks.v0_2_8.MonotonicClockImportsInterop.cs @@ -0,0 +1,36 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +using System; + +namespace WasiHttpWorld.wit.Imports.wasi.clocks.v0_2_8 +{ + internal static class MonotonicClockImportsInterop { + + public static class NowWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:clocks/monotonic-clock@0.2.8", EntryPoint = "now"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern long wasmImportNow(); + } + + public static class ResolutionWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:clocks/monotonic-clock@0.2.8", EntryPoint = "resolution"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern long wasmImportResolution(); + } + + public static class SubscribeInstantWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:clocks/monotonic-clock@0.2.8", EntryPoint = "subscribe-instant"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSubscribeInstant(long p0); + } + + public static class SubscribeDurationWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:clocks/monotonic-clock@0.2.8", EntryPoint = "subscribe-duration"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSubscribeDuration(long p0); + } + + } +} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.IOutgoingHandlerImports.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.IOutgoingHandlerImports.cs new file mode 100644 index 00000000000000..9ab572d2aec2a4 --- /dev/null +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.IOutgoingHandlerImports.cs @@ -0,0 +1,692 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +namespace WasiHttpWorld.wit.Imports.wasi.http.v0_2_8; + +internal interface IOutgoingHandlerImports { + + internal static unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FutureIncomingResponse Handle(global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.OutgoingRequest request, global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.RequestOptions? options) + { + var handle = request.Handle; + request.Handle = 0; + + int lowered; + int lowered4; + + if (options != null) { + var payload2 = (global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.RequestOptions) options; + var handle3 = payload2.Handle; + payload2.Handle = 0; + + lowered = 1; + lowered4 = handle3; + + } else { + + lowered = 0; + lowered4 = 0; + + } + + var retArea = stackalloc ulong[6]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 8); + OutgoingHandlerImportsInterop.HandleWasmInterop.wasmImportHandle(handle, lowered, lowered4, ptr); + + Result lifted205; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FutureIncomingResponse(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FutureIncomingResponse.THandle(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + + lifted205 = Result.Ok(resource); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode lifted204; + + switch (new global::System.Span((byte*)ptr + 8, 1)[0]) { + case 0: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DnsTimeout(); + break; + } + case 1: { + + string? lifted; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted = str; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + ushort? lifted21; + + switch (new global::System.Span((byte*)ptr + 28, 1)[0]) { + case 0: { + lifted21 = null; + break; + } + + case 1: { + + lifted21 = ((ushort)new global::System.Span((void*)((byte*)ptr + 30), 1)[0]); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 28, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DnsError(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.DnsErrorPayload ( + lifted, lifted21)); + break; + } + case 2: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationNotFound(); + break; + } + case 3: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationUnavailable(); + break; + } + case 4: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationIpProhibited(); + break; + } + case 5: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationIpUnroutable(); + break; + } + case 6: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionRefused(); + break; + } + case 7: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionTerminated(); + break; + } + case 8: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionTimeout(); + break; + } + case 9: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionReadTimeout(); + break; + } + case 10: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionWriteTimeout(); + break; + } + case 11: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionLimitReached(); + break; + } + case 12: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.TlsProtocolError(); + break; + } + case 13: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.TlsCertificateError(); + break; + } + case 14: { + + byte? lifted52; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted52 = null; + break; + } + + case 1: { + + lifted52 = ((byte)new global::System.Span((byte*)ptr + 17, 1)[0]); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + string? lifted58; + + switch (new global::System.Span((byte*)ptr + 20, 1)[0]) { + case 0: { + lifted58 = null; + break; + } + + case 1: { + + var str57 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 24), 1)[0], new global::System.Span((void*)((byte*)ptr + 28), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 28), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + } + + lifted58 = str57; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 20, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.TlsAlertReceived(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.TlsAlertReceivedPayload ( + lifted52, lifted58)); + break; + } + case 15: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestDenied(); + break; + } + case 16: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestLengthRequired(); + break; + } + case 17: { + + ulong? lifted69; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted69 = null; + break; + } + + case 1: { + + lifted69 = unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 24), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestBodySize(lifted69); + break; + } + case 18: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestMethodInvalid(); + break; + } + case 19: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestUriInvalid(); + break; + } + case 20: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestUriTooLong(); + break; + } + case 21: { + + uint? lifted82; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted82 = null; + break; + } + + case 1: { + + lifted82 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 20), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestHeaderSectionSize(lifted82); + break; + } + case 22: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload? lifted100; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted100 = null; + break; + } + + case 1: { + + string? lifted94; + + switch (new global::System.Span((byte*)ptr + 20, 1)[0]) { + case 0: { + lifted94 = null; + break; + } + + case 1: { + + var str93 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 24), 1)[0], new global::System.Span((void*)((byte*)ptr + 28), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 28), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + } + + lifted94 = str93; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 20, 1)[0])); + } + + uint? lifted99; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted99 = null; + break; + } + + case 1: { + + lifted99 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 36), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted100 = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted94, lifted99); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestHeaderSize(lifted100); + break; + } + case 23: { + + uint? lifted107; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted107 = null; + break; + } + + case 1: { + + lifted107 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 20), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestTrailerSectionSize(lifted107); + break; + } + case 24: { + + string? lifted115; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted115 = null; + break; + } + + case 1: { + + var str114 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted115 = str114; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + uint? lifted120; + + switch (new global::System.Span((byte*)ptr + 28, 1)[0]) { + case 0: { + lifted120 = null; + break; + } + + case 1: { + + lifted120 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 32), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 28, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestTrailerSize(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted115, lifted120)); + break; + } + case 25: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseIncomplete(); + break; + } + case 26: { + + uint? lifted129; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted129 = null; + break; + } + + case 1: { + + lifted129 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 20), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseHeaderSectionSize(lifted129); + break; + } + case 27: { + + string? lifted137; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted137 = null; + break; + } + + case 1: { + + var str136 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted137 = str136; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + uint? lifted142; + + switch (new global::System.Span((byte*)ptr + 28, 1)[0]) { + case 0: { + lifted142 = null; + break; + } + + case 1: { + + lifted142 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 32), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 28, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseHeaderSize(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted137, lifted142)); + break; + } + case 28: { + + ulong? lifted149; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted149 = null; + break; + } + + case 1: { + + lifted149 = unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 24), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseBodySize(lifted149); + break; + } + case 29: { + + uint? lifted156; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted156 = null; + break; + } + + case 1: { + + lifted156 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 20), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTrailerSectionSize(lifted156); + break; + } + case 30: { + + string? lifted164; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted164 = null; + break; + } + + case 1: { + + var str163 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted164 = str163; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + uint? lifted169; + + switch (new global::System.Span((byte*)ptr + 28, 1)[0]) { + case 0: { + lifted169 = null; + break; + } + + case 1: { + + lifted169 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 32), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 28, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTrailerSize(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted164, lifted169)); + break; + } + case 31: { + + string? lifted177; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted177 = null; + break; + } + + case 1: { + + var str176 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted177 = str176; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTransferCoding(lifted177); + break; + } + case 32: { + + string? lifted185; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted185 = null; + break; + } + + case 1: { + + var str184 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted185 = str184; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseContentCoding(lifted185); + break; + } + case 33: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTimeout(); + break; + } + case 34: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpUpgradeFailed(); + break; + } + case 35: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpProtocolError(); + break; + } + case 36: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.LoopDetected(); + break; + } + case 37: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConfigurationError(); + break; + } + case 38: { + + string? lifted203; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted203 = null; + break; + } + + case 1: { + + var str202 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted203 = str202; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.InternalError(lifted203); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 8, 1)[0]); + } + + lifted205 = Result.Err(lifted204); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted205.IsOk) + { + var tmp = lifted205.AsOk; + return tmp; + } + else + { + throw new WitException(lifted205.AsErr!, 0); + } + + } + +} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.cs new file mode 100644 index 00000000000000..3fa4f61a237a95 --- /dev/null +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.cs @@ -0,0 +1,6638 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +namespace WasiHttpWorld.wit.Imports.wasi.http.v0_2_8; + +internal interface ITypesImports { + + /** + * This type corresponds to HTTP standard Methods. + */ + + internal class Method { + internal readonly byte Tag; + private readonly object? value; + + private Method(byte tag, object? value) { + this.Tag = tag; + this.value = value; + } + + internal static Method Get() { + return new Method(Tags.Get, null); + } + + internal static Method Head() { + return new Method(Tags.Head, null); + } + + internal static Method Post() { + return new Method(Tags.Post, null); + } + + internal static Method Put() { + return new Method(Tags.Put, null); + } + + internal static Method Delete() { + return new Method(Tags.Delete, null); + } + + internal static Method Connect() { + return new Method(Tags.Connect, null); + } + + internal static Method Options() { + return new Method(Tags.Options, null); + } + + internal static Method Trace() { + return new Method(Tags.Trace, null); + } + + internal static Method Patch() { + return new Method(Tags.Patch, null); + } + + internal static Method Other(string other) { + return new Method(Tags.Other, other); + } + + internal string AsOther + { + get + { + if (Tag == Tags.Other) + return (string)value!; + else + throw new global::System.ArgumentException("expected Other, got " + Tag); + } + } + + internal class Tags { + internal const byte Get = 0; + internal const byte Head = 1; + internal const byte Post = 2; + internal const byte Put = 3; + internal const byte Delete = 4; + internal const byte Connect = 5; + internal const byte Options = 6; + internal const byte Trace = 7; + internal const byte Patch = 8; + internal const byte Other = 9; + } + } + + /** + * This type corresponds to HTTP standard Related Schemes. + */ + + internal class Scheme { + internal readonly byte Tag; + private readonly object? value; + + private Scheme(byte tag, object? value) { + this.Tag = tag; + this.value = value; + } + + internal static Scheme Http() { + return new Scheme(Tags.Http, null); + } + + internal static Scheme Https() { + return new Scheme(Tags.Https, null); + } + + internal static Scheme Other(string other) { + return new Scheme(Tags.Other, other); + } + + internal string AsOther + { + get + { + if (Tag == Tags.Other) + return (string)value!; + else + throw new global::System.ArgumentException("expected Other, got " + Tag); + } + } + + internal class Tags { + internal const byte Http = 0; + internal const byte Https = 1; + internal const byte Other = 2; + } + } + + /** + * Defines the case payload type for `DNS-error` above: + */ + + internal struct DnsErrorPayload { + internal string? rcode; + internal ushort? infoCode; + + internal DnsErrorPayload(string? rcode, ushort? infoCode) { + this.rcode = rcode; + this.infoCode = infoCode; + } + } + + /** + * Defines the case payload type for `TLS-alert-received` above: + */ + + internal struct TlsAlertReceivedPayload { + internal byte? alertId; + internal string? alertMessage; + + internal TlsAlertReceivedPayload(byte? alertId, string? alertMessage) { + this.alertId = alertId; + this.alertMessage = alertMessage; + } + } + + /** + * Defines the case payload type for `HTTP-response-{header,trailer}-size` above: + */ + + internal struct FieldSizePayload { + internal string? fieldName; + internal uint? fieldSize; + + internal 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> + */ + + internal class ErrorCode { + internal readonly byte Tag; + private readonly object? value; + + private ErrorCode(byte tag, object? value) { + this.Tag = tag; + this.value = value; + } + + internal static ErrorCode DnsTimeout() { + return new ErrorCode(Tags.DnsTimeout, null); + } + + internal static ErrorCode DnsError(DnsErrorPayload dnsError) { + return new ErrorCode(Tags.DnsError, dnsError); + } + + internal static ErrorCode DestinationNotFound() { + return new ErrorCode(Tags.DestinationNotFound, null); + } + + internal static ErrorCode DestinationUnavailable() { + return new ErrorCode(Tags.DestinationUnavailable, null); + } + + internal static ErrorCode DestinationIpProhibited() { + return new ErrorCode(Tags.DestinationIpProhibited, null); + } + + internal static ErrorCode DestinationIpUnroutable() { + return new ErrorCode(Tags.DestinationIpUnroutable, null); + } + + internal static ErrorCode ConnectionRefused() { + return new ErrorCode(Tags.ConnectionRefused, null); + } + + internal static ErrorCode ConnectionTerminated() { + return new ErrorCode(Tags.ConnectionTerminated, null); + } + + internal static ErrorCode ConnectionTimeout() { + return new ErrorCode(Tags.ConnectionTimeout, null); + } + + internal static ErrorCode ConnectionReadTimeout() { + return new ErrorCode(Tags.ConnectionReadTimeout, null); + } + + internal static ErrorCode ConnectionWriteTimeout() { + return new ErrorCode(Tags.ConnectionWriteTimeout, null); + } + + internal static ErrorCode ConnectionLimitReached() { + return new ErrorCode(Tags.ConnectionLimitReached, null); + } + + internal static ErrorCode TlsProtocolError() { + return new ErrorCode(Tags.TlsProtocolError, null); + } + + internal static ErrorCode TlsCertificateError() { + return new ErrorCode(Tags.TlsCertificateError, null); + } + + internal static ErrorCode TlsAlertReceived(TlsAlertReceivedPayload tlsAlertReceived) { + return new ErrorCode(Tags.TlsAlertReceived, tlsAlertReceived); + } + + internal static ErrorCode HttpRequestDenied() { + return new ErrorCode(Tags.HttpRequestDenied, null); + } + + internal static ErrorCode HttpRequestLengthRequired() { + return new ErrorCode(Tags.HttpRequestLengthRequired, null); + } + + internal static ErrorCode HttpRequestBodySize(ulong? httpRequestBodySize) { + return new ErrorCode(Tags.HttpRequestBodySize, httpRequestBodySize); + } + + internal static ErrorCode HttpRequestMethodInvalid() { + return new ErrorCode(Tags.HttpRequestMethodInvalid, null); + } + + internal static ErrorCode HttpRequestUriInvalid() { + return new ErrorCode(Tags.HttpRequestUriInvalid, null); + } + + internal static ErrorCode HttpRequestUriTooLong() { + return new ErrorCode(Tags.HttpRequestUriTooLong, null); + } + + internal static ErrorCode HttpRequestHeaderSectionSize(uint? httpRequestHeaderSectionSize) { + return new ErrorCode(Tags.HttpRequestHeaderSectionSize, httpRequestHeaderSectionSize); + } + + internal static ErrorCode HttpRequestHeaderSize(FieldSizePayload? httpRequestHeaderSize) { + return new ErrorCode(Tags.HttpRequestHeaderSize, httpRequestHeaderSize); + } + + internal static ErrorCode HttpRequestTrailerSectionSize(uint? httpRequestTrailerSectionSize) { + return new ErrorCode(Tags.HttpRequestTrailerSectionSize, httpRequestTrailerSectionSize); + } + + internal static ErrorCode HttpRequestTrailerSize(FieldSizePayload httpRequestTrailerSize) { + return new ErrorCode(Tags.HttpRequestTrailerSize, httpRequestTrailerSize); + } + + internal static ErrorCode HttpResponseIncomplete() { + return new ErrorCode(Tags.HttpResponseIncomplete, null); + } + + internal static ErrorCode HttpResponseHeaderSectionSize(uint? httpResponseHeaderSectionSize) { + return new ErrorCode(Tags.HttpResponseHeaderSectionSize, httpResponseHeaderSectionSize); + } + + internal static ErrorCode HttpResponseHeaderSize(FieldSizePayload httpResponseHeaderSize) { + return new ErrorCode(Tags.HttpResponseHeaderSize, httpResponseHeaderSize); + } + + internal static ErrorCode HttpResponseBodySize(ulong? httpResponseBodySize) { + return new ErrorCode(Tags.HttpResponseBodySize, httpResponseBodySize); + } + + internal static ErrorCode HttpResponseTrailerSectionSize(uint? httpResponseTrailerSectionSize) { + return new ErrorCode(Tags.HttpResponseTrailerSectionSize, httpResponseTrailerSectionSize); + } + + internal static ErrorCode HttpResponseTrailerSize(FieldSizePayload httpResponseTrailerSize) { + return new ErrorCode(Tags.HttpResponseTrailerSize, httpResponseTrailerSize); + } + + internal static ErrorCode HttpResponseTransferCoding(string? httpResponseTransferCoding) { + return new ErrorCode(Tags.HttpResponseTransferCoding, httpResponseTransferCoding); + } + + internal static ErrorCode HttpResponseContentCoding(string? httpResponseContentCoding) { + return new ErrorCode(Tags.HttpResponseContentCoding, httpResponseContentCoding); + } + + internal static ErrorCode HttpResponseTimeout() { + return new ErrorCode(Tags.HttpResponseTimeout, null); + } + + internal static ErrorCode HttpUpgradeFailed() { + return new ErrorCode(Tags.HttpUpgradeFailed, null); + } + + internal static ErrorCode HttpProtocolError() { + return new ErrorCode(Tags.HttpProtocolError, null); + } + + internal static ErrorCode LoopDetected() { + return new ErrorCode(Tags.LoopDetected, null); + } + + internal static ErrorCode ConfigurationError() { + return new ErrorCode(Tags.ConfigurationError, null); + } + + internal static ErrorCode InternalError(string? internalError) { + return new ErrorCode(Tags.InternalError, internalError); + } + + internal DnsErrorPayload AsDnsError + { + get + { + if (Tag == Tags.DnsError) + return (DnsErrorPayload)value!; + else + throw new global::System.ArgumentException("expected DnsError, got " + Tag); + } + } + + internal TlsAlertReceivedPayload AsTlsAlertReceived + { + get + { + if (Tag == Tags.TlsAlertReceived) + return (TlsAlertReceivedPayload)value!; + else + throw new global::System.ArgumentException("expected TlsAlertReceived, got " + Tag); + } + } + + internal ulong? AsHttpRequestBodySize + { + get + { + if (Tag == Tags.HttpRequestBodySize) + return (ulong?)value!; + else + throw new global::System.ArgumentException("expected HttpRequestBodySize, got " + Tag); + } + } + + internal uint? AsHttpRequestHeaderSectionSize + { + get + { + if (Tag == Tags.HttpRequestHeaderSectionSize) + return (uint?)value!; + else + throw new global::System.ArgumentException("expected HttpRequestHeaderSectionSize, got " + Tag); + } + } + + internal FieldSizePayload? AsHttpRequestHeaderSize + { + get + { + if (Tag == Tags.HttpRequestHeaderSize) + return (FieldSizePayload?)value!; + else + throw new global::System.ArgumentException("expected HttpRequestHeaderSize, got " + Tag); + } + } + + internal uint? AsHttpRequestTrailerSectionSize + { + get + { + if (Tag == Tags.HttpRequestTrailerSectionSize) + return (uint?)value!; + else + throw new global::System.ArgumentException("expected HttpRequestTrailerSectionSize, got " + Tag); + } + } + + internal FieldSizePayload AsHttpRequestTrailerSize + { + get + { + if (Tag == Tags.HttpRequestTrailerSize) + return (FieldSizePayload)value!; + else + throw new global::System.ArgumentException("expected HttpRequestTrailerSize, got " + Tag); + } + } + + internal uint? AsHttpResponseHeaderSectionSize + { + get + { + if (Tag == Tags.HttpResponseHeaderSectionSize) + return (uint?)value!; + else + throw new global::System.ArgumentException("expected HttpResponseHeaderSectionSize, got " + Tag); + } + } + + internal FieldSizePayload AsHttpResponseHeaderSize + { + get + { + if (Tag == Tags.HttpResponseHeaderSize) + return (FieldSizePayload)value!; + else + throw new global::System.ArgumentException("expected HttpResponseHeaderSize, got " + Tag); + } + } + + internal ulong? AsHttpResponseBodySize + { + get + { + if (Tag == Tags.HttpResponseBodySize) + return (ulong?)value!; + else + throw new global::System.ArgumentException("expected HttpResponseBodySize, got " + Tag); + } + } + + internal uint? AsHttpResponseTrailerSectionSize + { + get + { + if (Tag == Tags.HttpResponseTrailerSectionSize) + return (uint?)value!; + else + throw new global::System.ArgumentException("expected HttpResponseTrailerSectionSize, got " + Tag); + } + } + + internal FieldSizePayload AsHttpResponseTrailerSize + { + get + { + if (Tag == Tags.HttpResponseTrailerSize) + return (FieldSizePayload)value!; + else + throw new global::System.ArgumentException("expected HttpResponseTrailerSize, got " + Tag); + } + } + + internal string? AsHttpResponseTransferCoding + { + get + { + if (Tag == Tags.HttpResponseTransferCoding) + return (string?)value!; + else + throw new global::System.ArgumentException("expected HttpResponseTransferCoding, got " + Tag); + } + } + + internal string? AsHttpResponseContentCoding + { + get + { + if (Tag == Tags.HttpResponseContentCoding) + return (string?)value!; + else + throw new global::System.ArgumentException("expected HttpResponseContentCoding, got " + Tag); + } + } + + internal string? AsInternalError + { + get + { + if (Tag == Tags.InternalError) + return (string?)value!; + else + throw new global::System.ArgumentException("expected InternalError, got " + Tag); + } + } + + internal class Tags { + internal const byte DnsTimeout = 0; + internal const byte DnsError = 1; + internal const byte DestinationNotFound = 2; + internal const byte DestinationUnavailable = 3; + internal const byte DestinationIpProhibited = 4; + internal const byte DestinationIpUnroutable = 5; + internal const byte ConnectionRefused = 6; + internal const byte ConnectionTerminated = 7; + internal const byte ConnectionTimeout = 8; + internal const byte ConnectionReadTimeout = 9; + internal const byte ConnectionWriteTimeout = 10; + internal const byte ConnectionLimitReached = 11; + internal const byte TlsProtocolError = 12; + internal const byte TlsCertificateError = 13; + internal const byte TlsAlertReceived = 14; + internal const byte HttpRequestDenied = 15; + internal const byte HttpRequestLengthRequired = 16; + internal const byte HttpRequestBodySize = 17; + internal const byte HttpRequestMethodInvalid = 18; + internal const byte HttpRequestUriInvalid = 19; + internal const byte HttpRequestUriTooLong = 20; + internal const byte HttpRequestHeaderSectionSize = 21; + internal const byte HttpRequestHeaderSize = 22; + internal const byte HttpRequestTrailerSectionSize = 23; + internal const byte HttpRequestTrailerSize = 24; + internal const byte HttpResponseIncomplete = 25; + internal const byte HttpResponseHeaderSectionSize = 26; + internal const byte HttpResponseHeaderSize = 27; + internal const byte HttpResponseBodySize = 28; + internal const byte HttpResponseTrailerSectionSize = 29; + internal const byte HttpResponseTrailerSize = 30; + internal const byte HttpResponseTransferCoding = 31; + internal const byte HttpResponseContentCoding = 32; + internal const byte HttpResponseTimeout = 33; + internal const byte HttpUpgradeFailed = 34; + internal const byte HttpProtocolError = 35; + internal const byte LoopDetected = 36; + internal const byte ConfigurationError = 37; + internal const byte InternalError = 38; + } + } + + /** + * This type enumerates the different kinds of errors that may occur when + * setting or appending to a `fields` resource. + */ + + internal class HeaderError { + internal readonly byte Tag; + private readonly object? value; + + private HeaderError(byte tag, object? value) { + this.Tag = tag; + this.value = value; + } + + internal static HeaderError InvalidSyntax() { + return new HeaderError(Tags.InvalidSyntax, null); + } + + internal static HeaderError Forbidden() { + return new HeaderError(Tags.Forbidden, null); + } + + internal static HeaderError Immutable() { + return new HeaderError(Tags.Immutable, null); + } + + internal class Tags { + internal const byte InvalidSyntax = 0; + internal const byte Forbidden = 1; + internal const byte Immutable = 2; + } + } + + internal static unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode? HttpErrorCode(global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error err) + { + var handle = err.Handle; + + var retArea = stackalloc ulong[6]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 8); + TypesImportsInterop.HttpErrorCodeWasmInterop.wasmImportHttpErrorCode(handle, ptr); + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode? lifted198; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + lifted198 = null; + break; + } + + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode lifted197; + + switch (new global::System.Span((byte*)ptr + 8, 1)[0]) { + case 0: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DnsTimeout(); + break; + } + case 1: { + + string? lifted; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted = str; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + ushort? lifted14; + + switch (new global::System.Span((byte*)ptr + 28, 1)[0]) { + case 0: { + lifted14 = null; + break; + } + + case 1: { + + lifted14 = ((ushort)new global::System.Span((void*)((byte*)ptr + 30), 1)[0]); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 28, 1)[0])); + } + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DnsError(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.DnsErrorPayload ( + lifted, lifted14)); + break; + } + case 2: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationNotFound(); + break; + } + case 3: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationUnavailable(); + break; + } + case 4: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationIpProhibited(); + break; + } + case 5: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationIpUnroutable(); + break; + } + case 6: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionRefused(); + break; + } + case 7: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionTerminated(); + break; + } + case 8: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionTimeout(); + break; + } + case 9: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionReadTimeout(); + break; + } + case 10: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionWriteTimeout(); + break; + } + case 11: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionLimitReached(); + break; + } + case 12: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.TlsProtocolError(); + break; + } + case 13: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.TlsCertificateError(); + break; + } + case 14: { + + byte? lifted45; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted45 = null; + break; + } + + case 1: { + + lifted45 = ((byte)new global::System.Span((byte*)ptr + 17, 1)[0]); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + string? lifted51; + + switch (new global::System.Span((byte*)ptr + 20, 1)[0]) { + case 0: { + lifted51 = null; + break; + } + + case 1: { + + var str50 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 24), 1)[0], new global::System.Span((void*)((byte*)ptr + 28), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 28), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + } + + lifted51 = str50; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 20, 1)[0])); + } + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.TlsAlertReceived(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.TlsAlertReceivedPayload ( + lifted45, lifted51)); + break; + } + case 15: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestDenied(); + break; + } + case 16: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestLengthRequired(); + break; + } + case 17: { + + ulong? lifted62; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted62 = null; + break; + } + + case 1: { + + lifted62 = unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 24), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestBodySize(lifted62); + break; + } + case 18: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestMethodInvalid(); + break; + } + case 19: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestUriInvalid(); + break; + } + case 20: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestUriTooLong(); + break; + } + case 21: { + + uint? lifted75; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted75 = null; + break; + } + + case 1: { + + lifted75 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 20), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestHeaderSectionSize(lifted75); + break; + } + case 22: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload? lifted93; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted93 = null; + break; + } + + case 1: { + + string? lifted87; + + switch (new global::System.Span((byte*)ptr + 20, 1)[0]) { + case 0: { + lifted87 = null; + break; + } + + case 1: { + + var str86 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 24), 1)[0], new global::System.Span((void*)((byte*)ptr + 28), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 28), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + } + + lifted87 = str86; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 20, 1)[0])); + } + + uint? lifted92; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted92 = null; + break; + } + + case 1: { + + lifted92 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 36), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted93 = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted87, lifted92); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestHeaderSize(lifted93); + break; + } + case 23: { + + uint? lifted100; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted100 = null; + break; + } + + case 1: { + + lifted100 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 20), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestTrailerSectionSize(lifted100); + break; + } + case 24: { + + string? lifted108; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted108 = null; + break; + } + + case 1: { + + var str107 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted108 = str107; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + uint? lifted113; + + switch (new global::System.Span((byte*)ptr + 28, 1)[0]) { + case 0: { + lifted113 = null; + break; + } + + case 1: { + + lifted113 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 32), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 28, 1)[0])); + } + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestTrailerSize(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted108, lifted113)); + break; + } + case 25: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseIncomplete(); + break; + } + case 26: { + + uint? lifted122; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted122 = null; + break; + } + + case 1: { + + lifted122 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 20), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseHeaderSectionSize(lifted122); + break; + } + case 27: { + + string? lifted130; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted130 = null; + break; + } + + case 1: { + + var str129 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted130 = str129; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + uint? lifted135; + + switch (new global::System.Span((byte*)ptr + 28, 1)[0]) { + case 0: { + lifted135 = null; + break; + } + + case 1: { + + lifted135 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 32), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 28, 1)[0])); + } + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseHeaderSize(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted130, lifted135)); + break; + } + case 28: { + + ulong? lifted142; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted142 = null; + break; + } + + case 1: { + + lifted142 = unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 24), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseBodySize(lifted142); + break; + } + case 29: { + + uint? lifted149; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted149 = null; + break; + } + + case 1: { + + lifted149 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 20), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTrailerSectionSize(lifted149); + break; + } + case 30: { + + string? lifted157; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted157 = null; + break; + } + + case 1: { + + var str156 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted157 = str156; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + uint? lifted162; + + switch (new global::System.Span((byte*)ptr + 28, 1)[0]) { + case 0: { + lifted162 = null; + break; + } + + case 1: { + + lifted162 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 32), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 28, 1)[0])); + } + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTrailerSize(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted157, lifted162)); + break; + } + case 31: { + + string? lifted170; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted170 = null; + break; + } + + case 1: { + + var str169 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted170 = str169; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTransferCoding(lifted170); + break; + } + case 32: { + + string? lifted178; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted178 = null; + break; + } + + case 1: { + + var str177 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted178 = str177; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseContentCoding(lifted178); + break; + } + case 33: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTimeout(); + break; + } + case 34: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpUpgradeFailed(); + break; + } + case 35: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpProtocolError(); + break; + } + case 36: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.LoopDetected(); + break; + } + case 37: { + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConfigurationError(); + break; + } + case 38: { + + string? lifted196; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted196 = null; + break; + } + + case 1: { + + var str195 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted196 = str195; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted197 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.InternalError(lifted196); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 8, 1)[0]); + } + + lifted198 = lifted197; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 0, 1)[0])); + } + return lifted198; + + } + + /** + * This following block defines the `fields` resource which corresponds to + * HTTP standard Fields. Fields are a common representation used for both + * Headers and Trailers. + * + * A `fields` may be mutable or immutable. A `fields` created using the + * constructor, `from-list`, or `clone` will be mutable, but a `fields` + * resource given by other means (including, but not limited to, + * `incoming-request.headers`, `outgoing-request.headers`) might be + * immutable. In an immutable fields, the `set`, `append`, and `delete` + * operations will fail with `header-error.immutable`. + */ + + internal class Fields: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal Fields(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[resource-drop]fields"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal unsafe Fields() + { + var result = TypesImportsInterop.Fields.ConstructorWasmInterop.wasmImportConstructor(); + this.Handle = result; + + } + + internal static unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields FromList(global::System.Collections.Generic.List<(string, byte[])> entries) + { + var cleanups = new global::System.Collections.Generic.List(); + + void* address; + if ((16 * entries.Count) < 1024) { + var retArea = stackalloc uint[4 * entries.Count + 1]; + address = MemoryHelper.AlignStackPtr(retArea, 4); + } + else + { + var bufferSize = 16 * (nuint)entries.Count; + address = global::System.Runtime.InteropServices.NativeMemory.AlignedAlloc(bufferSize, 4); + cleanups.Add(() => global::System.Runtime.InteropServices.NativeMemory.AlignedFree(address)); + } + + for (int index = 0; index < entries.Count; ++index) { + (string, byte[]) element = entries[index]; + int basePtr = (int)address + (index * 16); + + var utf8Bytes = global::System.Text.Encoding.UTF8.GetBytes(element.Item1); + var length = utf8Bytes.Length; + var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes, global::System.Runtime.InteropServices.GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + new global::System.Span((void*)((byte*)basePtr + 4), 1)[0] = length; + new global::System.Span((void*)((byte*)basePtr + 0), 1)[0] = (nint)strPtr.ToInt32(); + + var gcHandle0 = global::System.Runtime.InteropServices.GCHandle.Alloc(element.Item2, global::System.Runtime.InteropServices.GCHandleType.Pinned); + var listPtr = gcHandle0.AddrOfPinnedObject(); + cleanups.Add(()=> gcHandle0.Free()); + new global::System.Span((void*)((byte*)basePtr + 12), 1)[0] = (element.Item2).Length; + new global::System.Span((void*)((byte*)basePtr + 8), 1)[0] = (nint)(nint)listPtr; + + } + + var retArea1 = stackalloc uint[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea1, 4); + TypesImportsInterop.Fields.FromListWasmInterop.wasmImportFromList((int)address, entries.Count, ptr); + + Result lifted12; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields.THandle(new global::System.Span((void*)((byte*)ptr + 4), 1)[0])); + + lifted12 = Result.Ok(resource); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError lifted; + + switch (new global::System.Span((byte*)ptr + 4, 1)[0]) { + case 0: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.InvalidSyntax(); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.Forbidden(); + break; + } + case 2: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.Immutable(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 4, 1)[0]); + } + + lifted12 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)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 unsafe global::System.Collections.Generic.List Get(string name) + { + var cleanups = new global::System.Collections.Generic.List(); + var handle = this.Handle; + + var utf8Bytes = global::System.Text.Encoding.UTF8.GetBytes(name); + var length = utf8Bytes.Length; + var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes, global::System.Runtime.InteropServices.GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + var retArea = stackalloc uint[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.Fields.GetWasmInterop.wasmImportGet(handle, strPtr.ToInt32(), length, ptr); + + var array0 = new global::System.Collections.Generic.List(new global::System.Span((void*)((byte*)ptr + 4), 1)[0]); + for (int index = 0; index < new global::System.Span((void*)((byte*)ptr + 4), 1)[0]; ++index) { + nint basePtr = new global::System.Span((void*)((byte*)ptr + 0), 1)[0] + (index * 8); + + var array = new byte[new global::System.Span((void*)((byte*)basePtr + 4), 1)[0]]; + new global::System.Span((void*)(new global::System.Span((void*)((byte*)basePtr + 0), 1)[0]), new global::System.Span((void*)((byte*)basePtr + 4), 1)[0]).CopyTo(new global::System.Span(array)); + + if (new global::System.Span((void*)((byte*)basePtr + 4), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)basePtr + 0), 1)[0]); + } + + array0.Add(array); + } + + if (new global::System.Span((void*)((byte*)ptr + 4), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 0), 1)[0]); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + return array0; + + } + + internal unsafe bool Has(string name) + { + var cleanups = new global::System.Collections.Generic.List(); + var handle = this.Handle; + + var utf8Bytes = global::System.Text.Encoding.UTF8.GetBytes(name); + var length = utf8Bytes.Length; + var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes, global::System.Runtime.InteropServices.GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + var result = TypesImportsInterop.Fields.HasWasmInterop.wasmImportHas(handle, strPtr.ToInt32(), length); + + foreach (var cleanup in cleanups) + { + cleanup(); + } + return (result != 0); + + } + + internal unsafe void Set(string name, global::System.Collections.Generic.List value) + { + var cleanups = new global::System.Collections.Generic.List(); + var handle = this.Handle; + + var utf8Bytes = global::System.Text.Encoding.UTF8.GetBytes(name); + var length = utf8Bytes.Length; + var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes, global::System.Runtime.InteropServices.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 = MemoryHelper.AlignStackPtr(retArea, 4); + } + else + { + var bufferSize = 8 * (nuint)value.Count; + address = global::System.Runtime.InteropServices.NativeMemory.AlignedAlloc(bufferSize, 4); + cleanups.Add(() => global::System.Runtime.InteropServices.NativeMemory.AlignedFree(address)); + } + + for (int index = 0; index < value.Count; ++index) { + byte[] element = value[index]; + int basePtr = (int)address + (index * 8); + + var gcHandle0 = global::System.Runtime.InteropServices.GCHandle.Alloc(element, global::System.Runtime.InteropServices.GCHandleType.Pinned); + var listPtr = gcHandle0.AddrOfPinnedObject(); + cleanups.Add(()=> gcHandle0.Free()); + new global::System.Span((void*)((byte*)basePtr + 4), 1)[0] = (element).Length; + new global::System.Span((void*)((byte*)basePtr + 0), 1)[0] = (nint)(nint)listPtr; + + } + + var retArea1 = stackalloc byte[2]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea1, 1); + TypesImportsInterop.Fields.SetWasmInterop.wasmImportSet(handle, strPtr.ToInt32(), length, (int)address, value.Count, ptr); + + Result lifted12; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted12 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError lifted; + + switch (new global::System.Span((byte*)ptr + 1, 1)[0]) { + case 0: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.InvalidSyntax(); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.Forbidden(); + break; + } + case 2: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.Immutable(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 1, 1)[0]); + } + + lifted12 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)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 unsafe void Delete(string name) + { + var cleanups = new global::System.Collections.Generic.List(); + var handle = this.Handle; + + var utf8Bytes = global::System.Text.Encoding.UTF8.GetBytes(name); + var length = utf8Bytes.Length; + var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes, global::System.Runtime.InteropServices.GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + var retArea = stackalloc byte[2]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 1); + TypesImportsInterop.Fields.DeleteWasmInterop.wasmImportDelete(handle, strPtr.ToInt32(), length, ptr); + + Result lifted8; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted8 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError lifted; + + switch (new global::System.Span((byte*)ptr + 1, 1)[0]) { + case 0: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.InvalidSyntax(); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.Forbidden(); + break; + } + case 2: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.Immutable(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 1, 1)[0]); + } + + lifted8 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)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 unsafe void Append(string name, byte[] value) + { + var cleanups = new global::System.Collections.Generic.List(); + var handle = this.Handle; + + var utf8Bytes = global::System.Text.Encoding.UTF8.GetBytes(name); + var length = utf8Bytes.Length; + var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes, global::System.Runtime.InteropServices.GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + var gcHandle0 = global::System.Runtime.InteropServices.GCHandle.Alloc(value, global::System.Runtime.InteropServices.GCHandleType.Pinned); + var listPtr = gcHandle0.AddrOfPinnedObject(); + cleanups.Add(()=> gcHandle0.Free()); + + var retArea = stackalloc byte[2]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 1); + TypesImportsInterop.Fields.AppendWasmInterop.wasmImportAppend(handle, strPtr.ToInt32(), length, (nint)listPtr, (value).Length, ptr); + + Result lifted9; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted9 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError lifted; + + switch (new global::System.Span((byte*)ptr + 1, 1)[0]) { + case 0: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.InvalidSyntax(); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.Forbidden(); + break; + } + case 2: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.Immutable(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 1, 1)[0]); + } + + lifted9 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)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 unsafe void Append(string name, global::System.Span value) + { + var cleanups = new global::System.Collections.Generic.List(); + fixed (void* listPtr = value) + { + var handle = this.Handle; + + var utf8Bytes = global::System.Text.Encoding.UTF8.GetBytes(name); + var length = utf8Bytes.Length; + var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes, global::System.Runtime.InteropServices.GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + var retArea = stackalloc byte[2]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 1); + TypesImportsInterop.Fields.AppendWasmInterop.wasmImportAppend(handle, strPtr.ToInt32(), length, (nint)listPtr, (value).Length, ptr); + + Result lifted9; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted9 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError lifted; + + switch (new global::System.Span((byte*)ptr + 1, 1)[0]) { + case 0: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.InvalidSyntax(); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.Forbidden(); + break; + } + case 2: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.Immutable(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 1, 1)[0]); + } + + lifted9 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)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 unsafe void Append(string name, global::System.Memory value) + { + var cleanups = new global::System.Collections.Generic.List(); + fixed (void* listPtr = value.Span) + { + var handle = this.Handle; + + var utf8Bytes = global::System.Text.Encoding.UTF8.GetBytes(name); + var length = utf8Bytes.Length; + var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes, global::System.Runtime.InteropServices.GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + var retArea = stackalloc byte[2]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 1); + TypesImportsInterop.Fields.AppendWasmInterop.wasmImportAppend(handle, strPtr.ToInt32(), length, (nint)listPtr, (value).Length, ptr); + + Result lifted9; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted9 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError lifted; + + switch (new global::System.Span((byte*)ptr + 1, 1)[0]) { + case 0: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.InvalidSyntax(); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.Forbidden(); + break; + } + case 2: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.HeaderError.Immutable(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 1, 1)[0]); + } + + lifted9 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)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 unsafe global::System.Collections.Generic.List<(string, byte[])> Entries() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.Fields.EntriesWasmInterop.wasmImportEntries(handle, ptr); + + var array0 = new global::System.Collections.Generic.List<(string, byte[])>(new global::System.Span((void*)((byte*)ptr + 4), 1)[0]); + for (int index = 0; index < new global::System.Span((void*)((byte*)ptr + 4), 1)[0]; ++index) { + nint basePtr = new global::System.Span((void*)((byte*)ptr + 0), 1)[0] + (index * 16); + + var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)basePtr + 0), 1)[0], new global::System.Span((void*)((byte*)basePtr + 4), 1)[0]); + if (new global::System.Span((void*)((byte*)basePtr + 4), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)basePtr + 0), 1)[0]); + } + + var array = new byte[new global::System.Span((void*)((byte*)basePtr + 12), 1)[0]]; + new global::System.Span((void*)(new global::System.Span((void*)((byte*)basePtr + 8), 1)[0]), new global::System.Span((void*)((byte*)basePtr + 12), 1)[0]).CopyTo(new global::System.Span(array)); + + if (new global::System.Span((void*)((byte*)basePtr + 12), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)basePtr + 8), 1)[0]); + } + + array0.Add((str, array)); + } + + if (new global::System.Span((void*)((byte*)ptr + 4), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 0), 1)[0]); + } + return array0; + + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields Clone() + { + var handle = this.Handle; + var result = TypesImportsInterop.Fields.CloneWasmInterop.wasmImportClone(handle); + var resource = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields.THandle(result)); + return resource; + + } + + } + + /** + * Represents an incoming HTTP Request. + */ + + internal class IncomingRequest: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal IncomingRequest(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[resource-drop]incoming-request"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method Method() + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.IncomingRequest.MethodWasmInterop.wasmImportMethod(handle, ptr); + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method lifted; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Get(); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Head(); + break; + } + case 2: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Post(); + break; + } + case 3: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Put(); + break; + } + case 4: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Delete(); + break; + } + case 5: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Connect(); + break; + } + case 6: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Options(); + break; + } + case 7: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Trace(); + break; + } + case 8: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Patch(); + break; + } + case 9: { + + var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 4), 1)[0], new global::System.Span((void*)((byte*)ptr + 8), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 8), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 4), 1)[0]); + } + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Other(str); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + return lifted; + + } + + internal unsafe string? PathWithQuery() + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.IncomingRequest.PathWithQueryWasmInterop.wasmImportPathWithQuery(handle, ptr); + + string? lifted; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 4), 1)[0], new global::System.Span((void*)((byte*)ptr + 8), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 8), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 4), 1)[0]); + } + + lifted = str; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 0, 1)[0])); + } + return lifted; + + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Scheme? Scheme() + { + var handle = this.Handle; + + var retArea = stackalloc uint[5]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.IncomingRequest.SchemeWasmInterop.wasmImportScheme(handle, ptr); + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Scheme? lifted8; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + lifted8 = null; + break; + } + + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Scheme lifted; + + switch (new global::System.Span((byte*)ptr + 4, 1)[0]) { + case 0: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Scheme.Http(); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Scheme.Https(); + break; + } + case 2: { + + var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 8), 1)[0], new global::System.Span((void*)((byte*)ptr + 12), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 12), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 8), 1)[0]); + } + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Scheme.Other(str); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 4, 1)[0]); + } + + lifted8 = lifted; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 0, 1)[0])); + } + return lifted8; + + } + + internal unsafe string? Authority() + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.IncomingRequest.AuthorityWasmInterop.wasmImportAuthority(handle, ptr); + + string? lifted; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 4), 1)[0], new global::System.Span((void*)((byte*)ptr + 8), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 8), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 4), 1)[0]); + } + + lifted = str; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 0, 1)[0])); + } + return lifted; + + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields Headers() + { + var handle = this.Handle; + var result = TypesImportsInterop.IncomingRequest.HeadersWasmInterop.wasmImportHeaders(handle); + var resource = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields.THandle(result)); + return resource; + + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.IncomingBody Consume() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.IncomingRequest.ConsumeWasmInterop.wasmImportConsume(handle, ptr); + + Result lifted; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.IncomingBody(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.IncomingBody.THandle(new global::System.Span((void*)((byte*)ptr + 4), 1)[0])); + + lifted = Result.Ok(resource); + break; + } + case 1: { + + lifted = Result.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)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. + */ + + internal class OutgoingRequest: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal OutgoingRequest(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[resource-drop]outgoing-request"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal unsafe OutgoingRequest(global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields headers) + { + var handle = headers.Handle; + headers.Handle = 0; + var result = TypesImportsInterop.OutgoingRequest.ConstructorWasmInterop.wasmImportConstructor(handle); + this.Handle = result; + + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.OutgoingBody Body() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.OutgoingRequest.BodyWasmInterop.wasmImportBody(handle, ptr); + + Result lifted; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.OutgoingBody(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.OutgoingBody.THandle(new global::System.Span((void*)((byte*)ptr + 4), 1)[0])); + + lifted = Result.Ok(resource); + break; + } + case 1: { + + lifted = Result.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return tmp; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method Method() + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.OutgoingRequest.MethodWasmInterop.wasmImportMethod(handle, ptr); + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method lifted; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Get(); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Head(); + break; + } + case 2: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Post(); + break; + } + case 3: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Put(); + break; + } + case 4: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Delete(); + break; + } + case 5: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Connect(); + break; + } + case 6: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Options(); + break; + } + case 7: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Trace(); + break; + } + case 8: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Patch(); + break; + } + case 9: { + + var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 4), 1)[0], new global::System.Span((void*)((byte*)ptr + 8), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 8), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 4), 1)[0]); + } + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method.Other(str); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + return lifted; + + } + + internal unsafe void SetMethod(global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Method method) + { + var cleanups = new global::System.Collections.Generic.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 = global::System.Text.Encoding.UTF8.GetBytes(payload26); + var length = utf8Bytes.Length; + var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes, global::System.Runtime.InteropServices.GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + lowered = 9; + lowered27 = strPtr.ToInt32(); + lowered28 = length; + + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + method); + } + var result = TypesImportsInterop.OutgoingRequest.SetMethodWasmInterop.wasmImportSetMethod(handle, lowered, lowered27, lowered28); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.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 unsafe string? PathWithQuery() + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.OutgoingRequest.PathWithQueryWasmInterop.wasmImportPathWithQuery(handle, ptr); + + string? lifted; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 4), 1)[0], new global::System.Span((void*)((byte*)ptr + 8), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 8), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 4), 1)[0]); + } + + lifted = str; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 0, 1)[0])); + } + return lifted; + + } + + internal unsafe void SetPathWithQuery(string? pathWithQuery) + { + var cleanups = new global::System.Collections.Generic.List(); + var handle = this.Handle; + + int lowered; + nint lowered3; + int lowered4; + + if (pathWithQuery != null) { + var payload2 = (string) pathWithQuery; + + var utf8Bytes = global::System.Text.Encoding.UTF8.GetBytes(payload2); + var length = utf8Bytes.Length; + var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes, global::System.Runtime.InteropServices.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 = TypesImportsInterop.OutgoingRequest.SetPathWithQueryWasmInterop.wasmImportSetPathWithQuery(handle, lowered, lowered3, lowered4); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.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 unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Scheme? Scheme() + { + var handle = this.Handle; + + var retArea = stackalloc uint[5]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.OutgoingRequest.SchemeWasmInterop.wasmImportScheme(handle, ptr); + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Scheme? lifted8; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + lifted8 = null; + break; + } + + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Scheme lifted; + + switch (new global::System.Span((byte*)ptr + 4, 1)[0]) { + case 0: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Scheme.Http(); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Scheme.Https(); + break; + } + case 2: { + + var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 8), 1)[0], new global::System.Span((void*)((byte*)ptr + 12), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 12), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 8), 1)[0]); + } + + lifted = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Scheme.Other(str); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 4, 1)[0]); + } + + lifted8 = lifted; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 0, 1)[0])); + } + return lifted8; + + } + + internal unsafe void SetScheme(global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Scheme? scheme) + { + var cleanups = new global::System.Collections.Generic.List(); + var handle = this.Handle; + + int lowered14; + int lowered15; + nint lowered16; + int lowered17; + + if (scheme != null) { + var payload2 = (global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.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 = global::System.Text.Encoding.UTF8.GetBytes(payload11); + var length = utf8Bytes.Length; + var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes, global::System.Runtime.InteropServices.GCHandleType.Pinned); + var strPtr = gcHandle.AddrOfPinnedObject(); + + cleanups.Add(()=> gcHandle.Free()); + + lowered = 2; + lowered12 = strPtr.ToInt32(); + lowered13 = length; + + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + payload2); + } + + lowered14 = 1; + lowered15 = lowered; + lowered16 = lowered12; + lowered17 = lowered13; + + } else { + + lowered14 = 0; + lowered15 = 0; + lowered16 = 0; + lowered17 = 0; + + } + var result = TypesImportsInterop.OutgoingRequest.SetSchemeWasmInterop.wasmImportSetScheme(handle, lowered14, lowered15, lowered16, lowered17); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.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 unsafe string? Authority() + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.OutgoingRequest.AuthorityWasmInterop.wasmImportAuthority(handle, ptr); + + string? lifted; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 4), 1)[0], new global::System.Span((void*)((byte*)ptr + 8), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 8), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 4), 1)[0]); + } + + lifted = str; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 0, 1)[0])); + } + return lifted; + + } + + internal unsafe void SetAuthority(string? authority) + { + var cleanups = new global::System.Collections.Generic.List(); + var handle = this.Handle; + + int lowered; + nint lowered3; + int lowered4; + + if (authority != null) { + var payload2 = (string) authority; + + var utf8Bytes = global::System.Text.Encoding.UTF8.GetBytes(payload2); + var length = utf8Bytes.Length; + var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes, global::System.Runtime.InteropServices.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 = TypesImportsInterop.OutgoingRequest.SetAuthorityWasmInterop.wasmImportSetAuthority(handle, lowered, lowered3, lowered4); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.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 unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields Headers() + { + var handle = this.Handle; + var result = TypesImportsInterop.OutgoingRequest.HeadersWasmInterop.wasmImportHeaders(handle); + var resource = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.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`. + */ + + internal class RequestOptions: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal RequestOptions(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[resource-drop]request-options"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal unsafe RequestOptions() + { + var result = TypesImportsInterop.RequestOptions.ConstructorWasmInterop.wasmImportConstructor(); + this.Handle = result; + + } + + internal unsafe ulong? ConnectTimeout() + { + var handle = this.Handle; + + var retArea = stackalloc ulong[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 8); + TypesImportsInterop.RequestOptions.ConnectTimeoutWasmInterop.wasmImportConnectTimeout(handle, ptr); + + ulong? lifted; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + lifted = unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 0, 1)[0])); + } + return lifted; + + } + + internal 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 = TypesImportsInterop.RequestOptions.SetConnectTimeoutWasmInterop.wasmImportSetConnectTimeout(handle, lowered, lowered3); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + result); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return ; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal unsafe ulong? FirstByteTimeout() + { + var handle = this.Handle; + + var retArea = stackalloc ulong[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 8); + TypesImportsInterop.RequestOptions.FirstByteTimeoutWasmInterop.wasmImportFirstByteTimeout(handle, ptr); + + ulong? lifted; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + lifted = unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 0, 1)[0])); + } + return lifted; + + } + + internal 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 = TypesImportsInterop.RequestOptions.SetFirstByteTimeoutWasmInterop.wasmImportSetFirstByteTimeout(handle, lowered, lowered3); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + result); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return ; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal unsafe ulong? BetweenBytesTimeout() + { + var handle = this.Handle; + + var retArea = stackalloc ulong[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 8); + TypesImportsInterop.RequestOptions.BetweenBytesTimeoutWasmInterop.wasmImportBetweenBytesTimeout(handle, ptr); + + ulong? lifted; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + lifted = unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 0, 1)[0])); + } + return lifted; + + } + + internal 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 = TypesImportsInterop.RequestOptions.SetBetweenBytesTimeoutWasmInterop.wasmImportSetBetweenBytesTimeout(handle, lowered, lowered3); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.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`. + */ + + internal class ResponseOutparam: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal ResponseOutparam(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[resource-drop]response-outparam"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal static unsafe void Set(global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ResponseOutparam param, Result response) + { + var cleanups = new global::System.Collections.Generic.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::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.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::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.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::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.DnsErrorPayload payload9 = payload3.AsDnsError; + + int lowered; + nint lowered16; + int lowered17; + + if (payload9.rcode != null) { + var payload15 = (string) payload9.rcode; + + var utf8Bytes = global::System.Text.Encoding.UTF8.GetBytes(payload15); + var length = utf8Bytes.Length; + var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes, global::System.Runtime.InteropServices.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::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.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 = global::System.Text.Encoding.UTF8.GetBytes(payload78); + var length81 = utf8Bytes80.Length; + var gcHandle82 = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes80, global::System.Runtime.InteropServices.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::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload? payload125 = payload3.AsHttpRequestHeaderSize; + + int lowered153; + int lowered154; + nint lowered155; + int lowered156; + int lowered157; + int lowered158; + + if (payload125 != null) { + var payload131 = (global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload) payload125; + + int lowered142; + nint lowered143; + int lowered144; + + if (payload131.fieldName != null) { + var payload137 = (string) payload131.fieldName; + + var utf8Bytes139 = global::System.Text.Encoding.UTF8.GetBytes(payload137); + var length140 = utf8Bytes139.Length; + var gcHandle141 = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes139, global::System.Runtime.InteropServices.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::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload payload172 = payload3.AsHttpRequestTrailerSize; + + int lowered183; + nint lowered184; + int lowered185; + + if (payload172.fieldName != null) { + var payload178 = (string) payload172.fieldName; + + var utf8Bytes180 = global::System.Text.Encoding.UTF8.GetBytes(payload178); + var length181 = utf8Bytes180.Length; + var gcHandle182 = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes180, global::System.Runtime.InteropServices.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::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload payload210 = payload3.AsHttpResponseHeaderSize; + + int lowered221; + nint lowered222; + int lowered223; + + if (payload210.fieldName != null) { + var payload216 = (string) payload210.fieldName; + + var utf8Bytes218 = global::System.Text.Encoding.UTF8.GetBytes(payload216); + var length219 = utf8Bytes218.Length; + var gcHandle220 = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes218, global::System.Runtime.InteropServices.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::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload payload256 = payload3.AsHttpResponseTrailerSize; + + int lowered267; + nint lowered268; + int lowered269; + + if (payload256.fieldName != null) { + var payload262 = (string) payload256.fieldName; + + var utf8Bytes264 = global::System.Text.Encoding.UTF8.GetBytes(payload262); + var length265 = utf8Bytes264.Length; + var gcHandle266 = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes264, global::System.Runtime.InteropServices.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 = global::System.Text.Encoding.UTF8.GetBytes(payload286); + var length289 = utf8Bytes288.Length; + var gcHandle290 = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes288, global::System.Runtime.InteropServices.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 = global::System.Text.Encoding.UTF8.GetBytes(payload302); + var length305 = utf8Bytes304.Length; + var gcHandle306 = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes304, global::System.Runtime.InteropServices.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 = global::System.Text.Encoding.UTF8.GetBytes(payload333); + var length336 = utf8Bytes335.Length; + var gcHandle337 = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes335, global::System.Runtime.InteropServices.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 global::System.ArgumentException("invalid discriminant: " + payload3); + } + + lowered348 = 1; + lowered349 = lowered341; + lowered350 = lowered342; + lowered351 = lowered343; + lowered352 = lowered344; + lowered353 = lowered345; + lowered354 = lowered346; + lowered355 = lowered347; + + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + response); + } + TypesImportsInterop.ResponseOutparam.SetWasmInterop.wasmImportSet(handle, lowered348, lowered349, lowered350, lowered351, lowered352, lowered353, lowered354, lowered355); + + foreach (var cleanup in cleanups) + { + cleanup(); + } + + } + + } + + /** + * Represents an incoming HTTP Response. + */ + + internal class IncomingResponse: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal IncomingResponse(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[resource-drop]incoming-response"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal unsafe ushort Status() + { + var handle = this.Handle; + var result = TypesImportsInterop.IncomingResponse.StatusWasmInterop.wasmImportStatus(handle); + return ((ushort)result); + + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields Headers() + { + var handle = this.Handle; + var result = TypesImportsInterop.IncomingResponse.HeadersWasmInterop.wasmImportHeaders(handle); + var resource = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields.THandle(result)); + return resource; + + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.IncomingBody Consume() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.IncomingResponse.ConsumeWasmInterop.wasmImportConsume(handle, ptr); + + Result lifted; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.IncomingBody(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.IncomingBody.THandle(new global::System.Span((void*)((byte*)ptr + 4), 1)[0])); + + lifted = Result.Ok(resource); + break; + } + case 1: { + + lifted = Result.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)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. + */ + + internal class IncomingBody: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal IncomingBody(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[resource-drop]incoming-body"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.InputStream Stream() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.IncomingBody.StreamWasmInterop.wasmImportStream(handle, ptr); + + Result lifted; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.InputStream(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.InputStream.THandle(new global::System.Span((void*)((byte*)ptr + 4), 1)[0])); + + lifted = Result.Ok(resource); + break; + } + case 1: { + + lifted = Result.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return tmp; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal static unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FutureTrailers Finish(global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.IncomingBody @this) + { + var handle = @this.Handle; + @this.Handle = 0; + var result = TypesImportsInterop.IncomingBody.FinishWasmInterop.wasmImportFinish(handle); + var resource = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FutureTrailers(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FutureTrailers.THandle(result)); + return resource; + + } + + } + + /** + * Represents a future which may eventually return trailers, or an error. + * + * In the case that the incoming HTTP Request or Response did not have any + * trailers, this future will resolve to the empty set of trailers once the + * complete Request or Response body has been received. + */ + + internal class FutureTrailers: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal FutureTrailers(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[resource-drop]future-trailers"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable Subscribe() + { + var handle = this.Handle; + var result = TypesImportsInterop.FutureTrailers.SubscribeWasmInterop.wasmImportSubscribe(handle); + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable.THandle(result)); + return resource; + + } + + internal unsafe Result, None>? Get() + { + var handle = this.Handle; + + var retArea = stackalloc ulong[8]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 8); + TypesImportsInterop.FutureTrailers.GetWasmInterop.wasmImportGet(handle, ptr); + + Result, None>? lifted213; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + lifted213 = null; + break; + } + + case 1: { + + Result, None> lifted212; + + switch (new global::System.Span((byte*)ptr + 8, 1)[0]) { + case 0: { + + Result lifted209; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields? lifted; + + switch (new global::System.Span((byte*)ptr + 24, 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields.THandle(new global::System.Span((void*)((byte*)ptr + 28), 1)[0])); + + lifted = resource; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 24, 1)[0])); + } + + lifted209 = Result.Ok(lifted); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode lifted208; + + switch (new global::System.Span((byte*)ptr + 24, 1)[0]) { + case 0: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DnsTimeout(); + break; + } + case 1: { + + string? lifted20; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted20 = null; + break; + } + + case 1: { + + var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0], new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 40), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0]); + } + + lifted20 = str; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + ushort? lifted25; + + switch (new global::System.Span((byte*)ptr + 44, 1)[0]) { + case 0: { + lifted25 = null; + break; + } + + case 1: { + + lifted25 = ((ushort)new global::System.Span((void*)((byte*)ptr + 46), 1)[0]); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 44, 1)[0])); + } + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DnsError(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.DnsErrorPayload ( + lifted20, lifted25)); + break; + } + case 2: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationNotFound(); + break; + } + case 3: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationUnavailable(); + break; + } + case 4: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationIpProhibited(); + break; + } + case 5: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationIpUnroutable(); + break; + } + case 6: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionRefused(); + break; + } + case 7: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionTerminated(); + break; + } + case 8: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionTimeout(); + break; + } + case 9: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionReadTimeout(); + break; + } + case 10: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionWriteTimeout(); + break; + } + case 11: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionLimitReached(); + break; + } + case 12: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.TlsProtocolError(); + break; + } + case 13: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.TlsCertificateError(); + break; + } + case 14: { + + byte? lifted56; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted56 = null; + break; + } + + case 1: { + + lifted56 = ((byte)new global::System.Span((byte*)ptr + 33, 1)[0]); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + string? lifted62; + + switch (new global::System.Span((byte*)ptr + 36, 1)[0]) { + case 0: { + lifted62 = null; + break; + } + + case 1: { + + var str61 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 40), 1)[0], new global::System.Span((void*)((byte*)ptr + 44), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 44), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + } + + lifted62 = str61; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 36, 1)[0])); + } + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.TlsAlertReceived(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.TlsAlertReceivedPayload ( + lifted56, lifted62)); + break; + } + case 15: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestDenied(); + break; + } + case 16: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestLengthRequired(); + break; + } + case 17: { + + ulong? lifted73; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted73 = null; + break; + } + + case 1: { + + lifted73 = unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 40), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestBodySize(lifted73); + break; + } + case 18: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestMethodInvalid(); + break; + } + case 19: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestUriInvalid(); + break; + } + case 20: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestUriTooLong(); + break; + } + case 21: { + + uint? lifted86; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted86 = null; + break; + } + + case 1: { + + lifted86 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 36), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestHeaderSectionSize(lifted86); + break; + } + case 22: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload? lifted104; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted104 = null; + break; + } + + case 1: { + + string? lifted98; + + switch (new global::System.Span((byte*)ptr + 36, 1)[0]) { + case 0: { + lifted98 = null; + break; + } + + case 1: { + + var str97 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 40), 1)[0], new global::System.Span((void*)((byte*)ptr + 44), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 44), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + } + + lifted98 = str97; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 36, 1)[0])); + } + + uint? lifted103; + + switch (new global::System.Span((byte*)ptr + 48, 1)[0]) { + case 0: { + lifted103 = null; + break; + } + + case 1: { + + lifted103 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 52), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 48, 1)[0])); + } + + lifted104 = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted98, lifted103); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestHeaderSize(lifted104); + break; + } + case 23: { + + uint? lifted111; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted111 = null; + break; + } + + case 1: { + + lifted111 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 36), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestTrailerSectionSize(lifted111); + break; + } + case 24: { + + string? lifted119; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted119 = null; + break; + } + + case 1: { + + var str118 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0], new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 40), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0]); + } + + lifted119 = str118; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + uint? lifted124; + + switch (new global::System.Span((byte*)ptr + 44, 1)[0]) { + case 0: { + lifted124 = null; + break; + } + + case 1: { + + lifted124 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 48), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 44, 1)[0])); + } + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestTrailerSize(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted119, lifted124)); + break; + } + case 25: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseIncomplete(); + break; + } + case 26: { + + uint? lifted133; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted133 = null; + break; + } + + case 1: { + + lifted133 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 36), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseHeaderSectionSize(lifted133); + break; + } + case 27: { + + string? lifted141; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted141 = null; + break; + } + + case 1: { + + var str140 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0], new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 40), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0]); + } + + lifted141 = str140; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + uint? lifted146; + + switch (new global::System.Span((byte*)ptr + 44, 1)[0]) { + case 0: { + lifted146 = null; + break; + } + + case 1: { + + lifted146 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 48), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 44, 1)[0])); + } + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseHeaderSize(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted141, lifted146)); + break; + } + case 28: { + + ulong? lifted153; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted153 = null; + break; + } + + case 1: { + + lifted153 = unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 40), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseBodySize(lifted153); + break; + } + case 29: { + + uint? lifted160; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted160 = null; + break; + } + + case 1: { + + lifted160 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 36), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTrailerSectionSize(lifted160); + break; + } + case 30: { + + string? lifted168; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted168 = null; + break; + } + + case 1: { + + var str167 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0], new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 40), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0]); + } + + lifted168 = str167; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + uint? lifted173; + + switch (new global::System.Span((byte*)ptr + 44, 1)[0]) { + case 0: { + lifted173 = null; + break; + } + + case 1: { + + lifted173 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 48), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 44, 1)[0])); + } + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTrailerSize(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted168, lifted173)); + break; + } + case 31: { + + string? lifted181; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted181 = null; + break; + } + + case 1: { + + var str180 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0], new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 40), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0]); + } + + lifted181 = str180; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTransferCoding(lifted181); + break; + } + case 32: { + + string? lifted189; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted189 = null; + break; + } + + case 1: { + + var str188 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0], new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 40), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0]); + } + + lifted189 = str188; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseContentCoding(lifted189); + break; + } + case 33: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTimeout(); + break; + } + case 34: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpUpgradeFailed(); + break; + } + case 35: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpProtocolError(); + break; + } + case 36: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.LoopDetected(); + break; + } + case 37: { + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConfigurationError(); + break; + } + case 38: { + + string? lifted207; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted207 = null; + break; + } + + case 1: { + + var str206 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0], new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 40), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0]); + } + + lifted207 = str206; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted208 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.InternalError(lifted207); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 24, 1)[0]); + } + + lifted209 = Result.Err(lifted208); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 16, 1)[0]); + } + + lifted212 = Result, None>.Ok(lifted209); + break; + } + case 1: { + + lifted212 = Result, None>.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 8, 1)[0]); + } + + lifted213 = lifted212; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 0, 1)[0])); + } + return lifted213; + + } + + } + + /** + * Represents an outgoing HTTP Response. + */ + + internal class OutgoingResponse: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal OutgoingResponse(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[resource-drop]outgoing-response"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal unsafe OutgoingResponse(global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields headers) + { + var handle = headers.Handle; + headers.Handle = 0; + var result = TypesImportsInterop.OutgoingResponse.ConstructorWasmInterop.wasmImportConstructor(handle); + this.Handle = result; + + } + + internal unsafe ushort StatusCode() + { + var handle = this.Handle; + var result = TypesImportsInterop.OutgoingResponse.StatusCodeWasmInterop.wasmImportStatusCode(handle); + return ((ushort)result); + + } + + internal unsafe void SetStatusCode(ushort statusCode) + { + var handle = this.Handle; + var result = TypesImportsInterop.OutgoingResponse.SetStatusCodeWasmInterop.wasmImportSetStatusCode(handle, statusCode); + + Result lifted; + + switch (result) { + case 0: { + + lifted = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + lifted = Result.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + result); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return ; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields Headers() + { + var handle = this.Handle; + var result = TypesImportsInterop.OutgoingResponse.HeadersWasmInterop.wasmImportHeaders(handle); + var resource = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields.THandle(result)); + return resource; + + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.OutgoingBody Body() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.OutgoingResponse.BodyWasmInterop.wasmImportBody(handle, ptr); + + Result lifted; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.OutgoingBody(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.OutgoingBody.THandle(new global::System.Span((void*)((byte*)ptr + 4), 1)[0])); + + lifted = Result.Ok(resource); + break; + } + case 1: { + + lifted = Result.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)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 occurred. The implementation should propagate this + * error to the HTTP protocol by whatever means it has available, + * including: corrupting the body on the wire, aborting the associated + * Request, or sending a late status code for the Response. + */ + + internal class OutgoingBody: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal OutgoingBody(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[resource-drop]outgoing-body"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.OutputStream Write() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + TypesImportsInterop.OutgoingBody.WriteWasmInterop.wasmImportWrite(handle, ptr); + + Result lifted; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.OutputStream(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.OutputStream.THandle(new global::System.Span((void*)((byte*)ptr + 4), 1)[0])); + + lifted = Result.Ok(resource); + break; + } + case 1: { + + lifted = Result.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted.IsOk) + { + var tmp = lifted.AsOk; + return tmp; + } + else + { + throw new WitException(lifted.AsErr!, 0); + } + + } + + internal static unsafe void Finish(global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.OutgoingBody @this, global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields? trailers) + { + var handle = @this.Handle; + @this.Handle = 0; + + int lowered; + int lowered4; + + if (trailers != null) { + var payload2 = (global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.Fields) trailers; + var handle3 = payload2.Handle; + payload2.Handle = 0; + + lowered = 1; + lowered4 = handle3; + + } else { + + lowered = 0; + lowered4 = 0; + + } + + var retArea = stackalloc ulong[6]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 8); + TypesImportsInterop.OutgoingBody.FinishWasmInterop.wasmImportFinish(handle, lowered, lowered4, ptr); + + Result lifted205; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted205 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode lifted204; + + switch (new global::System.Span((byte*)ptr + 8, 1)[0]) { + case 0: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DnsTimeout(); + break; + } + case 1: { + + string? lifted; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted = str; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + ushort? lifted21; + + switch (new global::System.Span((byte*)ptr + 28, 1)[0]) { + case 0: { + lifted21 = null; + break; + } + + case 1: { + + lifted21 = ((ushort)new global::System.Span((void*)((byte*)ptr + 30), 1)[0]); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 28, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DnsError(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.DnsErrorPayload ( + lifted, lifted21)); + break; + } + case 2: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationNotFound(); + break; + } + case 3: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationUnavailable(); + break; + } + case 4: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationIpProhibited(); + break; + } + case 5: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationIpUnroutable(); + break; + } + case 6: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionRefused(); + break; + } + case 7: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionTerminated(); + break; + } + case 8: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionTimeout(); + break; + } + case 9: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionReadTimeout(); + break; + } + case 10: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionWriteTimeout(); + break; + } + case 11: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionLimitReached(); + break; + } + case 12: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.TlsProtocolError(); + break; + } + case 13: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.TlsCertificateError(); + break; + } + case 14: { + + byte? lifted52; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted52 = null; + break; + } + + case 1: { + + lifted52 = ((byte)new global::System.Span((byte*)ptr + 17, 1)[0]); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + string? lifted58; + + switch (new global::System.Span((byte*)ptr + 20, 1)[0]) { + case 0: { + lifted58 = null; + break; + } + + case 1: { + + var str57 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 24), 1)[0], new global::System.Span((void*)((byte*)ptr + 28), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 28), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + } + + lifted58 = str57; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 20, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.TlsAlertReceived(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.TlsAlertReceivedPayload ( + lifted52, lifted58)); + break; + } + case 15: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestDenied(); + break; + } + case 16: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestLengthRequired(); + break; + } + case 17: { + + ulong? lifted69; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted69 = null; + break; + } + + case 1: { + + lifted69 = unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 24), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestBodySize(lifted69); + break; + } + case 18: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestMethodInvalid(); + break; + } + case 19: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestUriInvalid(); + break; + } + case 20: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestUriTooLong(); + break; + } + case 21: { + + uint? lifted82; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted82 = null; + break; + } + + case 1: { + + lifted82 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 20), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestHeaderSectionSize(lifted82); + break; + } + case 22: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload? lifted100; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted100 = null; + break; + } + + case 1: { + + string? lifted94; + + switch (new global::System.Span((byte*)ptr + 20, 1)[0]) { + case 0: { + lifted94 = null; + break; + } + + case 1: { + + var str93 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 24), 1)[0], new global::System.Span((void*)((byte*)ptr + 28), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 28), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + } + + lifted94 = str93; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 20, 1)[0])); + } + + uint? lifted99; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted99 = null; + break; + } + + case 1: { + + lifted99 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 36), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted100 = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted94, lifted99); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestHeaderSize(lifted100); + break; + } + case 23: { + + uint? lifted107; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted107 = null; + break; + } + + case 1: { + + lifted107 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 20), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestTrailerSectionSize(lifted107); + break; + } + case 24: { + + string? lifted115; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted115 = null; + break; + } + + case 1: { + + var str114 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted115 = str114; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + uint? lifted120; + + switch (new global::System.Span((byte*)ptr + 28, 1)[0]) { + case 0: { + lifted120 = null; + break; + } + + case 1: { + + lifted120 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 32), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 28, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestTrailerSize(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted115, lifted120)); + break; + } + case 25: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseIncomplete(); + break; + } + case 26: { + + uint? lifted129; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted129 = null; + break; + } + + case 1: { + + lifted129 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 20), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseHeaderSectionSize(lifted129); + break; + } + case 27: { + + string? lifted137; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted137 = null; + break; + } + + case 1: { + + var str136 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted137 = str136; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + uint? lifted142; + + switch (new global::System.Span((byte*)ptr + 28, 1)[0]) { + case 0: { + lifted142 = null; + break; + } + + case 1: { + + lifted142 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 32), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 28, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseHeaderSize(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted137, lifted142)); + break; + } + case 28: { + + ulong? lifted149; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted149 = null; + break; + } + + case 1: { + + lifted149 = unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 24), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseBodySize(lifted149); + break; + } + case 29: { + + uint? lifted156; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted156 = null; + break; + } + + case 1: { + + lifted156 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 20), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTrailerSectionSize(lifted156); + break; + } + case 30: { + + string? lifted164; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted164 = null; + break; + } + + case 1: { + + var str163 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted164 = str163; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + uint? lifted169; + + switch (new global::System.Span((byte*)ptr + 28, 1)[0]) { + case 0: { + lifted169 = null; + break; + } + + case 1: { + + lifted169 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 32), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 28, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTrailerSize(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted164, lifted169)); + break; + } + case 31: { + + string? lifted177; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted177 = null; + break; + } + + case 1: { + + var str176 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted177 = str176; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTransferCoding(lifted177); + break; + } + case 32: { + + string? lifted185; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted185 = null; + break; + } + + case 1: { + + var str184 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted185 = str184; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseContentCoding(lifted185); + break; + } + case 33: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTimeout(); + break; + } + case 34: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpUpgradeFailed(); + break; + } + case 35: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpProtocolError(); + break; + } + case 36: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.LoopDetected(); + break; + } + case 37: { + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConfigurationError(); + break; + } + case 38: { + + string? lifted203; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + lifted203 = null; + break; + } + + case 1: { + + var str202 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0], new global::System.Span((void*)((byte*)ptr + 24), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 24), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 20), 1)[0]); + } + + lifted203 = str202; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 16, 1)[0])); + } + + lifted204 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.InternalError(lifted203); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 8, 1)[0]); + } + + lifted205 = Result.Err(lifted204); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted205.IsOk) + { + var tmp = lifted205.AsOk; + return ; + } + else + { + throw new WitException(lifted205.AsErr!, 0); + } + + } + + } + + /** + * Represents a future which may eventually return an incoming HTTP + * Response, or an error. + * + * This resource is returned by the `wasi:http/outgoing-handler` interface to + * provide the HTTP Response corresponding to the sent Request. + */ + + internal class FutureIncomingResponse: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal FutureIncomingResponse(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[resource-drop]future-incoming-response"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable Subscribe() + { + var handle = this.Handle; + var result = TypesImportsInterop.FutureIncomingResponse.SubscribeWasmInterop.wasmImportSubscribe(handle); + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable.THandle(result)); + return resource; + + } + + internal unsafe Result, None>? Get() + { + var handle = this.Handle; + + var retArea = stackalloc ulong[8]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 8); + TypesImportsInterop.FutureIncomingResponse.GetWasmInterop.wasmImportGet(handle, ptr); + + Result, None>? lifted208; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + lifted208 = null; + break; + } + + case 1: { + + Result, None> lifted207; + + switch (new global::System.Span((byte*)ptr + 8, 1)[0]) { + case 0: { + + Result lifted204; + + switch (new global::System.Span((byte*)ptr + 16, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.IncomingResponse(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.IncomingResponse.THandle(new global::System.Span((void*)((byte*)ptr + 24), 1)[0])); + + lifted204 = Result.Ok(resource); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode lifted203; + + switch (new global::System.Span((byte*)ptr + 24, 1)[0]) { + case 0: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DnsTimeout(); + break; + } + case 1: { + + string? lifted; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted = null; + break; + } + + case 1: { + + var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0], new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 40), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0]); + } + + lifted = str; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + ushort? lifted20; + + switch (new global::System.Span((byte*)ptr + 44, 1)[0]) { + case 0: { + lifted20 = null; + break; + } + + case 1: { + + lifted20 = ((ushort)new global::System.Span((void*)((byte*)ptr + 46), 1)[0]); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 44, 1)[0])); + } + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DnsError(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.DnsErrorPayload ( + lifted, lifted20)); + break; + } + case 2: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationNotFound(); + break; + } + case 3: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationUnavailable(); + break; + } + case 4: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationIpProhibited(); + break; + } + case 5: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.DestinationIpUnroutable(); + break; + } + case 6: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionRefused(); + break; + } + case 7: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionTerminated(); + break; + } + case 8: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionTimeout(); + break; + } + case 9: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionReadTimeout(); + break; + } + case 10: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionWriteTimeout(); + break; + } + case 11: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConnectionLimitReached(); + break; + } + case 12: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.TlsProtocolError(); + break; + } + case 13: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.TlsCertificateError(); + break; + } + case 14: { + + byte? lifted51; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted51 = null; + break; + } + + case 1: { + + lifted51 = ((byte)new global::System.Span((byte*)ptr + 33, 1)[0]); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + string? lifted57; + + switch (new global::System.Span((byte*)ptr + 36, 1)[0]) { + case 0: { + lifted57 = null; + break; + } + + case 1: { + + var str56 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 40), 1)[0], new global::System.Span((void*)((byte*)ptr + 44), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 44), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + } + + lifted57 = str56; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 36, 1)[0])); + } + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.TlsAlertReceived(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.TlsAlertReceivedPayload ( + lifted51, lifted57)); + break; + } + case 15: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestDenied(); + break; + } + case 16: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestLengthRequired(); + break; + } + case 17: { + + ulong? lifted68; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted68 = null; + break; + } + + case 1: { + + lifted68 = unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 40), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestBodySize(lifted68); + break; + } + case 18: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestMethodInvalid(); + break; + } + case 19: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestUriInvalid(); + break; + } + case 20: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestUriTooLong(); + break; + } + case 21: { + + uint? lifted81; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted81 = null; + break; + } + + case 1: { + + lifted81 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 36), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestHeaderSectionSize(lifted81); + break; + } + case 22: { + + global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload? lifted99; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted99 = null; + break; + } + + case 1: { + + string? lifted93; + + switch (new global::System.Span((byte*)ptr + 36, 1)[0]) { + case 0: { + lifted93 = null; + break; + } + + case 1: { + + var str92 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 40), 1)[0], new global::System.Span((void*)((byte*)ptr + 44), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 44), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + } + + lifted93 = str92; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 36, 1)[0])); + } + + uint? lifted98; + + switch (new global::System.Span((byte*)ptr + 48, 1)[0]) { + case 0: { + lifted98 = null; + break; + } + + case 1: { + + lifted98 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 52), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 48, 1)[0])); + } + + lifted99 = new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted93, lifted98); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestHeaderSize(lifted99); + break; + } + case 23: { + + uint? lifted106; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted106 = null; + break; + } + + case 1: { + + lifted106 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 36), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestTrailerSectionSize(lifted106); + break; + } + case 24: { + + string? lifted114; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted114 = null; + break; + } + + case 1: { + + var str113 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0], new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 40), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0]); + } + + lifted114 = str113; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + uint? lifted119; + + switch (new global::System.Span((byte*)ptr + 44, 1)[0]) { + case 0: { + lifted119 = null; + break; + } + + case 1: { + + lifted119 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 48), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 44, 1)[0])); + } + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpRequestTrailerSize(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted114, lifted119)); + break; + } + case 25: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseIncomplete(); + break; + } + case 26: { + + uint? lifted128; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted128 = null; + break; + } + + case 1: { + + lifted128 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 36), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseHeaderSectionSize(lifted128); + break; + } + case 27: { + + string? lifted136; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted136 = null; + break; + } + + case 1: { + + var str135 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0], new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 40), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0]); + } + + lifted136 = str135; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + uint? lifted141; + + switch (new global::System.Span((byte*)ptr + 44, 1)[0]) { + case 0: { + lifted141 = null; + break; + } + + case 1: { + + lifted141 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 48), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 44, 1)[0])); + } + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseHeaderSize(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted136, lifted141)); + break; + } + case 28: { + + ulong? lifted148; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted148 = null; + break; + } + + case 1: { + + lifted148 = unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 40), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseBodySize(lifted148); + break; + } + case 29: { + + uint? lifted155; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted155 = null; + break; + } + + case 1: { + + lifted155 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 36), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTrailerSectionSize(lifted155); + break; + } + case 30: { + + string? lifted163; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted163 = null; + break; + } + + case 1: { + + var str162 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0], new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 40), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0]); + } + + lifted163 = str162; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + uint? lifted168; + + switch (new global::System.Span((byte*)ptr + 44, 1)[0]) { + case 0: { + lifted168 = null; + break; + } + + case 1: { + + lifted168 = unchecked((uint)(new global::System.Span((void*)((byte*)ptr + 48), 1)[0])); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 44, 1)[0])); + } + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTrailerSize(new global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.FieldSizePayload ( + lifted163, lifted168)); + break; + } + case 31: { + + string? lifted176; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted176 = null; + break; + } + + case 1: { + + var str175 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0], new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 40), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0]); + } + + lifted176 = str175; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTransferCoding(lifted176); + break; + } + case 32: { + + string? lifted184; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted184 = null; + break; + } + + case 1: { + + var str183 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0], new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 40), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0]); + } + + lifted184 = str183; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseContentCoding(lifted184); + break; + } + case 33: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpResponseTimeout(); + break; + } + case 34: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpUpgradeFailed(); + break; + } + case 35: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.HttpProtocolError(); + break; + } + case 36: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.LoopDetected(); + break; + } + case 37: { + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.ConfigurationError(); + break; + } + case 38: { + + string? lifted202; + + switch (new global::System.Span((byte*)ptr + 32, 1)[0]) { + case 0: { + lifted202 = null; + break; + } + + case 1: { + + var str201 = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0], new global::System.Span((void*)((byte*)ptr + 40), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 40), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 36), 1)[0]); + } + + lifted202 = str201; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 32, 1)[0])); + } + + lifted203 = global::WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports.ErrorCode.InternalError(lifted202); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 24, 1)[0]); + } + + lifted204 = Result.Err(lifted203); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 16, 1)[0]); + } + + lifted207 = Result, None>.Ok(lifted204); + break; + } + case 1: { + + lifted207 = Result, None>.Err(new global::WasiHttpWorld.None()); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 8, 1)[0]); + } + + lifted208 = lifted207; + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant: " + (new global::System.Span((byte*)ptr + 0, 1)[0])); + } + return lifted208; + + } + + } + +} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.OutgoingHandlerImportsInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.OutgoingHandlerImportsInterop.cs new file mode 100644 index 00000000000000..867a8cc21b5226 --- /dev/null +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.OutgoingHandlerImportsInterop.cs @@ -0,0 +1,18 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +using System; + +namespace WasiHttpWorld.wit.Imports.wasi.http.v0_2_8 +{ + internal static class OutgoingHandlerImportsInterop { + + public static class HandleWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/outgoing-handler@0.2.8", EntryPoint = "handle"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportHandle(int p0, int p1, int p2, nint p3); + } + + } +} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.TypesImportsInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.TypesImportsInterop.cs new file mode 100644 index 00000000000000..581be2a45e43cc --- /dev/null +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.TypesImportsInterop.cs @@ -0,0 +1,373 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +using System; + +namespace WasiHttpWorld.wit.Imports.wasi.http.v0_2_8 +{ + internal static class TypesImportsInterop { + + public static class HttpErrorCodeWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "http-error-code"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportHttpErrorCode(int p0, nint p1); + } + + internal static class Fields + { + + public static class ConstructorWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[constructor]fields"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportConstructor(); + } + + public static class FromListWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[static]fields.from-list"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportFromList(nint p0, int p1, nint p2); + } + + public static class GetWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]fields.get"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportGet(int p0, nint p1, int p2, nint p3); + } + + public static class HasWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]fields.has"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportHas(int p0, nint p1, int p2); + } + + public static class SetWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]fields.set"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportSet(int p0, nint p1, int p2, nint p3, int p4, nint p5); + } + + public static class DeleteWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]fields.delete"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportDelete(int p0, nint p1, int p2, nint p3); + } + + public static class AppendWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]fields.append"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportAppend(int p0, nint p1, int p2, nint p3, int p4, nint p5); + } + + public static class EntriesWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]fields.entries"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportEntries(int p0, nint p1); + } + + public static class CloneWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]fields.clone"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportClone(int p0); + } + + } + + internal static class IncomingRequest + { + + public static class MethodWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]incoming-request.method"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportMethod(int p0, nint p1); + } + + public static class PathWithQueryWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]incoming-request.path-with-query"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportPathWithQuery(int p0, nint p1); + } + + public static class SchemeWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]incoming-request.scheme"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportScheme(int p0, nint p1); + } + + public static class AuthorityWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]incoming-request.authority"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportAuthority(int p0, nint p1); + } + + public static class HeadersWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]incoming-request.headers"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportHeaders(int p0); + } + + public static class ConsumeWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]incoming-request.consume"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportConsume(int p0, nint p1); + } + + } + + internal static class OutgoingRequest + { + + public static class ConstructorWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[constructor]outgoing-request"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportConstructor(int p0); + } + + public static class BodyWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]outgoing-request.body"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportBody(int p0, nint p1); + } + + public static class MethodWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]outgoing-request.method"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportMethod(int p0, nint p1); + } + + public static class SetMethodWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]outgoing-request.set-method"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSetMethod(int p0, int p1, nint p2, int p3); + } + + public static class PathWithQueryWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]outgoing-request.path-with-query"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportPathWithQuery(int p0, nint p1); + } + + public static class SetPathWithQueryWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]outgoing-request.set-path-with-query"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSetPathWithQuery(int p0, int p1, nint p2, int p3); + } + + public static class SchemeWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]outgoing-request.scheme"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportScheme(int p0, nint p1); + } + + public static class SetSchemeWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]outgoing-request.set-scheme"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSetScheme(int p0, int p1, int p2, nint p3, int p4); + } + + public static class AuthorityWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]outgoing-request.authority"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportAuthority(int p0, nint p1); + } + + public static class SetAuthorityWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]outgoing-request.set-authority"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSetAuthority(int p0, int p1, nint p2, int p3); + } + + public static class HeadersWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]outgoing-request.headers"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportHeaders(int p0); + } + + } + + internal static class RequestOptions + { + + public static class ConstructorWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[constructor]request-options"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportConstructor(); + } + + public static class ConnectTimeoutWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]request-options.connect-timeout"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportConnectTimeout(int p0, nint p1); + } + + public static class SetConnectTimeoutWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]request-options.set-connect-timeout"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSetConnectTimeout(int p0, int p1, long p2); + } + + public static class FirstByteTimeoutWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]request-options.first-byte-timeout"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportFirstByteTimeout(int p0, nint p1); + } + + public static class SetFirstByteTimeoutWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]request-options.set-first-byte-timeout"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSetFirstByteTimeout(int p0, int p1, long p2); + } + + public static class BetweenBytesTimeoutWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]request-options.between-bytes-timeout"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportBetweenBytesTimeout(int p0, nint p1); + } + + public static class SetBetweenBytesTimeoutWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]request-options.set-between-bytes-timeout"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSetBetweenBytesTimeout(int p0, int p1, long p2); + } + + } + + internal static class ResponseOutparam + { + + public static class SetWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[static]response-outparam.set"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportSet(int p0, int p1, int p2, int p3, long p4, nint p5, nint p6, int p7, int p8); + } + + } + + internal static class IncomingResponse + { + + public static class StatusWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]incoming-response.status"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportStatus(int p0); + } + + public static class HeadersWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]incoming-response.headers"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportHeaders(int p0); + } + + public static class ConsumeWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]incoming-response.consume"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportConsume(int p0, nint p1); + } + + } + + internal static class IncomingBody + { + + public static class StreamWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]incoming-body.stream"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportStream(int p0, nint p1); + } + + public static class FinishWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[static]incoming-body.finish"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportFinish(int p0); + } + + } + + internal static class FutureTrailers + { + + public static class SubscribeWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]future-trailers.subscribe"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSubscribe(int p0); + } + + public static class GetWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]future-trailers.get"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportGet(int p0, nint p1); + } + + } + + internal static class OutgoingResponse + { + + public static class ConstructorWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[constructor]outgoing-response"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportConstructor(int p0); + } + + public static class StatusCodeWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]outgoing-response.status-code"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportStatusCode(int p0); + } + + public static class SetStatusCodeWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]outgoing-response.set-status-code"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSetStatusCode(int p0, int p1); + } + + public static class HeadersWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]outgoing-response.headers"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportHeaders(int p0); + } + + public static class BodyWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]outgoing-response.body"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportBody(int p0, nint p1); + } + + } + + internal static class OutgoingBody + { + + public static class WriteWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]outgoing-body.write"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportWrite(int p0, nint p1); + } + + public static class FinishWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[static]outgoing-body.finish"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportFinish(int p0, int p1, int p2, nint p3); + } + + } + + internal static class FutureIncomingResponse + { + + public static class SubscribeWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]future-incoming-response.subscribe"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSubscribe(int p0); + } + + public static class GetWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:http/types@0.2.8", EntryPoint = "[method]future-incoming-response.get"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportGet(int p0, nint p1); + } + + } + + } +} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.ErrorImportsInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.ErrorImportsInterop.cs new file mode 100644 index 00000000000000..ee93411e1201cd --- /dev/null +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.ErrorImportsInterop.cs @@ -0,0 +1,23 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +using System; + +namespace WasiHttpWorld.wit.Imports.wasi.io.v0_2_8 +{ + internal static class ErrorImportsInterop { + + internal static class Error + { + + public static class ToDebugStringWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/error@0.2.8", EntryPoint = "[method]error.to-debug-string"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportToDebugString(int p0, nint p1); + } + + } + + } +} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.cs new file mode 100644 index 00000000000000..797d8eb71bb2c6 --- /dev/null +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.cs @@ -0,0 +1,71 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +namespace WasiHttpWorld.wit.Imports.wasi.io.v0_2_8; + +internal interface IErrorImports { + + /** + * A resource which represents some error information. + * + * The only method provided by this resource is `to-debug-string`, + * which provides some human-readable information about the error. + * + * In the `wasi:io` package, this resource is returned through the + * `wasi:io/streams/stream-error` type. + * + * To provide more specific error information, other interfaces may + * offer functions to "downcast" this error into more specific types. For example, + * errors returned from streams derived from filesystem types can be described using + * the filesystem's own error-code type. This is done using the function + * `wasi:filesystem/types/filesystem-error-code`, which takes a `borrow<error>` + * parameter and returns an `option<wasi:filesystem/types/error-code>`. + * + * The set of functions which can "downcast" an `error` into a more + * concrete type is open. + */ + + internal class Error: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal Error(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/error@0.2.8", EntryPoint = "[resource-drop]error"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal unsafe string ToDebugString() + { + var handle = this.Handle; + + var retArea = stackalloc uint[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + ErrorImportsInterop.Error.ToDebugStringWasmInterop.wasmImportToDebugString(handle, ptr); + + var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span((void*)((byte*)ptr + 0), 1)[0], new global::System.Span((void*)((byte*)ptr + 4), 1)[0]); + if (new global::System.Span((void*)((byte*)ptr + 4), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 0), 1)[0]); + } + + return str; + + } + + } + +} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.cs new file mode 100644 index 00000000000000..875790576f7623 --- /dev/null +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.cs @@ -0,0 +1,96 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +namespace WasiHttpWorld.wit.Imports.wasi.io.v0_2_8; + +internal interface IPollImports { + + /** + * `pollable` represents a single I/O event which may be ready, or not. + */ + + internal class Pollable: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal Pollable(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/poll@0.2.8", EntryPoint = "[resource-drop]pollable"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal unsafe bool Ready() + { + var handle = this.Handle; + var result = PollImportsInterop.Pollable.ReadyWasmInterop.wasmImportReady(handle); + return (result != 0); + + } + + internal unsafe void Block() + { + var handle = this.Handle; + PollImportsInterop.Pollable.BlockWasmInterop.wasmImportBlock(handle); + + } + + } + + internal static unsafe uint[] Poll(global::System.Collections.Generic.List @in) + { + var cleanups = new global::System.Collections.Generic.List(); + + void* address; + if ((4 * @in.Count) < 1024) { + var retArea = stackalloc uint[1 * @in.Count + 1]; + address = MemoryHelper.AlignStackPtr(retArea, 4); + } + else + { + var bufferSize = 4 * (nuint)@in.Count; + address = global::System.Runtime.InteropServices.NativeMemory.AlignedAlloc(bufferSize, 4); + cleanups.Add(() => global::System.Runtime.InteropServices.NativeMemory.AlignedFree(address)); + } + + for (int index = 0; index < @in.Count; ++index) { + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable element = @in[index]; + int basePtr = (int)address + (index * 4); + var handle = element.Handle; + new global::System.Span((void*)((byte*)basePtr + 0), 1)[0] = handle; + + } + + var retArea0 = stackalloc uint[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea0, 4); + PollImportsInterop.PollWasmInterop.wasmImportPoll((int)address, @in.Count, ptr); + + var array = new uint[new global::System.Span((void*)((byte*)ptr + 4), 1)[0]]; + new global::System.Span((void*)(new global::System.Span((void*)((byte*)ptr + 0), 1)[0]), new global::System.Span((void*)((byte*)ptr + 4), 1)[0]).CopyTo(new global::System.Span(array)); + + if (new global::System.Span((void*)((byte*)ptr + 4), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 0), 1)[0]); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + return array; + + } + +} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.cs new file mode 100644 index 00000000000000..8f2ba045371dd2 --- /dev/null +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.cs @@ -0,0 +1,1107 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +namespace WasiHttpWorld.wit.Imports.wasi.io.v0_2_8; + +internal interface IStreamsImports { + + /** + * An error for input-stream and output-stream operations. + */ + + internal class StreamError { + internal readonly byte Tag; + private readonly object? value; + + private StreamError(byte tag, object? value) { + this.Tag = tag; + this.value = value; + } + + internal static StreamError LastOperationFailed(global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error lastOperationFailed) { + return new StreamError(Tags.LastOperationFailed, lastOperationFailed); + } + + internal static StreamError Closed() { + return new StreamError(Tags.Closed, null); + } + + internal global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error AsLastOperationFailed + { + get + { + if (Tag == Tags.LastOperationFailed) + return (global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error)value!; + else + throw new global::System.ArgumentException("expected LastOperationFailed, got " + Tag); + } + } + + internal class Tags { + internal const byte LastOperationFailed = 0; + internal const byte Closed = 1; + } + } + + /** + * An input bytestream. + * + * `input-stream`s are *non-blocking* to the extent practical on underlying + * platforms. I/O operations always return promptly; if fewer bytes are + * promptly available than requested, they return the number of bytes promptly + * available, which could even be zero. To wait for data to be available, + * use the `subscribe` function to obtain a `pollable` which can be polled + * for using `wasi:io/poll`. + */ + + internal class InputStream: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal InputStream(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[resource-drop]input-stream"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal unsafe byte[] Read(ulong len) + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + StreamsImportsInterop.InputStream.ReadWasmInterop.wasmImportRead(handle, unchecked((long)(len)), ptr); + + Result lifted6; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + var array = new byte[new global::System.Span((void*)((byte*)ptr + 8), 1)[0]]; + new global::System.Span((void*)(new global::System.Span((void*)((byte*)ptr + 4), 1)[0]), new global::System.Span((void*)((byte*)ptr + 8), 1)[0]).CopyTo(new global::System.Span(array)); + + if (new global::System.Span((void*)((byte*)ptr + 8), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 4), 1)[0]); + } + + lifted6 = Result.Ok(array); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 4, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 4, 1)[0]); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return tmp; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal unsafe byte[] BlockingRead(ulong len) + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + StreamsImportsInterop.InputStream.BlockingReadWasmInterop.wasmImportBlockingRead(handle, unchecked((long)(len)), ptr); + + Result lifted6; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + var array = new byte[new global::System.Span((void*)((byte*)ptr + 8), 1)[0]]; + new global::System.Span((void*)(new global::System.Span((void*)((byte*)ptr + 4), 1)[0]), new global::System.Span((void*)((byte*)ptr + 8), 1)[0]).CopyTo(new global::System.Span(array)); + + if (new global::System.Span((void*)((byte*)ptr + 8), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 4), 1)[0]); + } + + lifted6 = Result.Ok(array); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 4, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 4, 1)[0]); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return tmp; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal unsafe ulong Skip(ulong len) + { + var handle = this.Handle; + + var retArea = stackalloc ulong[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 8); + StreamsImportsInterop.InputStream.SkipWasmInterop.wasmImportSkip(handle, unchecked((long)(len)), ptr); + + Result lifted6; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted6 = Result.Ok(unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 8), 1)[0]))); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 8, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 12), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 8, 1)[0]); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return tmp; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal unsafe ulong BlockingSkip(ulong len) + { + var handle = this.Handle; + + var retArea = stackalloc ulong[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 8); + StreamsImportsInterop.InputStream.BlockingSkipWasmInterop.wasmImportBlockingSkip(handle, unchecked((long)(len)), ptr); + + Result lifted6; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted6 = Result.Ok(unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 8), 1)[0]))); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 8, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 12), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 8, 1)[0]); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return tmp; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable Subscribe() + { + var handle = this.Handle; + var result = StreamsImportsInterop.InputStream.SubscribeWasmInterop.wasmImportSubscribe(handle); + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable.THandle(result)); + return resource; + + } + + } + + /** + * An output bytestream. + * + * `output-stream`s are *non-blocking* to the extent practical on + * underlying platforms. Except where specified otherwise, I/O operations also + * always return promptly, after the number of bytes that can be written + * promptly, which could even be zero. To wait for the stream to be ready to + * accept data, the `subscribe` function to obtain a `pollable` which can be + * polled for using `wasi:io/poll`. + * + * Dropping an `output-stream` while there's still an active write in + * progress may result in the data being lost. Before dropping the stream, + * be sure to fully flush your writes. + */ + + internal class OutputStream: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal OutputStream(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[resource-drop]output-stream"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal unsafe ulong CheckWrite() + { + var handle = this.Handle; + + var retArea = stackalloc ulong[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 8); + StreamsImportsInterop.OutputStream.CheckWriteWasmInterop.wasmImportCheckWrite(handle, ptr); + + Result lifted6; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted6 = Result.Ok(unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 8), 1)[0]))); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 8, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 12), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 8, 1)[0]); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return tmp; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal unsafe void Write(byte[] contents) + { + var cleanups = new global::System.Collections.Generic.List(); + var handle = this.Handle; + + var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(contents, global::System.Runtime.InteropServices.GCHandleType.Pinned); + var listPtr = gcHandle.AddrOfPinnedObject(); + cleanups.Add(()=> gcHandle.Free()); + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + StreamsImportsInterop.OutputStream.WriteWasmInterop.wasmImportWrite(handle, (nint)listPtr, (contents).Length, ptr); + + Result lifted6; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 4, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 4, 1)[0]); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)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); + } + + } + + internal unsafe void Write(global::System.Span contents) + { + fixed (void* listPtr = contents) + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + StreamsImportsInterop.OutputStream.WriteWasmInterop.wasmImportWrite(handle, (nint)listPtr, (contents).Length, ptr); + + Result lifted6; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 4, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 4, 1)[0]); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + } + + } + + internal unsafe void Write(global::System.Memory contents) + { + fixed (void* listPtr = contents.Span) + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + StreamsImportsInterop.OutputStream.WriteWasmInterop.wasmImportWrite(handle, (nint)listPtr, (contents).Length, ptr); + + Result lifted6; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 4, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 4, 1)[0]); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + } + + } + + internal unsafe void BlockingWriteAndFlush(byte[] contents) + { + var cleanups = new global::System.Collections.Generic.List(); + var handle = this.Handle; + + var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(contents, global::System.Runtime.InteropServices.GCHandleType.Pinned); + var listPtr = gcHandle.AddrOfPinnedObject(); + cleanups.Add(()=> gcHandle.Free()); + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + StreamsImportsInterop.OutputStream.BlockingWriteAndFlushWasmInterop.wasmImportBlockingWriteAndFlush(handle, (nint)listPtr, (contents).Length, ptr); + + Result lifted6; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 4, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 4, 1)[0]); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)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); + } + + } + + internal unsafe void BlockingWriteAndFlush(global::System.Span contents) + { + fixed (void* listPtr = contents) + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + StreamsImportsInterop.OutputStream.BlockingWriteAndFlushWasmInterop.wasmImportBlockingWriteAndFlush(handle, (nint)listPtr, (contents).Length, ptr); + + Result lifted6; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 4, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 4, 1)[0]); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + } + + } + + internal unsafe void BlockingWriteAndFlush(global::System.Memory contents) + { + fixed (void* listPtr = contents.Span) + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + StreamsImportsInterop.OutputStream.BlockingWriteAndFlushWasmInterop.wasmImportBlockingWriteAndFlush(handle, (nint)listPtr, (contents).Length, ptr); + + Result lifted6; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 4, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 4, 1)[0]); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + } + + } + + internal unsafe void Flush() + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + StreamsImportsInterop.OutputStream.FlushWasmInterop.wasmImportFlush(handle, ptr); + + Result lifted6; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 4, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 4, 1)[0]); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal unsafe void BlockingFlush() + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + StreamsImportsInterop.OutputStream.BlockingFlushWasmInterop.wasmImportBlockingFlush(handle, ptr); + + Result lifted6; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 4, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 4, 1)[0]); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal unsafe global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable Subscribe() + { + var handle = this.Handle; + var result = StreamsImportsInterop.OutputStream.SubscribeWasmInterop.wasmImportSubscribe(handle); + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable.THandle(result)); + return resource; + + } + + internal unsafe void WriteZeroes(ulong len) + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + StreamsImportsInterop.OutputStream.WriteZeroesWasmInterop.wasmImportWriteZeroes(handle, unchecked((long)(len)), ptr); + + Result lifted6; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 4, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 4, 1)[0]); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal unsafe void BlockingWriteZeroesAndFlush(ulong len) + { + var handle = this.Handle; + + var retArea = stackalloc uint[4]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4); + StreamsImportsInterop.OutputStream.BlockingWriteZeroesAndFlushWasmInterop.wasmImportBlockingWriteZeroesAndFlush(handle, unchecked((long)(len)), ptr); + + Result lifted6; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted6 = Result.Ok(new global::WasiHttpWorld.None()); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 4, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 8), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 4, 1)[0]); + } + + lifted6 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted6.IsOk) + { + var tmp = lifted6.AsOk; + return ; + } + else + { + throw new WitException(lifted6.AsErr!, 0); + } + + } + + internal unsafe ulong Splice(global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.InputStream src, ulong len) + { + var handle = this.Handle; + var handle0 = src.Handle; + + var retArea = stackalloc ulong[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 8); + StreamsImportsInterop.OutputStream.SpliceWasmInterop.wasmImportSplice(handle, handle0, unchecked((long)(len)), ptr); + + Result lifted7; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted7 = Result.Ok(unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 8), 1)[0]))); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 8, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 12), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 8, 1)[0]); + } + + lifted7 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted7.IsOk) + { + var tmp = lifted7.AsOk; + return tmp; + } + else + { + throw new WitException(lifted7.AsErr!, 0); + } + + } + + internal unsafe ulong BlockingSplice(global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.InputStream src, ulong len) + { + var handle = this.Handle; + var handle0 = src.Handle; + + var retArea = stackalloc ulong[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 8); + StreamsImportsInterop.OutputStream.BlockingSpliceWasmInterop.wasmImportBlockingSplice(handle, handle0, unchecked((long)(len)), ptr); + + Result lifted7; + + switch (new global::System.Span((byte*)ptr + 0, 1)[0]) { + case 0: { + + lifted7 = Result.Ok(unchecked((ulong)(new global::System.Span((void*)((byte*)ptr + 8), 1)[0]))); + break; + } + case 1: { + + global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError lifted; + + switch (new global::System.Span((byte*)ptr + 8, 1)[0]) { + case 0: { + var resource = new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error(new global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IErrorImports.Error.THandle(new global::System.Span((void*)((byte*)ptr + 12), 1)[0])); + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.LastOperationFailed(resource); + break; + } + case 1: { + + lifted = global::WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports.StreamError.Closed(); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 8, 1)[0]); + } + + lifted7 = Result.Err(lifted); + break; + } + + default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span((byte*)ptr + 0, 1)[0]); + } + if (lifted7.IsOk) + { + var tmp = lifted7.AsOk; + return tmp; + } + else + { + throw new WitException(lifted7.AsErr!, 0); + } + + } + + } + +} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.PollImportsInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.PollImportsInterop.cs new file mode 100644 index 00000000000000..05705a72e49ea2 --- /dev/null +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.PollImportsInterop.cs @@ -0,0 +1,35 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +using System; + +namespace WasiHttpWorld.wit.Imports.wasi.io.v0_2_8 +{ + internal static class PollImportsInterop { + + internal static class Pollable + { + + public static class ReadyWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/poll@0.2.8", EntryPoint = "[method]pollable.ready"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportReady(int p0); + } + + public static class BlockWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/poll@0.2.8", EntryPoint = "[method]pollable.block"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportBlock(int p0); + } + + } + + public static class PollWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/poll@0.2.8", EntryPoint = "poll"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportPoll(nint p0, int p1, nint p2); + } + + } +} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.StreamsImportsInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.StreamsImportsInterop.cs new file mode 100644 index 00000000000000..946b0ccd178114 --- /dev/null +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.StreamsImportsInterop.cs @@ -0,0 +1,112 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +using System; + +namespace WasiHttpWorld.wit.Imports.wasi.io.v0_2_8 +{ + internal static class StreamsImportsInterop { + + internal static class InputStream + { + + public static class ReadWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[method]input-stream.read"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportRead(int p0, long p1, nint p2); + } + + public static class BlockingReadWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[method]input-stream.blocking-read"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportBlockingRead(int p0, long p1, nint p2); + } + + public static class SkipWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[method]input-stream.skip"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportSkip(int p0, long p1, nint p2); + } + + public static class BlockingSkipWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[method]input-stream.blocking-skip"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportBlockingSkip(int p0, long p1, nint p2); + } + + public static class SubscribeWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[method]input-stream.subscribe"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSubscribe(int p0); + } + + } + + internal static class OutputStream + { + + public static class CheckWriteWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[method]output-stream.check-write"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportCheckWrite(int p0, nint p1); + } + + public static class WriteWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[method]output-stream.write"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportWrite(int p0, nint p1, int p2, nint p3); + } + + public static class BlockingWriteAndFlushWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[method]output-stream.blocking-write-and-flush"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportBlockingWriteAndFlush(int p0, nint p1, int p2, nint p3); + } + + public static class FlushWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[method]output-stream.flush"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportFlush(int p0, nint p1); + } + + public static class BlockingFlushWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[method]output-stream.blocking-flush"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportBlockingFlush(int p0, nint p1); + } + + public static class SubscribeWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[method]output-stream.subscribe"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSubscribe(int p0); + } + + public static class WriteZeroesWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[method]output-stream.write-zeroes"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportWriteZeroes(int p0, long p1, nint p2); + } + + public static class BlockingWriteZeroesAndFlushWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[method]output-stream.blocking-write-zeroes-and-flush"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportBlockingWriteZeroesAndFlush(int p0, long p1, nint p2); + } + + public static class SpliceWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[method]output-stream.splice"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportSplice(int p0, int p1, long p2, nint p3); + } + + public static class BlockingSpliceWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/streams@0.2.8", EntryPoint = "[method]output-stream.blocking-splice"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportBlockingSplice(int p0, int p1, long p2, nint p3); + } + + } + + } +} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop.cs deleted file mode 100644 index 6357b932c8752d..00000000000000 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop.cs +++ /dev/null @@ -1,81 +0,0 @@ -// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT! -// -#nullable enable - -using System; -using System.Runtime.CompilerServices; -using System.Collections; -using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace WasiHttpWorld.wit.imports.wasi.clocks.v0_2_0 -{ - internal static class MonotonicClockInterop { - - internal static class NowWasmInterop - { - [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "now"), WasmImportLinkage] - internal static extern long wasmImportNow(); - - } - - internal static unsafe ulong Now() - { - var result = NowWasmInterop.wasmImportNow(); - return unchecked((ulong)(result)); - - //TODO: free alloc handle (interopString) if exists - } - - internal static class ResolutionWasmInterop - { - [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "resolution"), WasmImportLinkage] - internal static extern long wasmImportResolution(); - - } - - internal static unsafe ulong Resolution() - { - var result = ResolutionWasmInterop.wasmImportResolution(); - return unchecked((ulong)(result)); - - //TODO: free alloc handle (interopString) if exists - } - - internal static class SubscribeInstantWasmInterop - { - [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "subscribe-instant"), WasmImportLinkage] - internal static extern int wasmImportSubscribeInstant(long p0); - - } - - internal static unsafe global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable SubscribeInstant(ulong when) - { - var result = SubscribeInstantWasmInterop.wasmImportSubscribeInstant(unchecked((long)(when))); - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result)); - return resource; - - //TODO: free alloc handle (interopString) if exists - } - - internal static class SubscribeDurationWasmInterop - { - [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "subscribe-duration"), WasmImportLinkage] - internal static extern int wasmImportSubscribeDuration(long p0); - - } - - internal static unsafe global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable SubscribeDuration(ulong when) - { - var result = SubscribeDurationWasmInterop.wasmImportSubscribeDuration(unchecked((long)(when))); - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result)); - return resource; - - //TODO: free alloc handle (interopString) if exists - } - - } -} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.cs deleted file mode 100644 index ffc6bab2b2fc78..00000000000000 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.cs +++ /dev/null @@ -1,5903 +0,0 @@ -// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT! -// -#nullable enable - -using System; -using System.Runtime.CompilerServices; -using System.Collections; -using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace WasiHttpWorld.wit.imports.wasi.http.v0_2_0; - -internal interface ITypes { - - /** - * This type corresponds to HTTP standard Methods. - */ - - internal class Method { - internal readonly byte Tag; - private readonly object? value; - - private Method(byte tag, object? value) { - this.Tag = tag; - this.value = value; - } - - internal static Method get() { - return new Method(GET, null); - } - - internal static Method head() { - return new Method(HEAD, null); - } - - internal static Method post() { - return new Method(POST, null); - } - - internal static Method put() { - return new Method(PUT, null); - } - - internal static Method delete() { - return new Method(DELETE, null); - } - - internal static Method connect() { - return new Method(CONNECT, null); - } - - internal static Method options() { - return new Method(OPTIONS, null); - } - - internal static Method trace() { - return new Method(TRACE, null); - } - - internal static Method patch() { - return new Method(PATCH, null); - } - - internal static Method other(string other) { - return new Method(OTHER, other); - } - - internal string AsOther - { - get - { - if (Tag == OTHER) - return (string)value!; - else - throw new ArgumentException("expected OTHER, got " + Tag); - } - } - - internal const byte GET = 0; - internal const byte HEAD = 1; - internal const byte POST = 2; - internal const byte PUT = 3; - internal const byte DELETE = 4; - internal const byte CONNECT = 5; - internal const byte OPTIONS = 6; - internal const byte TRACE = 7; - internal const byte PATCH = 8; - internal const byte OTHER = 9; - } - - /** - * This type corresponds to HTTP standard Related Schemes. - */ - - internal class Scheme { - internal readonly byte Tag; - private readonly object? value; - - private Scheme(byte tag, object? value) { - this.Tag = tag; - this.value = value; - } - - internal static Scheme http() { - return new Scheme(HTTP, null); - } - - internal static Scheme https() { - return new Scheme(HTTPS, null); - } - - internal static Scheme other(string other) { - return new Scheme(OTHER, other); - } - - internal string AsOther - { - get - { - if (Tag == OTHER) - return (string)value!; - else - throw new ArgumentException("expected OTHER, got " + Tag); - } - } - - internal const byte HTTP = 0; - internal const byte HTTPS = 1; - internal const byte OTHER = 2; - } - - /** - * Defines the case payload type for `DNS-error` above: - */ - - internal class DnsErrorPayload { - internal readonly string? rcode; - internal readonly ushort? infoCode; - - internal DnsErrorPayload(string? rcode, ushort? infoCode) { - this.rcode = rcode; - this.infoCode = infoCode; - } - } - - /** - * Defines the case payload type for `TLS-alert-received` above: - */ - - internal class TlsAlertReceivedPayload { - internal readonly byte? alertId; - internal readonly string? alertMessage; - - internal TlsAlertReceivedPayload(byte? alertId, string? alertMessage) { - this.alertId = alertId; - this.alertMessage = alertMessage; - } - } - - /** - * Defines the case payload type for `HTTP-response-{header,trailer}-size` above: - */ - - internal class FieldSizePayload { - internal readonly string? fieldName; - internal readonly uint? fieldSize; - - internal 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 - */ - - internal class ErrorCode { - internal readonly byte Tag; - private readonly object? value; - - private ErrorCode(byte tag, object? value) { - this.Tag = tag; - this.value = value; - } - - internal static ErrorCode dnsTimeout() { - return new ErrorCode(DNS_TIMEOUT, null); - } - - internal static ErrorCode dnsError(DnsErrorPayload dnsError) { - return new ErrorCode(DNS_ERROR, dnsError); - } - - internal static ErrorCode destinationNotFound() { - return new ErrorCode(DESTINATION_NOT_FOUND, null); - } - - internal static ErrorCode destinationUnavailable() { - return new ErrorCode(DESTINATION_UNAVAILABLE, null); - } - - internal static ErrorCode destinationIpProhibited() { - return new ErrorCode(DESTINATION_IP_PROHIBITED, null); - } - - internal static ErrorCode destinationIpUnroutable() { - return new ErrorCode(DESTINATION_IP_UNROUTABLE, null); - } - - internal static ErrorCode connectionRefused() { - return new ErrorCode(CONNECTION_REFUSED, null); - } - - internal static ErrorCode connectionTerminated() { - return new ErrorCode(CONNECTION_TERMINATED, null); - } - - internal static ErrorCode connectionTimeout() { - return new ErrorCode(CONNECTION_TIMEOUT, null); - } - - internal static ErrorCode connectionReadTimeout() { - return new ErrorCode(CONNECTION_READ_TIMEOUT, null); - } - - internal static ErrorCode connectionWriteTimeout() { - return new ErrorCode(CONNECTION_WRITE_TIMEOUT, null); - } - - internal static ErrorCode connectionLimitReached() { - return new ErrorCode(CONNECTION_LIMIT_REACHED, null); - } - - internal static ErrorCode tlsProtocolError() { - return new ErrorCode(TLS_PROTOCOL_ERROR, null); - } - - internal static ErrorCode tlsCertificateError() { - return new ErrorCode(TLS_CERTIFICATE_ERROR, null); - } - - internal static ErrorCode tlsAlertReceived(TlsAlertReceivedPayload tlsAlertReceived) { - return new ErrorCode(TLS_ALERT_RECEIVED, tlsAlertReceived); - } - - internal static ErrorCode httpRequestDenied() { - return new ErrorCode(HTTP_REQUEST_DENIED, null); - } - - internal static ErrorCode httpRequestLengthRequired() { - return new ErrorCode(HTTP_REQUEST_LENGTH_REQUIRED, null); - } - - internal static ErrorCode httpRequestBodySize(ulong? httpRequestBodySize) { - return new ErrorCode(HTTP_REQUEST_BODY_SIZE, httpRequestBodySize); - } - - internal static ErrorCode httpRequestMethodInvalid() { - return new ErrorCode(HTTP_REQUEST_METHOD_INVALID, null); - } - - internal static ErrorCode httpRequestUriInvalid() { - return new ErrorCode(HTTP_REQUEST_URI_INVALID, null); - } - - internal static ErrorCode httpRequestUriTooLong() { - return new ErrorCode(HTTP_REQUEST_URI_TOO_LONG, null); - } - - internal static ErrorCode httpRequestHeaderSectionSize(uint? httpRequestHeaderSectionSize) { - return new ErrorCode(HTTP_REQUEST_HEADER_SECTION_SIZE, httpRequestHeaderSectionSize); - } - - internal static ErrorCode httpRequestHeaderSize(FieldSizePayload? httpRequestHeaderSize) { - return new ErrorCode(HTTP_REQUEST_HEADER_SIZE, httpRequestHeaderSize); - } - - internal static ErrorCode httpRequestTrailerSectionSize(uint? httpRequestTrailerSectionSize) { - return new ErrorCode(HTTP_REQUEST_TRAILER_SECTION_SIZE, httpRequestTrailerSectionSize); - } - - internal static ErrorCode httpRequestTrailerSize(FieldSizePayload httpRequestTrailerSize) { - return new ErrorCode(HTTP_REQUEST_TRAILER_SIZE, httpRequestTrailerSize); - } - - internal static ErrorCode httpResponseIncomplete() { - return new ErrorCode(HTTP_RESPONSE_INCOMPLETE, null); - } - - internal static ErrorCode httpResponseHeaderSectionSize(uint? httpResponseHeaderSectionSize) { - return new ErrorCode(HTTP_RESPONSE_HEADER_SECTION_SIZE, httpResponseHeaderSectionSize); - } - - internal static ErrorCode httpResponseHeaderSize(FieldSizePayload httpResponseHeaderSize) { - return new ErrorCode(HTTP_RESPONSE_HEADER_SIZE, httpResponseHeaderSize); - } - - internal static ErrorCode httpResponseBodySize(ulong? httpResponseBodySize) { - return new ErrorCode(HTTP_RESPONSE_BODY_SIZE, httpResponseBodySize); - } - - internal static ErrorCode httpResponseTrailerSectionSize(uint? httpResponseTrailerSectionSize) { - return new ErrorCode(HTTP_RESPONSE_TRAILER_SECTION_SIZE, httpResponseTrailerSectionSize); - } - - internal static ErrorCode httpResponseTrailerSize(FieldSizePayload httpResponseTrailerSize) { - return new ErrorCode(HTTP_RESPONSE_TRAILER_SIZE, httpResponseTrailerSize); - } - - internal static ErrorCode httpResponseTransferCoding(string? httpResponseTransferCoding) { - return new ErrorCode(HTTP_RESPONSE_TRANSFER_CODING, httpResponseTransferCoding); - } - - internal static ErrorCode httpResponseContentCoding(string? httpResponseContentCoding) { - return new ErrorCode(HTTP_RESPONSE_CONTENT_CODING, httpResponseContentCoding); - } - - internal static ErrorCode httpResponseTimeout() { - return new ErrorCode(HTTP_RESPONSE_TIMEOUT, null); - } - - internal static ErrorCode httpUpgradeFailed() { - return new ErrorCode(HTTP_UPGRADE_FAILED, null); - } - - internal static ErrorCode httpProtocolError() { - return new ErrorCode(HTTP_PROTOCOL_ERROR, null); - } - - internal static ErrorCode loopDetected() { - return new ErrorCode(LOOP_DETECTED, null); - } - - internal static ErrorCode configurationError() { - return new ErrorCode(CONFIGURATION_ERROR, null); - } - - internal static ErrorCode internalError(string? internalError) { - return new ErrorCode(INTERNAL_ERROR, internalError); - } - - internal DnsErrorPayload AsDnsError - { - get - { - if (Tag == DNS_ERROR) - return (DnsErrorPayload)value!; - else - throw new ArgumentException("expected DNS_ERROR, got " + Tag); - } - } - - internal TlsAlertReceivedPayload AsTlsAlertReceived - { - get - { - if (Tag == TLS_ALERT_RECEIVED) - return (TlsAlertReceivedPayload)value!; - else - throw new ArgumentException("expected TLS_ALERT_RECEIVED, got " + Tag); - } - } - - internal ulong? AsHttpRequestBodySize - { - get - { - if (Tag == HTTP_REQUEST_BODY_SIZE) - return (ulong?)value!; - else - throw new ArgumentException("expected HTTP_REQUEST_BODY_SIZE, got " + Tag); - } - } - - internal uint? AsHttpRequestHeaderSectionSize - { - get - { - if (Tag == HTTP_REQUEST_HEADER_SECTION_SIZE) - return (uint?)value!; - else - throw new ArgumentException("expected HTTP_REQUEST_HEADER_SECTION_SIZE, got " + Tag); - } - } - - internal FieldSizePayload? AsHttpRequestHeaderSize - { - get - { - if (Tag == HTTP_REQUEST_HEADER_SIZE) - return (FieldSizePayload?)value!; - else - throw new ArgumentException("expected HTTP_REQUEST_HEADER_SIZE, got " + Tag); - } - } - - internal uint? AsHttpRequestTrailerSectionSize - { - get - { - if (Tag == HTTP_REQUEST_TRAILER_SECTION_SIZE) - return (uint?)value!; - else - throw new ArgumentException("expected HTTP_REQUEST_TRAILER_SECTION_SIZE, got " + Tag); - } - } - - internal FieldSizePayload AsHttpRequestTrailerSize - { - get - { - if (Tag == HTTP_REQUEST_TRAILER_SIZE) - return (FieldSizePayload)value!; - else - throw new ArgumentException("expected HTTP_REQUEST_TRAILER_SIZE, got " + Tag); - } - } - - internal uint? AsHttpResponseHeaderSectionSize - { - get - { - if (Tag == HTTP_RESPONSE_HEADER_SECTION_SIZE) - return (uint?)value!; - else - throw new ArgumentException("expected HTTP_RESPONSE_HEADER_SECTION_SIZE, got " + Tag); - } - } - - internal FieldSizePayload AsHttpResponseHeaderSize - { - get - { - if (Tag == HTTP_RESPONSE_HEADER_SIZE) - return (FieldSizePayload)value!; - else - throw new ArgumentException("expected HTTP_RESPONSE_HEADER_SIZE, got " + Tag); - } - } - - internal ulong? AsHttpResponseBodySize - { - get - { - if (Tag == HTTP_RESPONSE_BODY_SIZE) - return (ulong?)value!; - else - throw new ArgumentException("expected HTTP_RESPONSE_BODY_SIZE, got " + Tag); - } - } - - internal uint? AsHttpResponseTrailerSectionSize - { - get - { - if (Tag == HTTP_RESPONSE_TRAILER_SECTION_SIZE) - return (uint?)value!; - else - throw new ArgumentException("expected HTTP_RESPONSE_TRAILER_SECTION_SIZE, got " + Tag); - } - } - - internal FieldSizePayload AsHttpResponseTrailerSize - { - get - { - if (Tag == HTTP_RESPONSE_TRAILER_SIZE) - return (FieldSizePayload)value!; - else - throw new ArgumentException("expected HTTP_RESPONSE_TRAILER_SIZE, got " + Tag); - } - } - - internal string? AsHttpResponseTransferCoding - { - get - { - if (Tag == HTTP_RESPONSE_TRANSFER_CODING) - return (string?)value!; - else - throw new ArgumentException("expected HTTP_RESPONSE_TRANSFER_CODING, got " + Tag); - } - } - - internal string? AsHttpResponseContentCoding - { - get - { - if (Tag == HTTP_RESPONSE_CONTENT_CODING) - return (string?)value!; - else - throw new ArgumentException("expected HTTP_RESPONSE_CONTENT_CODING, got " + Tag); - } - } - - internal string? AsInternalError - { - get - { - if (Tag == INTERNAL_ERROR) - return (string?)value!; - else - throw new ArgumentException("expected INTERNAL_ERROR, got " + Tag); - } - } - - internal const byte DNS_TIMEOUT = 0; - internal const byte DNS_ERROR = 1; - internal const byte DESTINATION_NOT_FOUND = 2; - internal const byte DESTINATION_UNAVAILABLE = 3; - internal const byte DESTINATION_IP_PROHIBITED = 4; - internal const byte DESTINATION_IP_UNROUTABLE = 5; - internal const byte CONNECTION_REFUSED = 6; - internal const byte CONNECTION_TERMINATED = 7; - internal const byte CONNECTION_TIMEOUT = 8; - internal const byte CONNECTION_READ_TIMEOUT = 9; - internal const byte CONNECTION_WRITE_TIMEOUT = 10; - internal const byte CONNECTION_LIMIT_REACHED = 11; - internal const byte TLS_PROTOCOL_ERROR = 12; - internal const byte TLS_CERTIFICATE_ERROR = 13; - internal const byte TLS_ALERT_RECEIVED = 14; - internal const byte HTTP_REQUEST_DENIED = 15; - internal const byte HTTP_REQUEST_LENGTH_REQUIRED = 16; - internal const byte HTTP_REQUEST_BODY_SIZE = 17; - internal const byte HTTP_REQUEST_METHOD_INVALID = 18; - internal const byte HTTP_REQUEST_URI_INVALID = 19; - internal const byte HTTP_REQUEST_URI_TOO_LONG = 20; - internal const byte HTTP_REQUEST_HEADER_SECTION_SIZE = 21; - internal const byte HTTP_REQUEST_HEADER_SIZE = 22; - internal const byte HTTP_REQUEST_TRAILER_SECTION_SIZE = 23; - internal const byte HTTP_REQUEST_TRAILER_SIZE = 24; - internal const byte HTTP_RESPONSE_INCOMPLETE = 25; - internal const byte HTTP_RESPONSE_HEADER_SECTION_SIZE = 26; - internal const byte HTTP_RESPONSE_HEADER_SIZE = 27; - internal const byte HTTP_RESPONSE_BODY_SIZE = 28; - internal const byte HTTP_RESPONSE_TRAILER_SECTION_SIZE = 29; - internal const byte HTTP_RESPONSE_TRAILER_SIZE = 30; - internal const byte HTTP_RESPONSE_TRANSFER_CODING = 31; - internal const byte HTTP_RESPONSE_CONTENT_CODING = 32; - internal const byte HTTP_RESPONSE_TIMEOUT = 33; - internal const byte HTTP_UPGRADE_FAILED = 34; - internal const byte HTTP_PROTOCOL_ERROR = 35; - internal const byte LOOP_DETECTED = 36; - internal const byte CONFIGURATION_ERROR = 37; - internal const byte INTERNAL_ERROR = 38; - } - - /** - * This type enumerates the different kinds of errors that may occur when - * setting or appending to a `fields` resource. - */ - - internal class HeaderError { - internal readonly byte Tag; - private readonly object? value; - - private HeaderError(byte tag, object? value) { - this.Tag = tag; - this.value = value; - } - - internal static HeaderError invalidSyntax() { - return new HeaderError(INVALID_SYNTAX, null); - } - - internal static HeaderError forbidden() { - return new HeaderError(FORBIDDEN, null); - } - - internal static HeaderError immutable() { - return new HeaderError(IMMUTABLE, null); - } - - internal const byte INVALID_SYNTAX = 0; - internal const byte FORBIDDEN = 1; - internal 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`. - */ - - internal class Fields: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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(); - - } - - internal unsafe Fields() - { - var result = ConstructorWasmInterop.wasmImportConstructor(); - this.Handle = result; - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal static unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields FromList(List<(string, byte[])> entries) - { - - byte[] buffer0 = new byte[16 * entries.Count]; - var gcHandle = GCHandle.Alloc(buffer0, GCHandleType.Pinned); - var address = gcHandle.AddrOfPinnedObject(); - - for (int index = 0; index < entries.Count; ++index) { - (string, byte[]) element = entries[index]; - int basePtr = (int)address + (index * 16); - - var result = element.Item1; - IntPtr interopString = InteropString.FromString(result, out int lengthresult); - BitConverter.TryWriteBytes(new Span((void*)(basePtr + 4), 4), unchecked((int)lengthresult)); - BitConverter.TryWriteBytes(new Span((void*)(basePtr + 0), 4), unchecked((int)interopString.ToInt32())); - - void* buffer = stackalloc byte[(element.Item2).Length]; - element.Item2.AsSpan().CopyTo(new Span(buffer, element.Item2.Length)); - BitConverter.TryWriteBytes(new Span((void*)(basePtr + 12), 4), unchecked((int)(element.Item2).Length)); - BitConverter.TryWriteBytes(new Span((void*)(basePtr + 8), 4), unchecked((int)(int)buffer)); - - } - - var retArea = new uint[2]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - FromListWasmInterop.wasmImportFromList((int)address, entries.Count, ptr); - - Result lifted11; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)))); - - lifted11 = Result.ok(resource); - break; - } - case 1: { - - global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError lifted; - - switch (new Span((void*)(ptr + 4), 1)[0]) { - case 0: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.invalidSyntax(); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.forbidden(); - break; - } - case 2: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.immutable(); - break; - } - - default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}"); - } - - lifted11 = Result.err(lifted); - break; - } - - default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); - } - gcHandle.Free(); - if (lifted11.IsOk) { - var tmp = lifted11.AsOk; - return tmp; - } else { - throw new WitException(lifted11.AsErr!, 0); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe List Get(string name) - { - var handle = this.Handle; - - var result = name; - IntPtr interopString = InteropString.FromString(result, out int lengthresult); - - var retArea = new uint[2]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - GetWasmInterop.wasmImportGet(handle, interopString.ToInt32(), lengthresult, 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); - } - return array0; - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe bool Has(string name) - { - var handle = this.Handle; - - var result = name; - IntPtr interopString = InteropString.FromString(result, out int lengthresult); - var result0 = HasWasmInterop.wasmImportHas(handle, interopString.ToInt32(), lengthresult); - return (result0 != 0); - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe void Set(string name, List value) - { - var handle = this.Handle; - - var result = name; - IntPtr interopString = InteropString.FromString(result, out int lengthresult); - - byte[] buffer0 = new byte[8 * value.Count]; - var gcHandle = GCHandle.Alloc(buffer0, GCHandleType.Pinned); - var address = gcHandle.AddrOfPinnedObject(); - - for (int index = 0; index < value.Count; ++index) { - byte[] element = value[index]; - int basePtr = (int)address + (index * 8); - - void* buffer = stackalloc byte[(element).Length]; - element.AsSpan().CopyTo(new Span(buffer, element.Length)); - BitConverter.TryWriteBytes(new Span((void*)(basePtr + 4), 4), unchecked((int)(element).Length)); - BitConverter.TryWriteBytes(new Span((void*)(basePtr + 0), 4), unchecked((int)(int)buffer)); - - } - - var retArea = new byte[2]; - fixed (byte* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - SetWasmInterop.wasmImportSet(handle, interopString.ToInt32(), lengthresult, (int)address, value.Count, ptr); - - Result lifted11; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - - lifted11 = Result.ok(new global::WasiHttpWorld.None()); - break; - } - case 1: { - - global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError lifted; - - switch (new Span((void*)(ptr + 1), 1)[0]) { - case 0: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.invalidSyntax(); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.forbidden(); - break; - } - case 2: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.immutable(); - break; - } - - default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 1), 1)[0]}"); - } - - lifted11 = Result.err(lifted); - break; - } - - default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}"); - } - gcHandle.Free(); - if (lifted11.IsOk) { - var tmp = lifted11.AsOk; - return ; - } else { - throw new WitException(lifted11.AsErr!, 0); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe void Delete(string name) - { - var handle = this.Handle; - - var result = name; - IntPtr interopString = InteropString.FromString(result, out int lengthresult); - - var retArea = new byte[2]; - fixed (byte* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - DeleteWasmInterop.wasmImportDelete(handle, interopString.ToInt32(), lengthresult, ptr); - - Result lifted8; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - - lifted8 = Result.ok(new global::WasiHttpWorld.None()); - break; - } - case 1: { - - global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError lifted; - - switch (new Span((void*)(ptr + 1), 1)[0]) { - case 0: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.invalidSyntax(); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.forbidden(); - break; - } - case 2: { - - lifted = global::WasiHttpWorld.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]}"); - } - if (lifted8.IsOk) { - var tmp = lifted8.AsOk; - return ; - } else { - throw new WitException(lifted8.AsErr!, 0); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe void Append(string name, byte[] value) - { - var handle = this.Handle; - - var result = name; - IntPtr interopString = InteropString.FromString(result, out int lengthresult); - - void* buffer = stackalloc byte[(value).Length]; - value.AsSpan().CopyTo(new Span(buffer, value.Length)); - - var retArea = new byte[2]; - fixed (byte* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - AppendWasmInterop.wasmImportAppend(handle, interopString.ToInt32(), lengthresult, (int)buffer, (value).Length, ptr); - - Result lifted8; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - - lifted8 = Result.ok(new global::WasiHttpWorld.None()); - break; - } - case 1: { - - global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError lifted; - - switch (new Span((void*)(ptr + 1), 1)[0]) { - case 0: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.invalidSyntax(); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.forbidden(); - break; - } - case 2: { - - lifted = global::WasiHttpWorld.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]}"); - } - if (lifted8.IsOk) { - var tmp = lifted8.AsOk; - return ; - } else { - throw new WitException(lifted8.AsErr!, 0); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe List<(string, byte[])> Entries() - { - var handle = this.Handle; - - var retArea = new uint[2]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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; - } - - //TODO: free alloc handle (interopString) if exists - } - - internal static class CloneWasmInterop - { - [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]fields.clone"), WasmImportLinkage] - internal static extern int wasmImportClone(int p0); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields Clone() - { - var handle = this.Handle; - var result = CloneWasmInterop.wasmImportClone(handle); - var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(result)); - return resource; - - //TODO: free alloc handle (interopString) if exists - } - - } - - /** - * Represents an incoming HTTP Request. - */ - - internal class IncomingRequest: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method Method() - { - var handle = this.Handle; - - var retArea = new uint[3]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - MethodWasmInterop.wasmImportMethod(handle, ptr); - - global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method lifted; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.get(); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.head(); - break; - } - case 2: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.post(); - break; - } - case 3: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.put(); - break; - } - case 4: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.delete(); - break; - } - case 5: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.connect(); - break; - } - case 6: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.options(); - break; - } - case 7: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.trace(); - break; - } - case 8: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.patch(); - break; - } - case 9: { - - lifted = global::WasiHttpWorld.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; - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe string? PathWithQuery() - { - var handle = this.Handle; - - var retArea = new uint[3]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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; - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme? Scheme() - { - var handle = this.Handle; - - var retArea = new uint[4]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - SchemeWasmInterop.wasmImportScheme(handle, ptr); - - global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme lifted; - - switch (new Span((void*)(ptr + 4), 1)[0]) { - case 0: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.http(); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.https(); - break; - } - case 2: { - - lifted = global::WasiHttpWorld.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; - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe string? Authority() - { - var handle = this.Handle; - - var retArea = new uint[3]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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; - } - - //TODO: free alloc handle (interopString) if exists - } - - internal static class HeadersWasmInterop - { - [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-request.headers"), WasmImportLinkage] - internal static extern int wasmImportHeaders(int p0); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields Headers() - { - var handle = this.Handle; - var result = HeadersWasmInterop.wasmImportHeaders(handle); - var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(result)); - return resource; - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody Consume() - { - var handle = this.Handle; - - var retArea = new uint[2]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - ConsumeWasmInterop.wasmImportConsume(handle, ptr); - - Result lifted; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody(new global::WasiHttpWorld.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::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - } - - /** - * Represents an outgoing HTTP Request. - */ - - internal class OutgoingRequest: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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); - - } - - internal unsafe OutgoingRequest(global::WasiHttpWorld.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; - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingBody Body() - { - var handle = this.Handle; - - var retArea = new uint[2]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - BodyWasmInterop.wasmImportBody(handle, ptr); - - Result lifted; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingBody(new global::WasiHttpWorld.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::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method Method() - { - var handle = this.Handle; - - var retArea = new uint[3]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - MethodWasmInterop.wasmImportMethod(handle, ptr); - - global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method lifted; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.get(); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.head(); - break; - } - case 2: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.post(); - break; - } - case 3: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.put(); - break; - } - case 4: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.delete(); - break; - } - case 5: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.connect(); - break; - } - case 6: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.options(); - break; - } - case 7: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.trace(); - break; - } - case 8: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.patch(); - break; - } - case 9: { - - lifted = global::WasiHttpWorld.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; - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe void SetMethod(global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method method) - { - 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 result = payload26; - IntPtr interopString = InteropString.FromString(result, out int lengthresult); - - lowered = 9; - lowered27 = interopString.ToInt32(); - lowered28 = lengthresult; - - break; - } - - default: throw new ArgumentException($"invalid discriminant: {method}"); - } - var result29 = SetMethodWasmInterop.wasmImportSetMethod(handle, lowered, lowered27, lowered28); - - Result lifted; - - switch (result29) { - case 0: { - - lifted = Result.ok(new global::WasiHttpWorld.None()); - break; - } - case 1: { - - lifted = Result.err(new global::WasiHttpWorld.None()); - break; - } - - default: throw new ArgumentException($"invalid discriminant: {result29}"); - } - if (lifted.IsOk) { - var tmp = lifted.AsOk; - return ; - } else { - throw new WitException(lifted.AsErr!, 0); - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe string? PathWithQuery() - { - var handle = this.Handle; - - var retArea = new uint[3]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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; - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe void SetPathWithQuery(string? pathWithQuery) - { - var handle = this.Handle; - - int lowered; - nint lowered3; - int lowered4; - - if (pathWithQuery != null) { - var payload2 = (string) pathWithQuery; - - var result = payload2; - IntPtr interopString = InteropString.FromString(result, out int lengthresult); - - lowered = 1; - lowered3 = interopString.ToInt32(); - lowered4 = lengthresult; - - } else { - - lowered = 0; - lowered3 = 0; - lowered4 = 0; - - } - var result5 = SetPathWithQueryWasmInterop.wasmImportSetPathWithQuery(handle, lowered, lowered3, lowered4); - - Result lifted; - - switch (result5) { - case 0: { - - lifted = Result.ok(new global::WasiHttpWorld.None()); - break; - } - case 1: { - - lifted = Result.err(new global::WasiHttpWorld.None()); - break; - } - - default: throw new ArgumentException($"invalid discriminant: {result5}"); - } - if (lifted.IsOk) { - var tmp = lifted.AsOk; - return ; - } else { - throw new WitException(lifted.AsErr!, 0); - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme? Scheme() - { - var handle = this.Handle; - - var retArea = new uint[4]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - SchemeWasmInterop.wasmImportScheme(handle, ptr); - - global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme lifted; - - switch (new Span((void*)(ptr + 4), 1)[0]) { - case 0: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.http(); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.https(); - break; - } - case 2: { - - lifted = global::WasiHttpWorld.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; - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe void SetScheme(global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme? scheme) - { - var handle = this.Handle; - - int lowered14; - int lowered15; - nint lowered16; - int lowered17; - - if (scheme != null) { - var payload2 = (global::WasiHttpWorld.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 result = payload11; - IntPtr interopString = InteropString.FromString(result, out int lengthresult); - - lowered = 2; - lowered12 = interopString.ToInt32(); - lowered13 = lengthresult; - - 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 result18 = SetSchemeWasmInterop.wasmImportSetScheme(handle, lowered14, lowered15, lowered16, lowered17); - - Result lifted; - - switch (result18) { - case 0: { - - lifted = Result.ok(new global::WasiHttpWorld.None()); - break; - } - case 1: { - - lifted = Result.err(new global::WasiHttpWorld.None()); - break; - } - - default: throw new ArgumentException($"invalid discriminant: {result18}"); - } - if (lifted.IsOk) { - var tmp = lifted.AsOk; - return ; - } else { - throw new WitException(lifted.AsErr!, 0); - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe string? Authority() - { - var handle = this.Handle; - - var retArea = new uint[3]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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; - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe void SetAuthority(string? authority) - { - var handle = this.Handle; - - int lowered; - nint lowered3; - int lowered4; - - if (authority != null) { - var payload2 = (string) authority; - - var result = payload2; - IntPtr interopString = InteropString.FromString(result, out int lengthresult); - - lowered = 1; - lowered3 = interopString.ToInt32(); - lowered4 = lengthresult; - - } else { - - lowered = 0; - lowered3 = 0; - lowered4 = 0; - - } - var result5 = SetAuthorityWasmInterop.wasmImportSetAuthority(handle, lowered, lowered3, lowered4); - - Result lifted; - - switch (result5) { - case 0: { - - lifted = Result.ok(new global::WasiHttpWorld.None()); - break; - } - case 1: { - - lifted = Result.err(new global::WasiHttpWorld.None()); - break; - } - - default: throw new ArgumentException($"invalid discriminant: {result5}"); - } - if (lifted.IsOk) { - var tmp = lifted.AsOk; - return ; - } else { - throw new WitException(lifted.AsErr!, 0); - } - - //TODO: free alloc handle (interopString) if exists - } - - internal static class HeadersWasmInterop - { - [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.headers"), WasmImportLinkage] - internal static extern int wasmImportHeaders(int p0); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields Headers() - { - var handle = this.Handle; - var result = HeadersWasmInterop.wasmImportHeaders(handle); - var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(result)); - return resource; - - //TODO: free alloc handle (interopString) if exists - } - - } - - /** - * 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`. - */ - - internal class RequestOptions: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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(); - - } - - internal unsafe RequestOptions() - { - var result = ConstructorWasmInterop.wasmImportConstructor(); - this.Handle = result; - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe ulong? ConnectTimeout() - { - var handle = this.Handle; - - var retArea = new ulong[2]; - fixed (ulong* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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; - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal 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::WasiHttpWorld.None()); - break; - } - case 1: { - - lifted = Result.err(new global::WasiHttpWorld.None()); - break; - } - - default: throw new ArgumentException($"invalid discriminant: {result}"); - } - if (lifted.IsOk) { - var tmp = lifted.AsOk; - return ; - } else { - throw new WitException(lifted.AsErr!, 0); - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe ulong? FirstByteTimeout() - { - var handle = this.Handle; - - var retArea = new ulong[2]; - fixed (ulong* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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; - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal 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::WasiHttpWorld.None()); - break; - } - case 1: { - - lifted = Result.err(new global::WasiHttpWorld.None()); - break; - } - - default: throw new ArgumentException($"invalid discriminant: {result}"); - } - if (lifted.IsOk) { - var tmp = lifted.AsOk; - return ; - } else { - throw new WitException(lifted.AsErr!, 0); - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe ulong? BetweenBytesTimeout() - { - var handle = this.Handle; - - var retArea = new ulong[2]; - fixed (ulong* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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; - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal 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::WasiHttpWorld.None()); - break; - } - case 1: { - - lifted = Result.err(new global::WasiHttpWorld.None()); - break; - } - - default: throw new ArgumentException($"invalid discriminant: {result}"); - } - if (lifted.IsOk) { - var tmp = lifted.AsOk; - return ; - } else { - throw new WitException(lifted.AsErr!, 0); - } - - //TODO: free alloc handle (interopString) if exists - } - - } - - /** - * 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`. - */ - - internal class ResponseOutparam: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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); - - } - - internal static unsafe void Set(global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ResponseOutparam param, Result response) - { - var handle = param.Handle; - param.Handle = 0; - - int lowered332; - int lowered333; - int lowered334; - long lowered335; - nint lowered336; - nint lowered337; - int lowered338; - int lowered339; - - switch (response.Tag) { - case 0: { - global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingResponse payload = response.AsOk; - var handle0 = payload.Handle; - payload.Handle = 0; - - lowered332 = 0; - lowered333 = handle0; - lowered334 = 0; - lowered335 = 0L; - lowered336 = 0; - lowered337 = 0; - lowered338 = 0; - lowered339 = 0; - - break; - } - case 1: { - global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode payload3 = response.AsErr; - - int lowered325; - int lowered326; - long lowered327; - nint lowered328; - nint lowered329; - int lowered330; - int lowered331; - - switch (payload3.Tag) { - case 0: { - - lowered325 = 0; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 1: { - global::WasiHttpWorld.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 result = payload15; - IntPtr interopString = InteropString.FromString(result, out int lengthresult); - - lowered = 1; - lowered16 = interopString.ToInt32(); - lowered17 = lengthresult; - - } 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; - - } - - lowered325 = 1; - lowered326 = lowered; - lowered327 = (long) (lowered16); - lowered328 = lowered17; - lowered329 = lowered24; - lowered330 = lowered25; - lowered331 = 0; - - break; - } - case 2: { - - lowered325 = 2; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 3: { - - lowered325 = 3; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 4: { - - lowered325 = 4; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 5: { - - lowered325 = 5; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 6: { - - lowered325 = 6; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 7: { - - lowered325 = 7; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 8: { - - lowered325 = 8; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 9: { - - lowered325 = 9; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 10: { - - lowered325 = 10; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 11: { - - lowered325 = 11; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 12: { - - lowered325 = 12; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 13: { - - lowered325 = 13; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 14: { - global::WasiHttpWorld.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 lowered81; - nint lowered82; - int lowered83; - - if (payload64.alertMessage != null) { - var payload78 = (string) payload64.alertMessage; - - var result80 = payload78; - IntPtr interopString79 = InteropString.FromString(result80, out int lengthresult80); - - lowered81 = 1; - lowered82 = interopString79.ToInt32(); - lowered83 = lengthresult80; - - } else { - - lowered81 = 0; - lowered82 = 0; - lowered83 = 0; - - } - - lowered325 = 14; - lowered326 = lowered71; - lowered327 = (long) (lowered72); - lowered328 = lowered81; - lowered329 = lowered82; - lowered330 = lowered83; - lowered331 = 0; - - break; - } - case 15: { - - lowered325 = 15; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 16: { - - lowered325 = 16; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 17: { - ulong? payload92 = payload3.AsHttpRequestBodySize; - - int lowered99; - long lowered100; - - if (payload92 != null) { - var payload98 = (ulong) payload92; - - lowered99 = 1; - lowered100 = unchecked((long)(payload98)); - - } else { - - lowered99 = 0; - lowered100 = 0L; - - } - - lowered325 = 17; - lowered326 = lowered99; - lowered327 = lowered100; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 18: { - - lowered325 = 18; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 19: { - - lowered325 = 19; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 20: { - - lowered325 = 20; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 21: { - uint? payload112 = payload3.AsHttpRequestHeaderSectionSize; - - int lowered119; - int lowered120; - - if (payload112 != null) { - var payload118 = (uint) payload112; - - lowered119 = 1; - lowered120 = unchecked((int)(payload118)); - - } else { - - lowered119 = 0; - lowered120 = 0; - - } - - lowered325 = 21; - lowered326 = lowered119; - lowered327 = (long) (lowered120); - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 22: { - global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload? payload123 = payload3.AsHttpRequestHeaderSize; - - int lowered149; - int lowered150; - nint lowered151; - int lowered152; - int lowered153; - int lowered154; - - if (payload123 != null) { - var payload129 = (global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload) payload123; - - int lowered138; - nint lowered139; - int lowered140; - - if (payload129.fieldName != null) { - var payload135 = (string) payload129.fieldName; - - var result137 = payload135; - IntPtr interopString136 = InteropString.FromString(result137, out int lengthresult137); - - lowered138 = 1; - lowered139 = interopString136.ToInt32(); - lowered140 = lengthresult137; - - } else { - - lowered138 = 0; - lowered139 = 0; - lowered140 = 0; - - } - - int lowered147; - int lowered148; - - if (payload129.fieldSize != null) { - var payload146 = (uint) payload129.fieldSize; - - lowered147 = 1; - lowered148 = unchecked((int)(payload146)); - - } else { - - lowered147 = 0; - lowered148 = 0; - - } - - lowered149 = 1; - lowered150 = lowered138; - lowered151 = lowered139; - lowered152 = lowered140; - lowered153 = lowered147; - lowered154 = lowered148; - - } else { - - lowered149 = 0; - lowered150 = 0; - lowered151 = 0; - lowered152 = 0; - lowered153 = 0; - lowered154 = 0; - - } - - lowered325 = 22; - lowered326 = lowered149; - lowered327 = (long) (lowered150); - lowered328 = lowered151; - lowered329 = lowered152; - lowered330 = lowered153; - lowered331 = lowered154; - - break; - } - case 23: { - uint? payload157 = payload3.AsHttpRequestTrailerSectionSize; - - int lowered164; - int lowered165; - - if (payload157 != null) { - var payload163 = (uint) payload157; - - lowered164 = 1; - lowered165 = unchecked((int)(payload163)); - - } else { - - lowered164 = 0; - lowered165 = 0; - - } - - lowered325 = 23; - lowered326 = lowered164; - lowered327 = (long) (lowered165); - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 24: { - global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload payload168 = payload3.AsHttpRequestTrailerSize; - - int lowered177; - nint lowered178; - int lowered179; - - if (payload168.fieldName != null) { - var payload174 = (string) payload168.fieldName; - - var result176 = payload174; - IntPtr interopString175 = InteropString.FromString(result176, out int lengthresult176); - - lowered177 = 1; - lowered178 = interopString175.ToInt32(); - lowered179 = lengthresult176; - - } else { - - lowered177 = 0; - lowered178 = 0; - lowered179 = 0; - - } - - int lowered186; - int lowered187; - - if (payload168.fieldSize != null) { - var payload185 = (uint) payload168.fieldSize; - - lowered186 = 1; - lowered187 = unchecked((int)(payload185)); - - } else { - - lowered186 = 0; - lowered187 = 0; - - } - - lowered325 = 24; - lowered326 = lowered177; - lowered327 = (long) (lowered178); - lowered328 = lowered179; - lowered329 = lowered186; - lowered330 = lowered187; - lowered331 = 0; - - break; - } - case 25: { - - lowered325 = 25; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 26: { - uint? payload193 = payload3.AsHttpResponseHeaderSectionSize; - - int lowered200; - int lowered201; - - if (payload193 != null) { - var payload199 = (uint) payload193; - - lowered200 = 1; - lowered201 = unchecked((int)(payload199)); - - } else { - - lowered200 = 0; - lowered201 = 0; - - } - - lowered325 = 26; - lowered326 = lowered200; - lowered327 = (long) (lowered201); - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 27: { - global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload payload204 = payload3.AsHttpResponseHeaderSize; - - int lowered213; - nint lowered214; - int lowered215; - - if (payload204.fieldName != null) { - var payload210 = (string) payload204.fieldName; - - var result212 = payload210; - IntPtr interopString211 = InteropString.FromString(result212, out int lengthresult212); - - lowered213 = 1; - lowered214 = interopString211.ToInt32(); - lowered215 = lengthresult212; - - } else { - - lowered213 = 0; - lowered214 = 0; - lowered215 = 0; - - } - - int lowered222; - int lowered223; - - if (payload204.fieldSize != null) { - var payload221 = (uint) payload204.fieldSize; - - lowered222 = 1; - lowered223 = unchecked((int)(payload221)); - - } else { - - lowered222 = 0; - lowered223 = 0; - - } - - lowered325 = 27; - lowered326 = lowered213; - lowered327 = (long) (lowered214); - lowered328 = lowered215; - lowered329 = lowered222; - lowered330 = lowered223; - lowered331 = 0; - - break; - } - case 28: { - ulong? payload226 = payload3.AsHttpResponseBodySize; - - int lowered233; - long lowered234; - - if (payload226 != null) { - var payload232 = (ulong) payload226; - - lowered233 = 1; - lowered234 = unchecked((long)(payload232)); - - } else { - - lowered233 = 0; - lowered234 = 0L; - - } - - lowered325 = 28; - lowered326 = lowered233; - lowered327 = lowered234; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 29: { - uint? payload237 = payload3.AsHttpResponseTrailerSectionSize; - - int lowered244; - int lowered245; - - if (payload237 != null) { - var payload243 = (uint) payload237; - - lowered244 = 1; - lowered245 = unchecked((int)(payload243)); - - } else { - - lowered244 = 0; - lowered245 = 0; - - } - - lowered325 = 29; - lowered326 = lowered244; - lowered327 = (long) (lowered245); - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 30: { - global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload payload248 = payload3.AsHttpResponseTrailerSize; - - int lowered257; - nint lowered258; - int lowered259; - - if (payload248.fieldName != null) { - var payload254 = (string) payload248.fieldName; - - var result256 = payload254; - IntPtr interopString255 = InteropString.FromString(result256, out int lengthresult256); - - lowered257 = 1; - lowered258 = interopString255.ToInt32(); - lowered259 = lengthresult256; - - } else { - - lowered257 = 0; - lowered258 = 0; - lowered259 = 0; - - } - - int lowered266; - int lowered267; - - if (payload248.fieldSize != null) { - var payload265 = (uint) payload248.fieldSize; - - lowered266 = 1; - lowered267 = unchecked((int)(payload265)); - - } else { - - lowered266 = 0; - lowered267 = 0; - - } - - lowered325 = 30; - lowered326 = lowered257; - lowered327 = (long) (lowered258); - lowered328 = lowered259; - lowered329 = lowered266; - lowered330 = lowered267; - lowered331 = 0; - - break; - } - case 31: { - string? payload270 = payload3.AsHttpResponseTransferCoding; - - int lowered279; - nint lowered280; - int lowered281; - - if (payload270 != null) { - var payload276 = (string) payload270; - - var result278 = payload276; - IntPtr interopString277 = InteropString.FromString(result278, out int lengthresult278); - - lowered279 = 1; - lowered280 = interopString277.ToInt32(); - lowered281 = lengthresult278; - - } else { - - lowered279 = 0; - lowered280 = 0; - lowered281 = 0; - - } - - lowered325 = 31; - lowered326 = lowered279; - lowered327 = (long) (lowered280); - lowered328 = lowered281; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 32: { - string? payload284 = payload3.AsHttpResponseContentCoding; - - int lowered293; - nint lowered294; - int lowered295; - - if (payload284 != null) { - var payload290 = (string) payload284; - - var result292 = payload290; - IntPtr interopString291 = InteropString.FromString(result292, out int lengthresult292); - - lowered293 = 1; - lowered294 = interopString291.ToInt32(); - lowered295 = lengthresult292; - - } else { - - lowered293 = 0; - lowered294 = 0; - lowered295 = 0; - - } - - lowered325 = 32; - lowered326 = lowered293; - lowered327 = (long) (lowered294); - lowered328 = lowered295; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 33: { - - lowered325 = 33; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 34: { - - lowered325 = 34; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 35: { - - lowered325 = 35; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 36: { - - lowered325 = 36; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 37: { - - lowered325 = 37; - lowered326 = 0; - lowered327 = 0L; - lowered328 = 0; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - case 38: { - string? payload313 = payload3.AsInternalError; - - int lowered322; - nint lowered323; - int lowered324; - - if (payload313 != null) { - var payload319 = (string) payload313; - - var result321 = payload319; - IntPtr interopString320 = InteropString.FromString(result321, out int lengthresult321); - - lowered322 = 1; - lowered323 = interopString320.ToInt32(); - lowered324 = lengthresult321; - - } else { - - lowered322 = 0; - lowered323 = 0; - lowered324 = 0; - - } - - lowered325 = 38; - lowered326 = lowered322; - lowered327 = (long) (lowered323); - lowered328 = lowered324; - lowered329 = 0; - lowered330 = 0; - lowered331 = 0; - - break; - } - - default: throw new ArgumentException($"invalid discriminant: {payload3}"); - } - - lowered332 = 1; - lowered333 = lowered325; - lowered334 = lowered326; - lowered335 = lowered327; - lowered336 = lowered328; - lowered337 = lowered329; - lowered338 = lowered330; - lowered339 = lowered331; - - break; - } - - default: throw new ArgumentException($"invalid discriminant: {response}"); - } - SetWasmInterop.wasmImportSet(handle, lowered332, lowered333, lowered334, lowered335, lowered336, lowered337, lowered338, lowered339); - - //TODO: free alloc handle (interopString) if exists - } - - } - - /** - * Represents an incoming HTTP Response. - */ - - internal class IncomingResponse: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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); - - } - - internal unsafe ushort Status() - { - var handle = this.Handle; - var result = StatusWasmInterop.wasmImportStatus(handle); - return ((ushort)result); - - //TODO: free alloc handle (interopString) if exists - } - - internal static class HeadersWasmInterop - { - [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-response.headers"), WasmImportLinkage] - internal static extern int wasmImportHeaders(int p0); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields Headers() - { - var handle = this.Handle; - var result = HeadersWasmInterop.wasmImportHeaders(handle); - var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(result)); - return resource; - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody Consume() - { - var handle = this.Handle; - - var retArea = new uint[2]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - ConsumeWasmInterop.wasmImportConsume(handle, ptr); - - Result lifted; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody(new global::WasiHttpWorld.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::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - } - - /** - * 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. - */ - - internal class IncomingBody: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.InputStream Stream() - { - var handle = this.Handle; - - var retArea = new uint[2]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - StreamWasmInterop.wasmImportStream(handle, ptr); - - Result lifted; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.InputStream(new global::WasiHttpWorld.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::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - internal static class FinishWasmInterop - { - [DllImport("wasi:http/types@0.2.0", EntryPoint = "[static]incoming-body.finish"), WasmImportLinkage] - internal static extern int wasmImportFinish(int p0); - - } - - internal static unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FutureTrailers Finish(global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FutureTrailers(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FutureTrailers.THandle(result)); - return resource; - - //TODO: free alloc handle (interopString) if exists - } - - } - - /** - * 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. - */ - - internal class FutureTrailers: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable Subscribe() - { - var handle = this.Handle; - var result = SubscribeWasmInterop.wasmImportSubscribe(handle); - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result)); - return resource; - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe Result, None>? Get() - { - var handle = this.Handle; - - var retArea = new ulong[7]; - fixed (ulong* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode lifted200; - - switch (new Span((void*)(ptr + 24), 1)[0]) { - case 0: { - - lifted200 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.dnsError(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.DnsErrorPayload ( - lifted20, lifted25)); - break; - } - case 2: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationNotFound(); - break; - } - case 3: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationUnavailable(); - break; - } - case 4: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationIpProhibited(); - break; - } - case 5: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationIpUnroutable(); - break; - } - case 6: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionRefused(); - break; - } - case 7: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionTerminated(); - break; - } - case 8: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionTimeout(); - break; - } - case 9: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionReadTimeout(); - break; - } - case 10: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionWriteTimeout(); - break; - } - case 11: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionLimitReached(); - break; - } - case 12: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.tlsProtocolError(); - break; - } - case 13: { - - lifted200 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.tlsAlertReceived(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.TlsAlertReceivedPayload ( - lifted56, lifted61)); - break; - } - case 15: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestDenied(); - break; - } - case 16: { - - lifted200 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestBodySize(lifted72); - break; - } - case 18: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestMethodInvalid(); - break; - } - case 19: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestUriInvalid(); - break; - } - case 20: { - - lifted200 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestHeaderSectionSize(lifted85); - break; - } - case 22: { - - global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestTrailerSize(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( - lifted116, lifted121)); - break; - } - case 25: { - - lifted200 = global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseHeaderSize(new global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseTrailerSize(new global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseContentCoding(lifted182); - break; - } - case 33: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseTimeout(); - break; - } - case 34: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpUpgradeFailed(); - break; - } - case 35: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpProtocolError(); - break; - } - case 36: { - - lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.loopDetected(); - break; - } - case 37: { - - lifted200 = global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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; - } - - //TODO: free alloc handle (interopString) if exists - } - - } - - /** - * Represents an outgoing HTTP Response. - */ - - internal class OutgoingResponse: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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); - - } - - internal unsafe OutgoingResponse(global::WasiHttpWorld.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; - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe ushort StatusCode() - { - var handle = this.Handle; - var result = StatusCodeWasmInterop.wasmImportStatusCode(handle); - return ((ushort)result); - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal 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::WasiHttpWorld.None()); - break; - } - case 1: { - - lifted = Result.err(new global::WasiHttpWorld.None()); - break; - } - - default: throw new ArgumentException($"invalid discriminant: {result}"); - } - if (lifted.IsOk) { - var tmp = lifted.AsOk; - return ; - } else { - throw new WitException(lifted.AsErr!, 0); - } - - //TODO: free alloc handle (interopString) if exists - } - - internal static class HeadersWasmInterop - { - [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-response.headers"), WasmImportLinkage] - internal static extern int wasmImportHeaders(int p0); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields Headers() - { - var handle = this.Handle; - var result = HeadersWasmInterop.wasmImportHeaders(handle); - var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(result)); - return resource; - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingBody Body() - { - var handle = this.Handle; - - var retArea = new uint[2]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - BodyWasmInterop.wasmImportBody(handle, ptr); - - Result lifted; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingBody(new global::WasiHttpWorld.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::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - } - - /** - * 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. - */ - - internal class OutgoingBody: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.OutputStream Write() - { - var handle = this.Handle; - - var retArea = new uint[2]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - WriteWasmInterop.wasmImportWrite(handle, ptr); - - Result lifted; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.OutputStream(new global::WasiHttpWorld.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::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal static unsafe void Finish(global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingBody @this, global::WasiHttpWorld.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::WasiHttpWorld.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 = new ulong[5]; - fixed (ulong* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - FinishWasmInterop.wasmImportFinish(handle, lowered, lowered4, ptr); - - Result lifted197; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - - lifted197 = Result.ok(new global::WasiHttpWorld.None()); - break; - } - case 1: { - - global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode lifted196; - - switch (new Span((void*)(ptr + 8), 1)[0]) { - case 0: { - - lifted196 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.dnsError(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.DnsErrorPayload ( - lifted, lifted21)); - break; - } - case 2: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationNotFound(); - break; - } - case 3: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationUnavailable(); - break; - } - case 4: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationIpProhibited(); - break; - } - case 5: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationIpUnroutable(); - break; - } - case 6: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionRefused(); - break; - } - case 7: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionTerminated(); - break; - } - case 8: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionTimeout(); - break; - } - case 9: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionReadTimeout(); - break; - } - case 10: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionWriteTimeout(); - break; - } - case 11: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionLimitReached(); - break; - } - case 12: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.tlsProtocolError(); - break; - } - case 13: { - - lifted196 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.tlsAlertReceived(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.TlsAlertReceivedPayload ( - lifted52, lifted57)); - break; - } - case 15: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestDenied(); - break; - } - case 16: { - - lifted196 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestBodySize(lifted68); - break; - } - case 18: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestMethodInvalid(); - break; - } - case 19: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestUriInvalid(); - break; - } - case 20: { - - lifted196 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestHeaderSectionSize(lifted81); - break; - } - case 22: { - - global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestTrailerSize(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( - lifted112, lifted117)); - break; - } - case 25: { - - lifted196 = global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseHeaderSize(new global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseTrailerSize(new global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseContentCoding(lifted178); - break; - } - case 33: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseTimeout(); - break; - } - case 34: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpUpgradeFailed(); - break; - } - case 35: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpProtocolError(); - break; - } - case 36: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.loopDetected(); - break; - } - case 37: { - - lifted196 = global::WasiHttpWorld.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::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - } - - /** - * 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. - */ - - internal class FutureIncomingResponse: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable Subscribe() - { - var handle = this.Handle; - var result = SubscribeWasmInterop.wasmImportSubscribe(handle); - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result)); - return resource; - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe Result, None>? Get() - { - var handle = this.Handle; - - var retArea = new ulong[7]; - fixed (ulong* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingResponse(new global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode lifted195; - - switch (new Span((void*)(ptr + 24), 1)[0]) { - case 0: { - - lifted195 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.dnsError(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.DnsErrorPayload ( - lifted, lifted20)); - break; - } - case 2: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationNotFound(); - break; - } - case 3: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationUnavailable(); - break; - } - case 4: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationIpProhibited(); - break; - } - case 5: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationIpUnroutable(); - break; - } - case 6: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionRefused(); - break; - } - case 7: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionTerminated(); - break; - } - case 8: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionTimeout(); - break; - } - case 9: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionReadTimeout(); - break; - } - case 10: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionWriteTimeout(); - break; - } - case 11: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionLimitReached(); - break; - } - case 12: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.tlsProtocolError(); - break; - } - case 13: { - - lifted195 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.tlsAlertReceived(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.TlsAlertReceivedPayload ( - lifted51, lifted56)); - break; - } - case 15: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestDenied(); - break; - } - case 16: { - - lifted195 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestBodySize(lifted67); - break; - } - case 18: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestMethodInvalid(); - break; - } - case 19: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestUriInvalid(); - break; - } - case 20: { - - lifted195 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestHeaderSectionSize(lifted80); - break; - } - case 22: { - - global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestTrailerSize(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( - lifted111, lifted116)); - break; - } - case 25: { - - lifted195 = global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseHeaderSize(new global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseTrailerSize(new global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseContentCoding(lifted177); - break; - } - case 33: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseTimeout(); - break; - } - case 34: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpUpgradeFailed(); - break; - } - case 35: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpProtocolError(); - break; - } - case 36: { - - lifted195 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.loopDetected(); - break; - } - case 37: { - - lifted195 = global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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; - } - - //TODO: free alloc handle (interopString) if exists - } - - } - -} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_0.OutgoingHandlerInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_0.OutgoingHandlerInterop.cs deleted file mode 100644 index 2d24c51b3aef60..00000000000000 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_0.OutgoingHandlerInterop.cs +++ /dev/null @@ -1,665 +0,0 @@ -// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT! -// -#nullable enable - -using System; -using System.Runtime.CompilerServices; -using System.Collections; -using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace WasiHttpWorld.wit.imports.wasi.http.v0_2_0 -{ - internal 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); - - } - - internal static unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FutureIncomingResponse Handle(global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingRequest request, global::WasiHttpWorld.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::WasiHttpWorld.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 = new ulong[5]; - fixed (ulong* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - HandleWasmInterop.wasmImportHandle(handle, lowered, lowered4, ptr); - - Result lifted197; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FutureIncomingResponse(new global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode lifted196; - - switch (new Span((void*)(ptr + 8), 1)[0]) { - case 0: { - - lifted196 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.dnsError(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.DnsErrorPayload ( - lifted, lifted21)); - break; - } - case 2: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationNotFound(); - break; - } - case 3: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationUnavailable(); - break; - } - case 4: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationIpProhibited(); - break; - } - case 5: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationIpUnroutable(); - break; - } - case 6: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionRefused(); - break; - } - case 7: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionTerminated(); - break; - } - case 8: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionTimeout(); - break; - } - case 9: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionReadTimeout(); - break; - } - case 10: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionWriteTimeout(); - break; - } - case 11: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionLimitReached(); - break; - } - case 12: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.tlsProtocolError(); - break; - } - case 13: { - - lifted196 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.tlsAlertReceived(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.TlsAlertReceivedPayload ( - lifted52, lifted57)); - break; - } - case 15: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestDenied(); - break; - } - case 16: { - - lifted196 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestBodySize(lifted68); - break; - } - case 18: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestMethodInvalid(); - break; - } - case 19: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestUriInvalid(); - break; - } - case 20: { - - lifted196 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestHeaderSectionSize(lifted81); - break; - } - case 22: { - - global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestTrailerSize(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( - lifted112, lifted117)); - break; - } - case 25: { - - lifted196 = global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseHeaderSize(new global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseTrailerSize(new global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseContentCoding(lifted178); - break; - } - case 33: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseTimeout(); - break; - } - case 34: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpUpgradeFailed(); - break; - } - case 35: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpProtocolError(); - break; - } - case 36: { - - lifted196 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.loopDetected(); - break; - } - case 37: { - - lifted196 = global::WasiHttpWorld.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::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - } -} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_0.TypesInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_0.TypesInterop.cs deleted file mode 100644 index f4505e864af3b6..00000000000000 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_0.TypesInterop.cs +++ /dev/null @@ -1,640 +0,0 @@ -// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT! -// -#nullable enable - -using System; -using System.Runtime.CompilerServices; -using System.Collections; -using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace WasiHttpWorld.wit.imports.wasi.http.v0_2_0 -{ - internal 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); - - } - - internal static unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode? HttpErrorCode(global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error err) - { - var handle = err.Handle; - - var retArea = new ulong[5]; - fixed (ulong* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - HttpErrorCodeWasmInterop.wasmImportHttpErrorCode(handle, ptr); - - global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode lifted189; - - switch (new Span((void*)(ptr + 8), 1)[0]) { - case 0: { - - lifted189 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.dnsError(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.DnsErrorPayload ( - lifted, lifted14)); - break; - } - case 2: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationNotFound(); - break; - } - case 3: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationUnavailable(); - break; - } - case 4: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationIpProhibited(); - break; - } - case 5: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationIpUnroutable(); - break; - } - case 6: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionRefused(); - break; - } - case 7: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionTerminated(); - break; - } - case 8: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionTimeout(); - break; - } - case 9: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionReadTimeout(); - break; - } - case 10: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionWriteTimeout(); - break; - } - case 11: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionLimitReached(); - break; - } - case 12: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.tlsProtocolError(); - break; - } - case 13: { - - lifted189 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.tlsAlertReceived(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.TlsAlertReceivedPayload ( - lifted45, lifted50)); - break; - } - case 15: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestDenied(); - break; - } - case 16: { - - lifted189 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestBodySize(lifted61); - break; - } - case 18: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestMethodInvalid(); - break; - } - case 19: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestUriInvalid(); - break; - } - case 20: { - - lifted189 = global::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestHeaderSectionSize(lifted74); - break; - } - case 22: { - - global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestTrailerSize(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload ( - lifted105, lifted110)); - break; - } - case 25: { - - lifted189 = global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseHeaderSize(new global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseTrailerSize(new global::WasiHttpWorld.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::WasiHttpWorld.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::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseContentCoding(lifted171); - break; - } - case 33: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseTimeout(); - break; - } - case 34: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpUpgradeFailed(); - break; - } - case 35: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpProtocolError(); - break; - } - case 36: { - - lifted189 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.loopDetected(); - break; - } - case 37: { - - lifted189 = global::WasiHttpWorld.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::WasiHttpWorld.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; - } - - //TODO: free alloc handle (interopString) if exists - } - - } -} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.ErrorInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.ErrorInterop.cs deleted file mode 100644 index 1e1f0b474f764b..00000000000000 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.ErrorInterop.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT! -// -#nullable enable - -using System; -using System.Runtime.CompilerServices; -using System.Collections; -using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace WasiHttpWorld.wit.imports.wasi.io.v0_2_0 -{ - internal static class ErrorInterop { - - } -} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.cs deleted file mode 100644 index b756be5ca465c9..00000000000000 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.cs +++ /dev/null @@ -1,87 +0,0 @@ -// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT! -// -#nullable enable - -using System; -using System.Runtime.CompilerServices; -using System.Collections; -using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace WasiHttpWorld.wit.imports.wasi.io.v0_2_0; - -internal interface IError { - - /** - * A resource which represents some error information. - * - * The only method provided by this resource is `to-debug-string`, - * which provides some human-readable information about the error. - * - * In the `wasi:io` package, this resource is returned through the - * `wasi:io/streams/stream-error` type. - * - * To provide more specific error information, other interfaces may - * provide functions to further "downcast" this error into more specific - * error information. For example, `error`s returned in streams derived - * from filesystem types to be described using the filesystem's own - * error-code type, using the function - * `wasi:filesystem/types/filesystem-error-code`, which takes a parameter - * `borrow<error>` and returns - * `option<wasi:filesystem/types/error-code>`. - * - * The set of functions which can "downcast" an `error` into a more - * concrete type is open. - */ - - internal class Error: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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); - - } - - internal unsafe string ToDebugString() - { - var handle = this.Handle; - - var retArea = new uint[2]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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))); - } - - //TODO: free alloc handle (interopString) if exists - } - - } - -} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.cs deleted file mode 100644 index 0f40463e5cdace..00000000000000 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.cs +++ /dev/null @@ -1,78 +0,0 @@ -// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT! -// -#nullable enable - -using System; -using System.Runtime.CompilerServices; -using System.Collections; -using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace WasiHttpWorld.wit.imports.wasi.io.v0_2_0; - -internal interface IPoll { - - /** - * `pollable` represents a single I/O event which may be ready, or not. - */ - - internal class Pollable: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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); - - } - - internal unsafe bool Ready() - { - var handle = this.Handle; - var result = ReadyWasmInterop.wasmImportReady(handle); - return (result != 0); - - //TODO: free alloc handle (interopString) if exists - } - - internal static class BlockWasmInterop - { - [DllImport("wasi:io/poll@0.2.0", EntryPoint = "[method]pollable.block"), WasmImportLinkage] - internal static extern void wasmImportBlock(int p0); - - } - - internal unsafe void Block() - { - var handle = this.Handle; - BlockWasmInterop.wasmImportBlock(handle); - - //TODO: free alloc handle (interopString) if exists - } - - } - -} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.cs deleted file mode 100644 index 650ebe41d3aa0a..00000000000000 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.cs +++ /dev/null @@ -1,980 +0,0 @@ -// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT! -// -#nullable enable - -using System; -using System.Runtime.CompilerServices; -using System.Collections; -using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace WasiHttpWorld.wit.imports.wasi.io.v0_2_0; - -internal interface IStreams { - - /** - * An error for input-stream and output-stream operations. - */ - - internal class StreamError { - internal readonly byte Tag; - private readonly object? value; - - private StreamError(byte tag, object? value) { - this.Tag = tag; - this.value = value; - } - - internal static StreamError lastOperationFailed(global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error lastOperationFailed) { - return new StreamError(LAST_OPERATION_FAILED, lastOperationFailed); - } - - internal static StreamError closed() { - return new StreamError(CLOSED, null); - } - - internal global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error AsLastOperationFailed - { - get - { - if (Tag == LAST_OPERATION_FAILED) - return (global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error)value!; - else - throw new ArgumentException("expected LAST_OPERATION_FAILED, got " + Tag); - } - } - - internal const byte LAST_OPERATION_FAILED = 0; - internal const byte CLOSED = 1; - } - - /** - * An input bytestream. - * - * `input-stream`s are *non-blocking* to the extent practical on underlying - * platforms. I/O operations always return promptly; if fewer bytes are - * promptly available than requested, they return the number of bytes promptly - * available, which could even be zero. To wait for data to be available, - * use the `subscribe` function to obtain a `pollable` which can be polled - * for using `wasi:io/poll`. - */ - - internal class InputStream: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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); - - } - - internal unsafe byte[] Read(ulong len) - { - var handle = this.Handle; - - var retArea = new uint[3]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; - - switch (new Span((void*)(ptr + 4), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); - - lifted = global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.lastOperationFailed(resource); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe byte[] BlockingRead(ulong len) - { - var handle = this.Handle; - - var retArea = new uint[3]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; - - switch (new Span((void*)(ptr + 4), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); - - lifted = global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.lastOperationFailed(resource); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe ulong Skip(ulong len) - { - var handle = this.Handle; - - var retArea = new ulong[2]; - fixed (ulong* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; - - switch (new Span((void*)(ptr + 8), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 12), 4)))); - - lifted = global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.lastOperationFailed(resource); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe ulong BlockingSkip(ulong len) - { - var handle = this.Handle; - - var retArea = new ulong[2]; - fixed (ulong* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; - - switch (new Span((void*)(ptr + 8), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 12), 4)))); - - lifted = global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.lastOperationFailed(resource); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - internal static class SubscribeWasmInterop - { - [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]input-stream.subscribe"), WasmImportLinkage] - internal static extern int wasmImportSubscribe(int p0); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable Subscribe() - { - var handle = this.Handle; - var result = SubscribeWasmInterop.wasmImportSubscribe(handle); - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result)); - return resource; - - //TODO: free alloc handle (interopString) if exists - } - - } - - /** - * An output bytestream. - * - * `output-stream`s are *non-blocking* to the extent practical on - * underlying platforms. Except where specified otherwise, I/O operations also - * always return promptly, after the number of bytes that can be written - * promptly, which could even be zero. To wait for the stream to be ready to - * accept data, the `subscribe` function to obtain a `pollable` which can be - * polled for using `wasi:io/poll`. - */ - - internal class OutputStream: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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); - - } - - internal unsafe ulong CheckWrite() - { - var handle = this.Handle; - - var retArea = new ulong[2]; - fixed (ulong* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; - - switch (new Span((void*)(ptr + 8), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 12), 4)))); - - lifted = global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.lastOperationFailed(resource); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe void Write(byte[] contents) - { - var handle = this.Handle; - - void* buffer = stackalloc byte[(contents).Length]; - contents.AsSpan().CopyTo(new Span(buffer, contents.Length)); - - var retArea = new uint[3]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - WriteWasmInterop.wasmImportWrite(handle, (int)buffer, (contents).Length, ptr); - - Result lifted6; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - - lifted6 = Result.ok(new global::WasiHttpWorld.None()); - break; - } - case 1: { - - global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; - - switch (new Span((void*)(ptr + 4), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); - - lifted = global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.lastOperationFailed(resource); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe void BlockingWriteAndFlush(byte[] contents) - { - var handle = this.Handle; - - void* buffer = stackalloc byte[(contents).Length]; - contents.AsSpan().CopyTo(new Span(buffer, contents.Length)); - - var retArea = new uint[3]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - BlockingWriteAndFlushWasmInterop.wasmImportBlockingWriteAndFlush(handle, (int)buffer, (contents).Length, ptr); - - Result lifted6; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - - lifted6 = Result.ok(new global::WasiHttpWorld.None()); - break; - } - case 1: { - - global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; - - switch (new Span((void*)(ptr + 4), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); - - lifted = global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.lastOperationFailed(resource); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe void Flush() - { - var handle = this.Handle; - - var retArea = new uint[3]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - FlushWasmInterop.wasmImportFlush(handle, ptr); - - Result lifted6; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - - lifted6 = Result.ok(new global::WasiHttpWorld.None()); - break; - } - case 1: { - - global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; - - switch (new Span((void*)(ptr + 4), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); - - lifted = global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.lastOperationFailed(resource); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe void BlockingFlush() - { - var handle = this.Handle; - - var retArea = new uint[3]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - BlockingFlushWasmInterop.wasmImportBlockingFlush(handle, ptr); - - Result lifted6; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - - lifted6 = Result.ok(new global::WasiHttpWorld.None()); - break; - } - case 1: { - - global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; - - switch (new Span((void*)(ptr + 4), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); - - lifted = global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.lastOperationFailed(resource); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - internal static class SubscribeWasmInterop - { - [DllImport("wasi:io/streams@0.2.0", EntryPoint = "[method]output-stream.subscribe"), WasmImportLinkage] - internal static extern int wasmImportSubscribe(int p0); - - } - - internal unsafe global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable Subscribe() - { - var handle = this.Handle; - var result = SubscribeWasmInterop.wasmImportSubscribe(handle); - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result)); - return resource; - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe void WriteZeroes(ulong len) - { - var handle = this.Handle; - - var retArea = new uint[3]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - WriteZeroesWasmInterop.wasmImportWriteZeroes(handle, unchecked((long)(len)), ptr); - - Result lifted6; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - - lifted6 = Result.ok(new global::WasiHttpWorld.None()); - break; - } - case 1: { - - global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; - - switch (new Span((void*)(ptr + 4), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); - - lifted = global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.lastOperationFailed(resource); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe void BlockingWriteZeroesAndFlush(ulong len) - { - var handle = this.Handle; - - var retArea = new uint[3]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - BlockingWriteZeroesAndFlushWasmInterop.wasmImportBlockingWriteZeroesAndFlush(handle, unchecked((long)(len)), ptr); - - Result lifted6; - - switch (new Span((void*)(ptr + 0), 1)[0]) { - case 0: { - - lifted6 = Result.ok(new global::WasiHttpWorld.None()); - break; - } - case 1: { - - global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; - - switch (new Span((void*)(ptr + 4), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)))); - - lifted = global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.lastOperationFailed(resource); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe ulong Splice(global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.InputStream src, ulong len) - { - var handle = this.Handle; - var handle0 = src.Handle; - - var retArea = new ulong[2]; - fixed (ulong* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; - - switch (new Span((void*)(ptr + 8), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 12), 4)))); - - lifted = global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.lastOperationFailed(resource); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - 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); - - } - - internal unsafe ulong BlockingSplice(global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.InputStream src, ulong len) - { - var handle = this.Handle; - var handle0 = src.Handle; - - var retArea = new ulong[2]; - fixed (ulong* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError lifted; - - switch (new Span((void*)(ptr + 8), 1)[0]) { - case 0: { - var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.Error.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 12), 4)))); - - lifted = global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.StreamError.lastOperationFailed(resource); - break; - } - case 1: { - - lifted = global::WasiHttpWorld.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); - } - } - - //TODO: free alloc handle (interopString) if exists - } - - } - -} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.PollInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.PollInterop.cs deleted file mode 100644 index 77b82700cf5396..00000000000000 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.PollInterop.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT! -// -#nullable enable - -using System; -using System.Runtime.CompilerServices; -using System.Collections; -using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace WasiHttpWorld.wit.imports.wasi.io.v0_2_0 -{ - internal 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); - - } - - internal static unsafe uint[] Poll(List @in) - { - - byte[] buffer = new byte[4 * @in.Count]; - var gcHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - var address = gcHandle.AddrOfPinnedObject(); - - for (int index = 0; index < @in.Count; ++index) { - global::WasiHttpWorld.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), unchecked((int)handle)); - - } - - var retArea = new uint[2]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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)); - gcHandle.Free(); - return array; - } - - //TODO: free alloc handle (interopString) if exists - } - - } -} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.StreamsInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.StreamsInterop.cs deleted file mode 100644 index cd31c05f1bb8ff..00000000000000 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_0.StreamsInterop.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT! -// -#nullable enable - -using System; -using System.Runtime.CompilerServices; -using System.Collections; -using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace WasiHttpWorld.wit.imports.wasi.io.v0_2_0 -{ - internal static class StreamsInterop { - - } -} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld_component_type.wit b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld_component_type.wit index b6c30d485194eb..085c5eba9ca60e 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld_component_type.wit +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld_component_type.wit @@ -1,10 +1,10 @@ -package wasi:http@0.2.0; +package wasi:http@0.2.8; 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}; + use wasi:clocks/monotonic-clock@0.2.8.{duration}; + use wasi:io/streams@0.2.8.{input-stream, output-stream}; + use wasi:io/error@0.2.8.{error as io-error}; + use wasi:io/poll@0.2.8.{pollable}; variant method { get, @@ -90,17 +90,19 @@ interface types { type field-key = string; + type field-name = field-key; + 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>; + from-list: static func(entries: list>) -> result; + get: func(name: field-name) -> list; + has: func(name: field-name) -> bool; + set: func(name: field-name, value: list) -> result<_, header-error>; + delete: func(name: field-name) -> result<_, header-error>; + append: func(name: field-name, value: field-value) -> result<_, header-error>; + entries: func() -> list>; clone: func() -> fields; } @@ -191,14 +193,14 @@ interface outgoing-handler { } world wasi-http { - 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:io/poll@0.2.8; + import wasi:clocks/monotonic-clock@0.2.8; + import wasi:io/error@0.2.8; + import wasi:io/streams@0.2.8; import types; import outgoing-handler; } -package wasi:io@0.2.0 { +package wasi:io@0.2.8 { interface poll { resource pollable { ready: func() -> bool; @@ -245,9 +247,9 @@ package wasi:io@0.2.0 { } -package wasi:clocks@0.2.0 { +package wasi:clocks@0.2.8 { interface monotonic-clock { - use wasi:io/poll@0.2.0.{pollable}; + use wasi:io/poll@0.2.8.{pollable}; type instant = u64; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs index 5738da0b8a8634..85e4508598bb1b 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs @@ -5,10 +5,10 @@ using System.Threading; using System.Threading.Tasks; using WasiHttpWorld; -using WasiHttpWorld.wit.imports.wasi.http.v0_2_0; -using WasiHttpWorld.wit.imports.wasi.io.v0_2_0; -using static WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes; -using static WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams; +using WasiHttpWorld.wit.Imports.wasi.http.v0_2_8; +using WasiHttpWorld.wit.Imports.wasi.io.v0_2_8; +using static WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports; +using static WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports; namespace System.Net.Http { @@ -108,7 +108,7 @@ CancellationToken cancellationToken } catch (WitException e) { - if (((StreamError)e.Value).Tag == StreamError.CLOSED) + if (((StreamError)e.Value).Tag == StreamError.Tags.Closed) { otherSideClosed = true; return 0; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiOutputStream.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiOutputStream.cs index 43452d5d3236bf..fcaaaa4d1da7f8 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiOutputStream.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiOutputStream.cs @@ -5,10 +5,10 @@ using System.Threading; using System.Threading.Tasks; using WasiHttpWorld; -using WasiHttpWorld.wit.imports.wasi.http.v0_2_0; -using WasiHttpWorld.wit.imports.wasi.io.v0_2_0; -using static WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes; -using static WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams; +using WasiHttpWorld.wit.Imports.wasi.http.v0_2_8; +using WasiHttpWorld.wit.Imports.wasi.io.v0_2_8; +using static WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.ITypesImports; +using static WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.IStreamsImports; namespace System.Net.Http { diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.ps1 b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.ps1 index bd67c74bff211f..db1be8182e69ef 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.ps1 +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.ps1 @@ -10,13 +10,13 @@ $dir = Split-Path $scriptpath Push-Location $dir -cargo install --locked --no-default-features --features csharp --version 0.32.0 wit-bindgen-cli -Invoke-WebRequest -UseBasicParsing -Uri https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.0.tar.gz -OutFile v0.2.0.tar.gz -tar xzf v0.2.0.tar.gz -cp world.wit wasi-http-0.2.0/wit/world.wit -wit-bindgen c-sharp -w wasi-http -r native-aot --internal wasi-http-0.2.0/wit -rm -r wasi-http-0.2.0 -rm v0.2.0.tar.gz +cargo install --locked --no-default-features --features csharp --version 0.57.1 wit-bindgen-cli +Invoke-WebRequest -UseBasicParsing -Uri https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.8.tar.gz -OutFile v0.2.8.tar.gz +tar xzf v0.2.8.tar.gz +cp world.wit wasi-http-0.2.8/wit/world.wit +wit-bindgen c-sharp -w wasi-http -r native-aot --internal wasi-http-0.2.8/wit +rm -r wasi-http-0.2.8 +rm v0.2.8.tar.gz rm WasiHttpWorld_wasm_import_linkage_attribute.cs Pop-Location diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.sh b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.sh index 037645181dc312..1a60d7970843a0 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.sh +++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.sh @@ -11,9 +11,9 @@ set -ex # [cargo](https://rustup.rs/) # [curl](https://curl.se/download.html) -cargo install --locked --no-default-features --features csharp --version 0.32.0 wit-bindgen-cli -curl -OL https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.0.tar.gz -tar xzf v0.2.0.tar.gz -cp world.wit wasi-http-0.2.0/wit/world.wit -wit-bindgen c-sharp -w wasi-http -r native-aot --internal --skip-support-files wasi-http-0.2.0/wit -rm -r wasi-http-0.2.0 v0.2.0.tar.gz WasiHttpWorld_wasm_import_linkage_attribute.cs +cargo install --locked --no-default-features --features csharp --version 0.57.1 wit-bindgen-cli +curl -OL https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.8.tar.gz +tar xzf v0.2.8.tar.gz +cp world.wit wasi-http-0.2.8/wit/world.wit +wit-bindgen c-sharp -w wasi-http -r native-aot --internal --skip-support-files wasi-http-0.2.8/wit +rm -r wasi-http-0.2.8 v0.2.8.tar.gz WasiHttpWorld_wasm_import_linkage_attribute.cs diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HPackTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HPackTest.cs index 18e502f48281d0..91c429899a3c38 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HPackTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HPackTest.cs @@ -32,6 +32,7 @@ public HPackTest(ITestOutputHelper output) : base(output) [Theory] [MemberData(nameof(HeaderEncodingTestData))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", typeof(PlatformDetection), nameof(PlatformDetection.IsWasi))] public async Task HPack_HeaderEncoding(string headerName, string expectedValue, byte[] expectedEncoding) { await Http2LoopbackServer.CreateClientAndServerAsync( diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.BasicAuth.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.BasicAuth.cs index a6ac590fb6adcf..94aab07fffe7a4 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.BasicAuth.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.BasicAuth.cs @@ -22,6 +22,7 @@ public HttpClientHandlerTest_BasicAuth(ITestOutputHelper output) : base(output) protected override Version UseVersion => HttpVersion.Version20; [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "PreAuthenticate is not supported on Wasi")] public async Task RefreshesPreAuthCredentialsOnChange() { CredentialPlugin credentialPlugin = new CredentialPlugin(); diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Connect.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Connect.cs index a153069b662fb1..77a95ff6c92b15 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Connect.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Connect.cs @@ -19,6 +19,7 @@ public HttpClientHandler_Connect_Test(ITestOutputHelper output) : base(output) { [InlineData(HttpStatusCode.Created)] [InlineData(HttpStatusCode.Accepted)] [InlineData(HttpStatusCode.NoContent)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] public async Task ConnectMethod_Success(HttpStatusCode statusCode) { await LoopbackServer.CreateServerAsync(async (server, url) => @@ -78,6 +79,7 @@ await server.AcceptConnectionAsync(async connection => } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] public async Task ConnectMethod_Fails() { await LoopbackServer.CreateServerAsync(async (server, url) => diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http1.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http1.cs index b57e3812784599..6b057a59a6b8ac 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http1.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http1.cs @@ -18,6 +18,7 @@ public HttpClientHandlerTest_Http1(ITestOutputHelper output) : base(output) { } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNodeJS))] [ActiveIssue("https://github.com/dotnet/runtime/issues/101115", typeof(PlatformDetection), nameof(PlatformDetection.IsFirefox))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", typeof(PlatformDetection), nameof(PlatformDetection.IsWasi))] public async Task SendAsync_HostHeader_First() { // RFC 7230 3.2.2. Field Order diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs index 662fd3479ce1a3..f3df45379b81a4 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs @@ -53,7 +53,7 @@ protected static HttpClientHandler CreateHttpClientHandler(Version useVersion = HttpClientHandler handler = (PlatformDetection.SupportsAlpn && useVersion != HttpVersion.Version30) ? new HttpClientHandler() : new VersionHttpClientHandler(useVersion); // Browser doesn't support ServerCertificateCustomValidationCallback - if (allowAllCertificates && PlatformDetection.IsNotBrowser) + if (allowAllCertificates && PlatformDetection.IsNotBrowser && PlatformDetection.IsNotWasi) { handler.ServerCertificateCustomValidationCallback = TestHelper.AllowAllCertificates; } diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientMiniStressTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientMiniStressTest.cs index e19c321dfd0a55..1e8ab9ed3701e3 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientMiniStressTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientMiniStressTest.cs @@ -89,6 +89,7 @@ await server.AcceptConnectionAsync(async connection => [Collection(nameof(HttpClientMiniStress))] [SkipOnPlatform(TestPlatforms.Browser, "System.Net.Security is not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "System.Net.Security is not supported on Wasi")] public abstract class HttpClientMiniStress : HttpClientHandlerTestBase { public HttpClientMiniStress(ITestOutputHelper output) : base(output) { } diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs index 949649ebf46141..ecbe5b6568cab9 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs @@ -295,6 +295,7 @@ public async Task GetContentAsync_ErrorStatusCode_ExpectedExceptionThrown(bool w [Fact] [SkipOnPlatform(TestPlatforms.Browser, "Socket is not supported on Browser")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", typeof(PlatformDetection), nameof(PlatformDetection.IsWasi))] public async Task GetContentAsync_WhenCannotConnect_ExceptionContainsHostInfo() { const string Host = "localhost:1234"; @@ -765,6 +766,7 @@ public void Dispose_UseAfterDispose_Throws() [InlineData(false)] [InlineData(true)] [SkipOnPlatform(TestPlatforms.Browser, "System.Net.Sockets is not supported on this platform")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", typeof(PlatformDetection), nameof(PlatformDetection.IsWasi))] public void CancelAllPending_AllPendingOperationsCanceled(bool withInfiniteTimeout) { using (var client = new HttpClient(new CustomResponseHandler((r, c) => WhenCanceled(c)))) @@ -783,6 +785,7 @@ public void CancelAllPending_AllPendingOperationsCanceled(bool withInfiniteTimeo [InlineData(HttpCompletionOption.ResponseContentRead)] [InlineData(HttpCompletionOption.ResponseHeadersRead)] [SkipOnPlatform(TestPlatforms.Browser, "System.Net.Sockets is not supported on this platform")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", typeof(PlatformDetection), nameof(PlatformDetection.IsWasi))] public void Timeout_TooShort_AllPendingOperationsCanceled(HttpCompletionOption completionOption) { using (var client = new HttpClient(new CustomResponseHandler((r, c) => WhenCanceled(c)))) @@ -820,6 +823,7 @@ public async Task Timeout_CallerCanceledTokenAfterTimeout_TimeoutIsNotDetected(H [InlineData(HttpCompletionOption.ResponseContentRead)] [InlineData(HttpCompletionOption.ResponseHeadersRead)] [SkipOnPlatform(TestPlatforms.Browser, "System.Net.Sockets is not supported on this platform")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", typeof(PlatformDetection), nameof(PlatformDetection.IsWasi))] public void Timeout_CallerCanceledTokenBeforeTimeout_TimeoutIsNotDetected(HttpCompletionOption completionOption) { using (var client = new HttpClient(new CustomResponseHandler((r, c) => WhenCanceled(c)))) @@ -1016,6 +1020,7 @@ public void Send_SingleThread_Succeeds(HttpCompletionOption completionOption) [InlineData(HttpCompletionOption.ResponseHeadersRead)] [SkipOnPlatform(TestPlatforms.Browser, "Synchronous Send is not supported on Browser")] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send is not supported on Android")] + [SkipOnPlatform(TestPlatforms.Wasi, "Synchronous Send is not supported on Wasi")] public async Task Send_SingleThread_Loopback_Succeeds(HttpCompletionOption completionOption) { string content = "Test content"; @@ -1071,6 +1076,7 @@ await server.AcceptConnectionAsync(async connection => [OuterLoop] [SkipOnPlatform(TestPlatforms.Browser, "Synchronous Send is not supported on Browser")] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send is not supported on Android")] + [SkipOnPlatform(TestPlatforms.Wasi, "Synchronous Send is not supported on Wasi")] public async Task Send_CancelledRequestContent_Throws() { CancellationTokenSource cts = new CancellationTokenSource(); @@ -1162,6 +1168,7 @@ await server.AcceptConnectionAsync(async connection => [OuterLoop] [SkipOnPlatform(TestPlatforms.Browser, "Synchronous Send is not supported on Browser")] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send is not supported on Android")] + [SkipOnPlatform(TestPlatforms.Wasi, "Synchronous Send is not supported on Wasi")] public async Task Send_CancelledResponseContent_Throws() { string content = "Test content"; @@ -1214,6 +1221,7 @@ await IgnoreExceptions(async () => [OuterLoop] [SkipOnPlatform(TestPlatforms.Browser, "Synchronous Send is not supported on Browser")] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send is not supported on Android")] + [SkipOnPlatform(TestPlatforms.Wasi, "Synchronous Send is not supported on Wasi")] public async Task Send_TimeoutResponseContent_Throws() { const string Content = "Test content"; @@ -1272,6 +1280,7 @@ public static IEnumerable VersionSelectionMemberData() [Theory] [MemberData(nameof(VersionSelectionMemberData))] [SkipOnPlatform(TestPlatforms.Browser, "Version is ignored on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "Version is ignored on Wasi")] public async Task SendAsync_CorrectVersionSelected_LoopbackServer(Version requestVersion, HttpVersionPolicy versionPolicy, Version serverVersion, bool useSsl, object expectedResult) { await HttpAgnosticLoopbackServer.CreateClientAndServerAsync( @@ -1322,6 +1331,7 @@ await HttpAgnosticLoopbackServer.CreateClientAndServerAsync( [OuterLoop("Uses external servers")] [MemberData(nameof(VersionSelectionMemberData))] [SkipOnPlatform(TestPlatforms.Browser, "Version is ignored on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "Version is ignored on Wasi")] public async Task SendAsync_CorrectVersionSelected_ExternalServer(Version requestVersion, HttpVersionPolicy versionPolicy, Version serverVersion, bool useSsl, object expectedResult) { RemoteServer remoteServer = null; @@ -1639,6 +1649,7 @@ public HttpResponseMessage PublicSend(HttpRequestMessage request, CancellationTo [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [SkipOnPlatform(TestPlatforms.Android, "The Send method is not implemented on mobile platforms")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", typeof(PlatformDetection), nameof(PlatformDetection.IsWasi))] public void Send_NullRequest_ThrowsException() { using var client = new CustomHttpClient(); diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpConnectionKeyTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpConnectionKeyTest.cs index 0517cc612d013a..8237726abd4c9b 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpConnectionKeyTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpConnectionKeyTest.cs @@ -24,6 +24,7 @@ public static IEnumerable KeyComponents() } [Theory, MemberData(nameof(KeyComponents))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", typeof(PlatformDetection), nameof(PlatformDetection.IsWasi))] public void Equals_DifferentParameters_ReturnsTrueIfAllEqual(string kindString, string host, int port, string sslHostName, Uri proxyUri, string identity, bool expected) { Type connectionKindType = Type.GetType("System.Net.Http.HttpConnectionKind, System.Net.Http"); diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpContentTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpContentTest.cs index 7591c95439893a..625f53a5a921ba 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpContentTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpContentTest.cs @@ -299,6 +299,7 @@ public async Task ReadAsStreamAsync_FirstGetFromUnbufferedContentThenGetFromBuff } [SkipOnPlatform(TestPlatforms.Browser, "Browser doesn't support Synchronous reads")] + [SkipOnPlatform(TestPlatforms.Wasi, "Wasi doesn't support Synchronous reads")] [Theory] [InlineData(true)] [InlineData(false)] @@ -534,6 +535,7 @@ await LoopbackServer.CreateClientAndServerAsync( } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] public async Task LoadIntoBufferAsync_Unbuffered_CanBeCanceled_AlreadyCanceledCts() { await LoopbackServer.CreateClientAndServerAsync( @@ -819,6 +821,7 @@ await LoopbackServer.CreateClientAndServerAsync( [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/86317", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] public async Task ReadAsStringAsync_Unbuffered_CanBeCanceled_AlreadyCanceledCts() { await LoopbackServer.CreateClientAndServerAsync( @@ -900,6 +903,7 @@ await LoopbackServer.CreateClientAndServerAsync( [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/86317", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] public async Task ReadAsByteArrayAsync_Unbuffered_CanBeCanceled_AlreadyCanceledCts() { await LoopbackServer.CreateClientAndServerAsync( diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs index 22c91de5ab73b8..3390856612f3cb 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs @@ -289,6 +289,7 @@ public HttpMetricsTest(ITestOutputHelper output) : base(output) } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] public Task ActiveRequests_Success_Recorded() { return LoopbackServerFactory.CreateClientAndServerAsync(async uri => @@ -346,6 +347,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri => } [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNodeJSOrFirefox))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] [InlineData("GET", HttpStatusCode.OK)] [InlineData("PUT", HttpStatusCode.Created)] public Task RequestDuration_Success_Recorded(string method, HttpStatusCode statusCode) @@ -449,6 +451,7 @@ await RemoteExecutor.Invoke(static testClass => } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] public Task RequestDuration_CustomTags_Recorded() { return LoopbackServerFactory.CreateClientAndServerAsync(async uri => @@ -475,6 +478,7 @@ public Task RequestDuration_CustomTags_Recorded() } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] public Task RequestDuration_MultipleCallbacksPerRequest_AllCalledInOrder() { return LoopbackServerFactory.CreateClientAndServerAsync(async uri => @@ -591,6 +595,7 @@ public enum ResponseContentType } [Theory] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] [InlineData(HttpCompletionOption.ResponseContentRead, ResponseContentType.Empty)] [InlineData(HttpCompletionOption.ResponseContentRead, ResponseContentType.ContentLength)] [InlineData(HttpCompletionOption.ResponseContentRead, ResponseContentType.TransferEncodingChunked)] @@ -714,6 +719,7 @@ public Task ActiveRequests_Redirect_RecordedForEachHttpSpan(int credentialsMode) [Theory] [PlatformSpecific(~TestPlatforms.Browser)] // BrowserHttpHandler supports only a limited set of methods. + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] [MemberData(nameof(MethodData))] public async Task RequestMetrics_EmitNormalizedMethodTags(string method, string expectedMethodTag) { @@ -818,6 +824,7 @@ await server.AcceptConnectionAsync(async connection => } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] public async Task RequestDuration_RequestCancelled_ErrorReasonIsExceptionType() { TaskCompletionSource clientCompleted = new(TaskCreationOptions.RunContinuationsAsynchronously); @@ -862,6 +869,7 @@ await server.AcceptConnectionAsync(async connection => } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] public async Task RequestDuration_ConnectionError_LogsExpectedErrorReason() { if (UseVersion.Major == 3) @@ -1036,6 +1044,7 @@ public HttpMetricsTest_Http11(ITestOutputHelper output) : base(output) } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNodeJSOrFirefox))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] public async Task RequestDuration_EnrichmentHandler_ContentLengthError_Recorded() { await LoopbackServerFactory.CreateClientAndServerAsync(async uri => @@ -1066,6 +1075,7 @@ await Assert.ThrowsAsync(async () => } [Theory] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] [InlineData(400)] [InlineData(404)] [InlineData(599)] @@ -1090,6 +1100,7 @@ public Task RequestDuration_ErrorStatus_ErrorTypeRecorded(int statusCode) [Fact] [SkipOnPlatform(TestPlatforms.Browser, "Browser is relaxed about validating HTTP headers")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] public async Task RequestDuration_ConnectionClosedWhileReceivingHeaders_Recorded() { using CancellationTokenSource cancelServerCts = new CancellationTokenSource(); @@ -1122,6 +1133,7 @@ await IgnoreExceptions(async () => } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] public Task DurationHistograms_HaveBucketSizeHints() { return LoopbackServerFactory.CreateClientAndServerAsync(async uri => diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/NtAuthTests.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/NtAuthTests.cs index 5c5954fb3491d2..145ab6b3a890f6 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/NtAuthTests.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/NtAuthTests.cs @@ -104,6 +104,7 @@ public void Dispose() } } + [SkipOnPlatform(TestPlatforms.Wasi, "NTLM/Negotiate test servers are not supported on WASI")] public partial class NtAuthTests : IClassFixture { private readonly NtAuthServers _servers; diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/ReadOnlyMemoryContentTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/ReadOnlyMemoryContentTest.cs index df9b4d7c08662a..975baf11567e0c 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/ReadOnlyMemoryContentTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/ReadOnlyMemoryContentTest.cs @@ -226,6 +226,7 @@ public async Task ReadAsStreamAsync_Read_InvalidArguments(bool useArray, bool re [InlineData(2, true, true)] // ReadAsync(byte[], ...) [InlineData(3, true, true)] // ReadAsync(Memory,...) [InlineData(4, true, true)] // Begin/EndRead(byte[],...) + [SkipOnPlatform(TestPlatforms.Wasi, "Synchronous and APM (Begin/EndRead) stream reads are not supported on Wasi")] public async Task ReadAsStreamAsync_ReadMultipleBytes_MatchesInput(int mode, bool useArray, bool readStreamAsync) { const int ContentLength = 1024; diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/ResponseStreamConformanceTests.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/ResponseStreamConformanceTests.cs index 37a6bac02d1a3d..ca1fc15037141f 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/ResponseStreamConformanceTests.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/ResponseStreamConformanceTests.cs @@ -9,6 +9,7 @@ namespace System.Net.Http.Functional.Tests { + [SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.Wasi, "ConnectCallback is not supported on Browser and Wasi")] public sealed class Http1CloseResponseStreamConformanceTests : ResponseConnectedStreamConformanceTests { protected override string GetResponseHeaders() => "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n"; @@ -23,6 +24,7 @@ protected override async Task CreateConnectedStreamsAsync() } + [SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.Wasi, "ConnectCallback is not supported on Browser and Wasi")] public sealed class Http1RawResponseStreamConformanceTests : ResponseConnectedStreamConformanceTests { protected override string GetResponseHeaders() => "HTTP/1.1 101 Switching Protocols\r\n\r\n"; @@ -37,6 +39,7 @@ protected override async Task CreateConnectedStreamsAsync() } + [SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.Wasi, "ConnectCallback is not supported on Browser and Wasi")] public sealed class Http1ContentLengthResponseStreamConformanceTests : ResponseStandaloneStreamConformanceTests { protected override async Task WriteResponseAsync(Stream responseStream, byte[] bodyData) @@ -46,6 +49,7 @@ protected override async Task WriteResponseAsync(Stream responseStream, byte[] b } } + [SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.Wasi, "ConnectCallback is not supported on Browser and Wasi")] public sealed class Http1SingleChunkResponseStreamConformanceTests : ResponseStandaloneStreamConformanceTests { protected override async Task WriteResponseAsync(Stream responseStream, byte[] bodyData) @@ -62,6 +66,7 @@ protected override async Task WriteResponseAsync(Stream responseStream, byte[] b } } + [SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.Wasi, "ConnectCallback is not supported on Browser and Wasi")] public sealed class Http1MultiChunkResponseStreamConformanceTests : ResponseStandaloneStreamConformanceTests { protected override async Task WriteResponseAsync(Stream responseStream, byte[] bodyData) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/ResponseStreamZeroByteReadTests.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/ResponseStreamZeroByteReadTests.cs index 1f6ad745e82e04..46367e61fa64c3 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/ResponseStreamZeroByteReadTests.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/ResponseStreamZeroByteReadTests.cs @@ -81,6 +81,7 @@ public static IEnumerable ZeroByteRead_IssuesZeroByteReadOnUnderlyingS [Theory] [MemberData(nameof(ZeroByteRead_IssuesZeroByteReadOnUnderlyingStream_MemberData))] [SkipOnPlatform(TestPlatforms.Browser, "ConnectCallback is not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "ConnectCallback is not supported on Wasi")] public async Task ZeroByteRead_IssuesZeroByteReadOnUnderlyingStream(StreamConformanceTests.ReadWriteMode readMode, bool useSsl) { (Stream httpConnection, Stream server) = ConnectedStreams.CreateBidirectional(4096, int.MaxValue); @@ -197,6 +198,7 @@ public ResponseStreamZeroByteReadTestBase(ITestOutputHelper output) : base(outpu [Theory] [InlineData(true)] [InlineData(false)] + [SkipOnPlatform(TestPlatforms.Wasi, "Synchronous Read is not supported on Wasi")] public async Task ZeroByteRead_BlocksUntilDataIsAvailable(bool async) { var zeroByteReadIssued = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs index 09c2e6d1d0679c..e07ad485919f63 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs @@ -132,6 +132,7 @@ public SocketsHttpHandler_HttpClientHandler_Asynchrony_Test_Http3(ITestOutputHel } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public abstract class SocketsHttpHandler_HttpClientHandler_Asynchrony_Test : HttpClientHandler_Asynchrony_Test { public SocketsHttpHandler_HttpClientHandler_Asynchrony_Test(ITestOutputHelper output) : base(output) { } @@ -288,6 +289,7 @@ protected sealed class SetOnFinalized } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_HttpProtocolTests : HttpProtocolTests { public SocketsHttpHandler_HttpProtocolTests(ITestOutputHelper output) : base(output) { } @@ -315,16 +317,19 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_HttpProtocolTests_Dribble : HttpProtocolTests_Dribble { public SocketsHttpHandler_HttpProtocolTests_Dribble(ITestOutputHelper output) : base(output) { } } + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_DiagnosticsTest_Http11 : DiagnosticsTest { public SocketsHttpHandler_DiagnosticsTest_Http11(ITestOutputHelper output) : base(output) { } } + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_DiagnosticsTest_Http2 : DiagnosticsTest { public SocketsHttpHandler_DiagnosticsTest_Http2(ITestOutputHelper output) : base(output) { } @@ -338,12 +343,14 @@ public SocketsHttpHandler_DiagnosticsTest_Http3(ITestOutputHelper output) : base protected override Version UseVersion => HttpVersion.Version30; } + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_HttpClient_SelectedSites_Test : HttpClient_SelectedSites_Test { public SocketsHttpHandler_HttpClient_SelectedSites_Test(ITestOutputHelper output) : base(output) { } } #if !TARGETS_BROWSER + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_HttpClientEKUTest : HttpClientEKUTest { public SocketsHttpHandler_HttpClientEKUTest(ITestOutputHelper output) : base(output) { } @@ -351,34 +358,40 @@ public SocketsHttpHandler_HttpClientEKUTest(ITestOutputHelper output) : base(out #endif [SkipOnPlatform(TestPlatforms.Browser, "AutomaticDecompression not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "AutomaticDecompression not supported on Wasi")] public sealed class SocketsHttpHandler_HttpClientHandler_Decompression_Tests : HttpClientHandler_Decompression_Test { public SocketsHttpHandler_HttpClientHandler_Decompression_Tests(ITestOutputHelper output) : base(output) { } } [SkipOnPlatform(TestPlatforms.Browser, "Certificates are not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "Certificates are not supported on Wasi")] public sealed class SocketsHttpHandler_HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test : HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test { public SocketsHttpHandler_HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test(ITestOutputHelper output) : base(output) { } } [SkipOnPlatform(TestPlatforms.Browser, "Certificates are not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "Certificates are not supported on Wasi")] public sealed class SocketsHttpHandler_HttpClientHandler_ClientCertificates_Test : HttpClientHandler_ClientCertificates_Test { public SocketsHttpHandler_HttpClientHandler_ClientCertificates_Test(ITestOutputHelper output) : base(output) { } } [SkipOnPlatform(TestPlatforms.Browser, "Proxy is not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "Proxy is not supported on Wasi")] public sealed class SocketsHttpHandler_HttpClientHandler_DefaultProxyCredentials_Test : HttpClientHandler_DefaultProxyCredentials_Test { public SocketsHttpHandler_HttpClientHandler_DefaultProxyCredentials_Test(ITestOutputHelper output) : base(output) { } } + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_HttpClientHandler_Finalization_Http11_Test : HttpClientHandler_Finalization_Test { public SocketsHttpHandler_HttpClientHandler_Finalization_Http11_Test(ITestOutputHelper output) : base(output) { } } + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_HttpClientHandler_Finalization_Http2_Test : HttpClientHandler_Finalization_Test { public SocketsHttpHandler_HttpClientHandler_Finalization_Http2_Test(ITestOutputHelper output) : base(output) { } @@ -386,6 +399,7 @@ public SocketsHttpHandler_HttpClientHandler_Finalization_Http2_Test(ITestOutputH } [SkipOnPlatform(TestPlatforms.Browser, "MaxConnectionsPerServer not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "MaxConnectionsPerServer not supported on Wasi")] public sealed class SocketsHttpHandler_HttpClientHandler_MaxConnectionsPerServer_Test : HttpClientHandler_MaxConnectionsPerServer_Test { public SocketsHttpHandler_HttpClientHandler_MaxConnectionsPerServer_Test(ITestOutputHelper output) : base(output) { } @@ -450,12 +464,14 @@ await server.AcceptConnectionAsync(async connection => } [SkipOnPlatform(TestPlatforms.Browser, "Certificates are not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "Certificates are not supported on Wasi")] public sealed class SocketsHttpHandler_HttpClientHandler_ServerCertificates_Test : HttpClientHandler_ServerCertificates_Test { public SocketsHttpHandler_HttpClientHandler_ServerCertificates_Test(ITestOutputHelper output) : base(output) { } } [SkipOnPlatform(TestPlatforms.Browser, "ResponseDrainTimeout is not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_HttpClientHandler_ResponseDrain_Test : HttpClientHandler_ResponseDrain_Test { protected override void SetResponseDrainTimeout(HttpClientHandler handler, TimeSpan time) @@ -700,6 +716,7 @@ await server.AcceptConnectionAsync(async connection => } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_PostScenarioTest : PostScenarioTest { public SocketsHttpHandler_PostScenarioTest(ITestOutputHelper output) : base(output) { } @@ -707,6 +724,7 @@ public SocketsHttpHandler_PostScenarioTest(ITestOutputHelper output) : base(outp [Theory] [InlineData(false)] [InlineData(true)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/98957", TestPlatforms.Wasi)] public async Task DisposeTargetStream_ThrowsObjectDisposedException(bool knownLength) { var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); @@ -756,18 +774,21 @@ protected override bool TryComputeLength(out long length) } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupportedOrNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_ResponseStreamTest : ResponseStreamTest { public SocketsHttpHandler_ResponseStreamTest(ITestOutputHelper output) : base(output) { } } [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_HttpClientHandler_SslProtocols_Test : HttpClientHandler_SslProtocols_Test { public SocketsHttpHandler_HttpClientHandler_SslProtocols_Test(ITestOutputHelper output) : base(output) { } } [SkipOnPlatform(TestPlatforms.Browser, "UseProxy not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_HttpClientHandler_Proxy_Test : HttpClientHandler_Proxy_Test { public SocketsHttpHandler_HttpClientHandler_Proxy_Test(ITestOutputHelper output) : base(output) { } @@ -812,6 +833,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => } } + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public abstract class SocketsHttpHandler_TrailingHeaders_Test : HttpClientHandlerTestBase { public SocketsHttpHandler_TrailingHeaders_Test(ITestOutputHelper output) : base(output) { } @@ -933,6 +955,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri => } [SkipOnPlatform(TestPlatforms.Browser, "HTTP/1 trailers are not supported by most major browsers")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_Http1_TrailingHeaders_Test : SocketsHttpHandler_TrailingHeaders_Test { public SocketsHttpHandler_Http1_TrailingHeaders_Test(ITestOutputHelper output) : base(output) { } @@ -1348,6 +1371,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri => } } + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_HttpClientHandlerTest : HttpClientHandlerTest { public SocketsHttpHandler_HttpClientHandlerTest(ITestOutputHelper output) : base(output) { } @@ -1364,12 +1388,14 @@ public async Task SendAsync_UriWithNonDnsNonAsciiHost_Throws() } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandlerTest_AutoRedirect : HttpClientHandlerTest_AutoRedirect { public SocketsHttpHandlerTest_AutoRedirect(ITestOutputHelper output) : base(output) { } } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_DefaultCredentialsTest : DefaultCredentialsTest { public SocketsHttpHandler_DefaultCredentialsTest(ITestOutputHelper output) : base(output) { } @@ -1401,24 +1427,28 @@ await LoopbackServerFactory.CreateClientAndServerAsync( } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_IdnaProtocolTests : IdnaProtocolTests { public SocketsHttpHandler_IdnaProtocolTests(ITestOutputHelper output) : base(output) { } } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandlerTest_RequestRetry : HttpClientHandlerTest_RequestRetry { public SocketsHttpHandlerTest_RequestRetry(ITestOutputHelper output) : base(output) { } } [SkipOnPlatform(TestPlatforms.Browser, "UseCookies is not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandlerTest_Cookies : HttpClientHandlerTest_Cookies { public SocketsHttpHandlerTest_Cookies(ITestOutputHelper output) : base(output) { } } [SkipOnPlatform(TestPlatforms.Browser, "UseCookies is not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandlerTest_Cookies_Http11 : HttpClientHandlerTest_Cookies_Http11 { public SocketsHttpHandlerTest_Cookies_Http11(ITestOutputHelper output) : base(output) { } @@ -1837,12 +1867,14 @@ public SocketsHttpHandler_HttpClientHandler_MaxResponseHeadersLength_Http3(ITest } [SkipOnPlatform(TestPlatforms.Browser, "Socket is not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_HttpClientHandler_Authentication_Test : HttpClientHandler_Authentication_Test { public SocketsHttpHandler_HttpClientHandler_Authentication_Test(ITestOutputHelper output) : base(output) { } } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_ConnectionUpgrade_Test : HttpClientHandlerTestBase { public SocketsHttpHandler_ConnectionUpgrade_Test(ITestOutputHelper output) : base(output) { } @@ -1963,12 +1995,14 @@ await server.AcceptConnectionAsync(async (LoopbackServer.Connection connection) } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_Connect_Test : HttpClientHandler_Connect_Test { public SocketsHttpHandler_Connect_Test(ITestOutputHelper output) : base(output) { } } [SkipOnPlatform(TestPlatforms.Browser, "Socket is not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_HttpClientHandler_ConnectionPooling_Test : HttpClientHandlerTestBase { public SocketsHttpHandler_HttpClientHandler_ConnectionPooling_Test(ITestOutputHelper output) : base(output) { } @@ -2303,6 +2337,7 @@ await proxyServer.AcceptConnectionAsync(async connection => // System.Net.Sockets is not supported on this platform [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandler_PublicAPIBehavior_Test { [Fact] @@ -2723,6 +2758,7 @@ await Assert.ThrowsAnyAsync(() => } [SkipOnPlatform(TestPlatforms.Browser, "Headers.Location are not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandlerTest_LocationHeader { private static readonly byte[] s_redirectResponseBefore = Encoding.ASCII.GetBytes( @@ -2778,6 +2814,7 @@ private static byte[] PreperateResponseWithRedirect(byte[] location) } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandlerTest_Http2 : HttpClientHandlerTest_Http2 { public SocketsHttpHandlerTest_Http2(ITestOutputHelper output) : base(output) { } @@ -3095,6 +3132,7 @@ private async Task SendResponses(Http2LoopbackConnection connection, IEnumerable } } + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public abstract class SocketsHttpHandlerTest_ConnectCallback : HttpClientHandlerTestBase { public SocketsHttpHandlerTest_ConnectCallback(ITestOutputHelper output) : base(output) { } @@ -3731,6 +3769,7 @@ public override int ReadByte() => } [SkipOnPlatform(TestPlatforms.Browser, "Socket is not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandlerTest_ConnectCallback_Http11 : SocketsHttpHandlerTest_ConnectCallback { public SocketsHttpHandlerTest_ConnectCallback_Http11(ITestOutputHelper output) : base(output) { } @@ -3813,6 +3852,7 @@ await LoopbackServer.CreateClientAndServerAsync( } } + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public abstract class SocketsHttpHandlerTest_PlaintextStreamFilter : HttpClientHandlerTestBase { public SocketsHttpHandlerTest_PlaintextStreamFilter(ITestOutputHelper output) : base(output) { } @@ -4056,6 +4096,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync( } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandlerTest_PlaintextStreamFilter_Http11 : SocketsHttpHandlerTest_PlaintextStreamFilter { public SocketsHttpHandlerTest_PlaintextStreamFilter_Http11(ITestOutputHelper output) : base(output) { } @@ -4176,6 +4217,7 @@ public SocketsHttpHandlerTest_HttpClientHandlerTest_Http2(ITestOutputHelper outp protected override Version UseVersion => HttpVersion.Version20; } + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http11 : HttpClientHandlerTest_Headers { public SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http11(ITestOutputHelper output) : base(output) { } @@ -4265,6 +4307,7 @@ public SocketsHttpHandler_HttpClientHandler_Finalization_Http3(ITestOutputHelper } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public abstract class SocketsHttpHandler_RequestValidationTest { protected abstract bool TestAsync { get; } @@ -4287,30 +4330,35 @@ public void Send_NullRequest_ThrowsArgumentNullException() } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public void Send_NullRequestUri_ThrowsInvalidOperationException() { Throws(new HttpRequestMessage()); } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public void Send_RelativeRequestUri_ThrowsInvalidOperationException() { Throws(new HttpRequestMessage(HttpMethod.Get, new Uri("/relative", UriKind.Relative))); } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public void Send_UnsupportedRequestUriScheme_ThrowsNotSupportedException() { Throws(new HttpRequestMessage(HttpMethod.Get, "foo://foo.bar")); } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public void Send_MajorVersionZero_ThrowsNotSupportedException() { Throws(new HttpRequestMessage { Version = new Version(0, 42) }); } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public void Send_TransferEncodingChunkedWithNoContent_ThrowsHttpRequestException() { var request = new HttpRequestMessage(); @@ -4321,6 +4369,7 @@ public void Send_TransferEncodingChunkedWithNoContent_ThrowsHttpRequestException } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public void Send_Http10WithTransferEncodingChunked_ThrowsNotSupportedException() { var request = new HttpRequestMessage @@ -4361,6 +4410,7 @@ public sealed class SocketsHttpHandler_RequestValidationTest_Sync : SocketsHttpH } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public abstract class SocketsHttpHandler_RequestContentLengthMismatchTest : HttpClientHandlerTestBase { public SocketsHttpHandler_RequestContentLengthMismatchTest(ITestOutputHelper output) : base(output) { } @@ -4422,6 +4472,7 @@ public SocketsHttpHandler_RequestContentLengthMismatchTest_Http3(ITestOutputHelp } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public abstract class SocketsHttpHandler_SecurityTest : HttpClientHandlerTestBase { private readonly CertificateSetup _certificateSetup; @@ -4606,6 +4657,7 @@ public SocketsHttpHandler_SocketsHttpHandler_SecurityTest_Http3(ITestOutputHelpe } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public abstract class SocketsHttpHandler_HttpRequestErrorTest : HttpClientHandlerTestBase { protected SocketsHttpHandler_HttpRequestErrorTest(ITestOutputHelper output) : base(output) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/SocksProxyTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/SocksProxyTest.cs index 3705d67b32a4d1..6c2d29d1317ece 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/SocksProxyTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/SocksProxyTest.cs @@ -119,6 +119,7 @@ public async Task TestExceptionalAsync(string scheme, string host, bool useAuth, [SkipOnPlatform(TestPlatforms.Browser, "UseProxy not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "UseProxy not supported on Wasi")] public sealed class SocksProxyTest_Http1_Async : SocksProxyTest { public SocksProxyTest_Http1_Async(ITestOutputHelper helper) : base(helper) { } @@ -126,6 +127,7 @@ public SocksProxyTest_Http1_Async(ITestOutputHelper helper) : base(helper) { } } [SkipOnPlatform(TestPlatforms.Browser, "UseProxy not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "UseProxy not supported on Wasi")] [SkipOnPlatform(TestPlatforms.Android, "The sync Send method is not supported on mobile platforms")] public sealed class SocksProxyTest_Http1_Sync : SocksProxyTest { @@ -135,6 +137,7 @@ public SocksProxyTest_Http1_Sync(ITestOutputHelper helper) : base(helper) { } } [SkipOnPlatform(TestPlatforms.Browser, "UseProxy not supported on Browser")] + [SkipOnPlatform(TestPlatforms.Wasi, "UseProxy not supported on Wasi")] public sealed class SocksProxyTest_Http2 : SocksProxyTest { public SocksProxyTest_Http2(ITestOutputHelper helper) : base(helper) { } diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/SyncHttpHandlerTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/SyncHttpHandlerTest.cs index fb0b07ec8af149..8c53a643822a1c 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/SyncHttpHandlerTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/SyncHttpHandlerTest.cs @@ -8,6 +8,7 @@ namespace System.Net.Http.Functional.Tests { [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send method is not supported on Android.")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SyncHttpHandler_HttpProtocolTests : HttpProtocolTests { public SyncHttpHandler_HttpProtocolTests(ITestOutputHelper output) : base(output) { } @@ -16,6 +17,7 @@ public SyncHttpHandler_HttpProtocolTests(ITestOutputHelper output) : base(output [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send method is not supported on Android.")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SyncHttpHandler_HttpProtocolTests_Dribble : HttpProtocolTests_Dribble { public SyncHttpHandler_HttpProtocolTests_Dribble(ITestOutputHelper output) : base(output) { } @@ -23,6 +25,7 @@ public SyncHttpHandler_HttpProtocolTests_Dribble(ITestOutputHelper output) : bas } [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send method is not supported on Android.")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SyncHttpHandler_DiagnosticsTest : DiagnosticsTest { public SyncHttpHandler_DiagnosticsTest(ITestOutputHelper output) : base(output) { } @@ -31,6 +34,7 @@ public SyncHttpHandler_DiagnosticsTest(ITestOutputHelper output) : base(output) [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupportedOrNotBrowser))] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send method is not supported on Android.")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SyncHttpHandler_PostScenarioTest : PostScenarioTest { public SyncHttpHandler_PostScenarioTest(ITestOutputHelper output) : base(output) { } @@ -39,6 +43,7 @@ public SyncHttpHandler_PostScenarioTest(ITestOutputHelper output) : base(output) [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send method is not supported on Android.")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SyncHttpHandler_HttpClientHandlerTest : HttpClientHandlerTest { public SyncHttpHandler_HttpClientHandlerTest(ITestOutputHelper output) : base(output) { } @@ -47,6 +52,7 @@ public SyncHttpHandler_HttpClientHandlerTest(ITestOutputHelper output) : base(ou [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send method is not supported on Android.")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SyncHttpHandlerTest_AutoRedirect : HttpClientHandlerTest_AutoRedirect { public SyncHttpHandlerTest_AutoRedirect(ITestOutputHelper output) : base(output) { } @@ -54,6 +60,7 @@ public SyncHttpHandlerTest_AutoRedirect(ITestOutputHelper output) : base(output) } [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send method is not supported on Android.")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SyncHttpHandler_HttpClientHandler_Decompression_Tests : HttpClientHandler_Decompression_Test { public SyncHttpHandler_HttpClientHandler_Decompression_Tests(ITestOutputHelper output) : base(output) { } @@ -62,6 +69,7 @@ public SyncHttpHandler_HttpClientHandler_Decompression_Tests(ITestOutputHelper o [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send method is not supported on Android.")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SyncHttpHandler_IdnaProtocolTests : IdnaProtocolTests { public SyncHttpHandler_IdnaProtocolTests(ITestOutputHelper output) : base(output) { } @@ -70,6 +78,7 @@ public SyncHttpHandler_IdnaProtocolTests(ITestOutputHelper output) : base(output [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send method is not supported on Android.")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SyncHttpHandlerTest_RequestRetry : HttpClientHandlerTest_RequestRetry { public SyncHttpHandlerTest_RequestRetry(ITestOutputHelper output) : base(output) { } @@ -78,6 +87,7 @@ public SyncHttpHandlerTest_RequestRetry(ITestOutputHelper output) : base(output) [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send method is not supported on Android.")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SyncHttpHandlerTest_Cookies : HttpClientHandlerTest_Cookies { public SyncHttpHandlerTest_Cookies(ITestOutputHelper output) : base(output) { } @@ -86,6 +96,7 @@ public SyncHttpHandlerTest_Cookies(ITestOutputHelper output) : base(output) { } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send method is not supported on Android.")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SyncHttpHandlerTest_Cookies_Http11 : HttpClientHandlerTest_Cookies_Http11 { public SyncHttpHandlerTest_Cookies_Http11(ITestOutputHelper output) : base(output) { } @@ -94,6 +105,7 @@ public SyncHttpHandlerTest_Cookies_Http11(ITestOutputHelper output) : base(outpu [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send method is not supported on Android.")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SyncHttpHandler_HttpClientHandler_Cancellation_Test : SocketsHttpHandler_Cancellation_Test { public SyncHttpHandler_HttpClientHandler_Cancellation_Test(ITestOutputHelper output) : base(output) { } @@ -102,6 +114,7 @@ public SyncHttpHandler_HttpClientHandler_Cancellation_Test(ITestOutputHelper out [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send method is not supported on Android.")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SyncHttpHandler_HttpClientHandler_Authentication_Test : HttpClientHandler_Authentication_Test { public SyncHttpHandler_HttpClientHandler_Authentication_Test(ITestOutputHelper output) : base(output) { } @@ -110,6 +123,7 @@ public SyncHttpHandler_HttpClientHandler_Authentication_Test(ITestOutputHelper o [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send method is not supported on Android.")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SyncHttpHandler_Connect_Test : HttpClientHandler_Connect_Test { public SyncHttpHandler_Connect_Test(ITestOutputHelper output) : base(output) { } @@ -118,6 +132,7 @@ public SyncHttpHandler_Connect_Test(ITestOutputHelper output) : base(output) { } [SkipOnPlatform(TestPlatforms.Browser, "System.Net.Sockets is not supported on this platform.")] [SkipOnPlatform(TestPlatforms.Android, "Synchronous Send method is not supported on Android.")] + [SkipOnPlatform(TestPlatforms.Wasi, "SocketsHttpHandler is not supported on WASI")] public sealed class SyncHttpHandlerTest_HttpClientHandlerTest_Headers : HttpClientHandlerTest_Headers { public SyncHttpHandlerTest_HttpClientHandlerTest_Headers(ITestOutputHelper output) : base(output) { } diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEngine.Wasi.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEngine.Wasi.cs index 0a39feb2699364..768d658146ee93 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEngine.Wasi.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEngine.Wasi.cs @@ -24,7 +24,8 @@ public static bool TryRegisterSocket(IntPtr socketHandle, SocketAsyncContext con engine = s_engine; nint entryPtr = default; - error = Interop.Sys.GetWasiSocketDescriptor(socketHandle, &entryPtr); + int socketType = 0; + error = Interop.Sys.GetWasiSocketDescriptor(socketHandle, &entryPtr, &socketType); if (error != Interop.Error.SUCCESS) { return false; @@ -55,28 +56,31 @@ public static IList BeforePollHook(object? state) // fail fast if the handle is not found in the descriptor table // probably because the socket was closed and the entry was removed, without unregistering the poll hook nint entryPtr = default; + int socketType = 0; IntPtr socketHandle = context._socket.DangerousGetHandle(); - var error = Interop.Sys.GetWasiSocketDescriptor(socketHandle, &entryPtr); + var error = Interop.Sys.GetWasiSocketDescriptor(socketHandle, &entryPtr, &socketType); if (error != Interop.Error.SUCCESS) { Environment.FailFast("Can't resolve libc descriptor for socket handle " + socketHandle); } - var entry = (descriptor_table_entry_t*)entryPtr; - switch (entry->tag) + // wasi-libc no longer exposes a tagged union for descriptor entries; entryPtr points + // directly at the socket struct and socketType (1 = TCP/stream, 2 = UDP/datagram) + // is derived natively via SO_TYPE. + switch (socketType) { - case descriptor_table_entry_tag.DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: + case 1: { - tcp_socket_t* socket = &(entry->entry.tcp_socket); + tcp_socket_t* socket = (tcp_socket_t*)entryPtr; switch (socket->state.tag) { case tcp_socket_state_tag.TCP_SOCKET_STATE_CONNECTING: case tcp_socket_state_tag.TCP_SOCKET_STATE_LISTENING: - pollableHandles.Add(socket->socket_pollable.handle); + pollableHandles.Add(EnsurePollable(SubscribeKindTcpSocket, socket->socket.handle, ref socket->socket_pollable.handle)); break; case tcp_socket_state_tag.TCP_SOCKET_STATE_CONNECTED: - pollableHandles.Add(socket->state.state.connected.input_pollable.handle); - pollableHandles.Add(socket->state.state.connected.output_pollable.handle); + pollableHandles.Add(EnsurePollable(SubscribeKindInputStream, socket->state.state.connected.input.handle, ref socket->state.state.connected.input_pollable.handle)); + pollableHandles.Add(EnsurePollable(SubscribeKindOutputStream, socket->state.state.connected.output.handle, ref socket->state.state.connected.output_pollable.handle)); break; case tcp_socket_state_tag.TCP_SOCKET_STATE_CONNECT_FAILED: context.HandleEventsInline(Sys.SocketEvents.Error); @@ -89,9 +93,9 @@ public static IList BeforePollHook(object? state) } break; } - case descriptor_table_entry_tag.DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: + case 2: { - udp_socket_t* socket = &(entry->entry.udp_socket); + udp_socket_t* socket = (udp_socket_t*)entryPtr; switch (socket->state.tag) { case udp_socket_state_tag.UDP_SOCKET_STATE_UNBOUND: @@ -111,8 +115,8 @@ public static IList BeforePollHook(object? state) { streams = &(socket->state.state.connected.streams); } - pollableHandles.Add(streams->incoming_pollable.handle); - pollableHandles.Add(streams->outgoing_pollable.handle); + pollableHandles.Add(EnsurePollable(SubscribeKindIncomingDatagramStream, streams->incoming.handle, ref streams->incoming_pollable.handle)); + pollableHandles.Add(EnsurePollable(SubscribeKindOutgoingDatagramStream, streams->outgoing.handle, ref streams->outgoing_pollable.handle)); break; } @@ -122,11 +126,36 @@ public static IList BeforePollHook(object? state) break; } default: - throw new NotImplementedException("TYPE" + entry->tag); + throw new NotImplementedException("TYPE" + socketType); } return pollableHandles; } + // Kinds understood by SystemNative_WasiSubscribeSocketPollable. + private const int SubscribeKindInputStream = 0; + private const int SubscribeKindOutputStream = 1; + private const int SubscribeKindTcpSocket = 2; + private const int SubscribeKindIncomingDatagramStream = 4; + private const int SubscribeKindOutgoingDatagramStream = 5; + + // In the new wasi-libc, the pollables embedded in the socket state are created lazily: + // their handle stays 0 until the matching `subscribe` import is called. Subscribe on demand + // and store the handle back into the socket state so wasi-libc owns and later drops it. + private static int EnsurePollable(int kind, int streamOrSocketHandle, ref int pollableHandle) + { + if (pollableHandle == 0) + { + pollableHandle = Interop.Sys.WasiSubscribeSocketPollable(kind, streamOrSocketHandle); + } + // A 0 handle is not a valid pollable. Adding it to the poll set would corrupt the + // WASI poll loop, so fail fast instead of silently registering an invalid handle. + if (pollableHandle == 0) + { + Environment.FailFast("Failed to subscribe WASI pollable for kind " + kind + " and handle " + streamOrSocketHandle); + } + return pollableHandle; + } + public static void HandleSocketEvent(object? state) { SocketAsyncContext ctx = (SocketAsyncContext)state!; diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Wasi.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Wasi.cs index 3fd6dee783e01c..ae0a203c2a8ffa 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Wasi.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Wasi.cs @@ -95,7 +95,7 @@ internal struct tcp_socket_state_connected_t [StructLayout(LayoutKind.Sequential)] internal struct tcp_socket_state_connect_failed_t { - public byte error_code; + public int error_code; } internal enum tcp_socket_state_tag @@ -126,16 +126,21 @@ internal struct tcp_socket_state_t public tcp_socket_state_union state; } + // Layout mirrors wasi-libc (WASIp2) tcp_socket_t from + // https://github.com/WebAssembly/wasi-libc/blob/161b3195fc25/libc-bottom-half/headers/private/wasi/tcp.h + // Only `socket`, `state` and `socket_pollable` are read; trailing fields are modelled for completeness. [StructLayout(LayoutKind.Sequential)] internal struct tcp_socket_t { public tcp_own_tcp_socket_t socket; + public tcp_socket_state_t state; public poll_own_pollable_t socket_pollable; - public bool blocking; - public bool fake_nodelay; - public bool fake_reuseaddr; + public byte blocking; + public byte fake_nodelay; + public byte fake_reuseaddr; public byte family; - public tcp_socket_state_t state; + public ulong send_timeout; + public ulong recv_timeout; } [StructLayout(LayoutKind.Sequential)] @@ -195,33 +200,15 @@ internal struct udp_socket_state_t public udp_socket_state_union state; } + // Layout mirrors wasi-libc (WASIp2) udp_socket_t from + // https://github.com/WebAssembly/wasi-libc/blob/161b3195fc25/libc-bottom-half/sources/udp.c [StructLayout(LayoutKind.Sequential)] internal struct udp_socket_t { public udp_own_udp_socket_t socket; public poll_own_pollable_t socket_pollable; - public bool blocking; + public byte blocking; public byte family; public udp_socket_state_t state; } - - internal enum descriptor_table_entry_tag - { - DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET, - DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET, - } - - [StructLayout(LayoutKind.Explicit)] - internal struct descriptor_table_entry_union - { - [FieldOffset(0)] public tcp_socket_t tcp_socket; - [FieldOffset(0)] public udp_socket_t udp_socket; - } - - [StructLayout(LayoutKind.Sequential)] - internal struct descriptor_table_entry_t - { - public descriptor_table_entry_tag tag; - public descriptor_table_entry_union entry; - } } diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs index b0a1f7867e5342..0911b50892862d 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs @@ -710,6 +710,7 @@ public unsafe void Ctor_SafeHandle_SocketPair_Success() [InlineData(true)] [InlineData(false)] [PlatformSpecific(TestPlatforms.AnyUnix)] // Windows has no API to query the blocking state of a socket and assumes true. + [SkipOnPlatform(TestPlatforms.Wasi, "Wasi doesn't support Socket.Blocking")] public void Ctor_SafeHandle_BlockingMatchesHandle(bool blocking) { using var orig = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketAsyncEventArgsTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketAsyncEventArgsTest.cs index bb65f2f33934b1..2cdd654581e692 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketAsyncEventArgsTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketAsyncEventArgsTest.cs @@ -1092,6 +1092,7 @@ public async Task SendTo_DifferentEP_Success(bool ipv4) [ConditionalFact(typeof(DualModeBase), nameof(DualModeBase.LocalhostIsBothIPv4AndIPv6))] [ActiveIssue("https://github.com/dotnet/runtime/issues/124079", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] + [SkipOnPlatform(TestPlatforms.Wasi, "Wasi doesn't support DualMode")] public void Connect_Parallel_Success() { using PortBlocker portBlocker = new PortBlocker(() => @@ -1125,6 +1126,7 @@ public void Connect_Parallel_Success() [ConditionalFact(typeof(DualModeBase), nameof(DualModeBase.LocalhostIsBothIPv4AndIPv6))] [ActiveIssue("https://github.com/dotnet/runtime/issues/124079", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] + [SkipOnPlatform(TestPlatforms.Wasi, "Wasi doesn't support DualMode")] public void Connect_Parallel_Fails() { using PortBlocker portBlocker = new PortBlocker(() => @@ -1161,6 +1163,7 @@ public void Connect_Parallel_Fails() [InlineData(false)] [ActiveIssue("https://github.com/dotnet/runtime/issues/124079", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] [ActiveIssue("https://github.com/dotnet/runtime/issues/127986", TestPlatforms.Android)] + [SkipOnPlatform(TestPlatforms.Wasi, "Wasi doesn't support DualMode")] public void Connect_Parallel_FailsOver(bool preferIPv6) { using PortBlocker portBlocker = new PortBlocker(() => diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 7e9355d26d52a0..8e32c60707ae49 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -2994,8 +2994,9 @@ - - - + + + + diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/TimerQueue.Wasi.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/TimerQueue.Wasi.cs index 1517d9b11d45ea..cf5018ca91a9af 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/TimerQueue.Wasi.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/TimerQueue.Wasi.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Threading.Tasks; -using WasiPollWorld.wit.imports.wasi.clocks.v0_2_0; +using MonotonicClockInterop = WasiPollWorld.wit.Imports.wasi.clocks.v0_2_8.IMonotonicClockImports; namespace System.Threading { diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiEventLoop.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiEventLoop.cs index 483a34b91a6503..a1bed7a722a121 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiEventLoop.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiEventLoop.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Threading.Tasks; -using WasiPollWorld.wit.imports.wasi.io.v0_2_0; -using Pollable = WasiPollWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable; -using MonotonicClockInterop = WasiPollWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop; +using WasiPollWorld.wit.Imports.wasi.io.v0_2_8; +using Pollable = WasiPollWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable; +using MonotonicClockInterop = WasiPollWorld.wit.Imports.wasi.clocks.v0_2_8.IMonotonicClockImports; namespace System.Threading { @@ -153,7 +153,7 @@ internal static void CheckPollables(object? _) // this could block, this is blocking WASI API call // FIXME: this will also block soft-debugger ability to pause the execution. Solutions: A) upgrade to WASIp3 B) register debugger connection's pollable - var readyIndexes = PollInterop.Poll(pending); + var readyIndexes = IPollImports.Poll(pending); var holdersCount = holders.Count; for (int i = 0; i < readyIndexes.Length; i++) diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPoll.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPoll.cs index 888adcfe3a3fb5..eb78abdd9ef53c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPoll.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPoll.cs @@ -1,24 +1,22 @@ -// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! // #nullable enable + using System; -using System.Runtime.CompilerServices; -using System.Collections; using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; +using System.Collections.Concurrent; +using System.Threading; +using System.Threading.Tasks; namespace WasiPollWorld { - internal interface IWasiPollWorld { + internal interface IWasiPollWorldImports{ } internal readonly struct None {} - [StructLayout(LayoutKind.Sequential)] - internal readonly struct Result + [global::System.Runtime.InteropServices.StructLayoutAttribute(global::System.Runtime.InteropServices.LayoutKind.Sequential)] + internal readonly struct Result { internal readonly byte Tag; private readonly object value; @@ -29,49 +27,63 @@ private Result(byte tag, object value) this.value = value; } - internal static Result ok(Ok ok) + internal static Result Ok(TOk ok) { - return new Result(OK, ok!); + return new Result(Tags.Ok, ok!); } - internal static Result err(Err err) + internal static Result Err(TErr err) { - return new Result(ERR, err!); + return new Result(Tags.Err, err!); } - internal bool IsOk => Tag == OK; - internal bool IsErr => Tag == ERR; + internal bool IsOk => Tag == Tags.Ok; + internal bool IsErr => Tag == Tags.Err; - internal Ok AsOk + internal TOk AsOk { get { - if (Tag == OK) - return (Ok)value; - else - throw new ArgumentException("expected OK, got " + Tag); + if (Tag == Tags.Ok) + { + return (TOk)value; + } + + throw new global::System.ArgumentException("expected k, got " + Tag); } } - internal Err AsErr + internal TErr AsErr { get { - if (Tag == ERR) - return (Err)value; - else - throw new ArgumentException("expected ERR, got " + Tag); + if (Tag == Tags.Err) + { + return (TErr)value; + } + + throw new global::System.ArgumentException("expected Err, got " + Tag); } } - internal const byte OK = 0; - internal const byte ERR = 1; + internal class Tags + { + internal const byte Ok = 0; + internal const byte Err = 1; + } } - namespace exports { - internal static class WasiPollWorld + internal static class MemoryHelper + { + internal static unsafe void* AlignStackPtr(void* stackAddress, uint alignment) { + return (void*)(((nint)stackAddress) + ((int)alignment - 1) & -(int)alignment); } } + namespace Imports { + internal partial class WasiPollWorldImportsInterop : IWasiPollWorldImports + {} + } + } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.clocks.v0_2_8.IMonotonicClockImports.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.clocks.v0_2_8.IMonotonicClockImports.cs new file mode 100644 index 00000000000000..86c502b2f01f29 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.clocks.v0_2_8.IMonotonicClockImports.cs @@ -0,0 +1,39 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +namespace WasiPollWorld.wit.Imports.wasi.clocks.v0_2_8; + +internal interface IMonotonicClockImports { + + internal static unsafe ulong Now() + { + var result = MonotonicClockImportsInterop.NowWasmInterop.wasmImportNow(); + return unchecked((ulong)(result)); + + } + + internal static unsafe ulong Resolution() + { + var result = MonotonicClockImportsInterop.ResolutionWasmInterop.wasmImportResolution(); + return unchecked((ulong)(result)); + + } + + internal static unsafe global::WasiPollWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable SubscribeInstant(ulong when) + { + var result = MonotonicClockImportsInterop.SubscribeInstantWasmInterop.wasmImportSubscribeInstant(unchecked((long)(when))); + var resource = new global::WasiPollWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable(new global::WasiPollWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable.THandle(result)); + return resource; + + } + + internal static unsafe global::WasiPollWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable SubscribeDuration(ulong when) + { + var result = MonotonicClockImportsInterop.SubscribeDurationWasmInterop.wasmImportSubscribeDuration(unchecked((long)(when))); + var resource = new global::WasiPollWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable(new global::WasiPollWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable.THandle(result)); + return resource; + + } + +} diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.clocks.v0_2_8.MonotonicClockImportsInterop.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.clocks.v0_2_8.MonotonicClockImportsInterop.cs new file mode 100644 index 00000000000000..ad43a9bbcb3b01 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.clocks.v0_2_8.MonotonicClockImportsInterop.cs @@ -0,0 +1,36 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +using System; + +namespace WasiPollWorld.wit.Imports.wasi.clocks.v0_2_8 +{ + internal static class MonotonicClockImportsInterop { + + public static class NowWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:clocks/monotonic-clock@0.2.8", EntryPoint = "now"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern long wasmImportNow(); + } + + public static class ResolutionWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:clocks/monotonic-clock@0.2.8", EntryPoint = "resolution"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern long wasmImportResolution(); + } + + public static class SubscribeInstantWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:clocks/monotonic-clock@0.2.8", EntryPoint = "subscribe-instant"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSubscribeInstant(long p0); + } + + public static class SubscribeDurationWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:clocks/monotonic-clock@0.2.8", EntryPoint = "subscribe-duration"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportSubscribeDuration(long p0); + } + + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.cs new file mode 100644 index 00000000000000..75402c2ecca50e --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.cs @@ -0,0 +1,96 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +namespace WasiPollWorld.wit.Imports.wasi.io.v0_2_8; + +internal interface IPollImports { + + /** + * `pollable` represents a single I/O event which may be ready, or not. + */ + + internal class Pollable: global::System.IDisposable { + internal int Handle { get; set; } + + internal readonly record struct THandle(int Handle); + + internal Pollable(THandle handle) { + Handle = handle.Handle; + } + + public void Dispose() { + Dispose(true); + } + + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/poll@0.2.8", EntryPoint = "[resource-drop]pollable"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + private static extern void wasmImportResourceDrop(int p0); + + protected virtual void Dispose(bool disposing) { + if (disposing && Handle != 0) { + wasmImportResourceDrop(Handle); + Handle = 0; + } + } + + internal unsafe bool Ready() + { + var handle = this.Handle; + var result = PollImportsInterop.Pollable.ReadyWasmInterop.wasmImportReady(handle); + return (result != 0); + + } + + internal unsafe void Block() + { + var handle = this.Handle; + PollImportsInterop.Pollable.BlockWasmInterop.wasmImportBlock(handle); + + } + + } + + internal static unsafe uint[] Poll(global::System.Collections.Generic.List @in) + { + var cleanups = new global::System.Collections.Generic.List(); + + void* address; + if ((4 * @in.Count) < 1024) { + var retArea = stackalloc uint[1 * @in.Count + 1]; + address = MemoryHelper.AlignStackPtr(retArea, 4); + } + else + { + var bufferSize = 4 * (nuint)@in.Count; + address = global::System.Runtime.InteropServices.NativeMemory.AlignedAlloc(bufferSize, 4); + cleanups.Add(() => global::System.Runtime.InteropServices.NativeMemory.AlignedFree(address)); + } + + for (int index = 0; index < @in.Count; ++index) { + global::WasiPollWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.Pollable element = @in[index]; + int basePtr = (int)address + (index * 4); + var handle = element.Handle; + new global::System.Span((void*)((byte*)basePtr + 0), 1)[0] = handle; + + } + + var retArea0 = stackalloc uint[3]; + var ptr = (nint)MemoryHelper.AlignStackPtr(retArea0, 4); + PollImportsInterop.PollWasmInterop.wasmImportPoll((int)address, @in.Count, ptr); + + var array = new uint[new global::System.Span((void*)((byte*)ptr + 4), 1)[0]]; + new global::System.Span((void*)(new global::System.Span((void*)((byte*)ptr + 0), 1)[0]), new global::System.Span((void*)((byte*)ptr + 4), 1)[0]).CopyTo(new global::System.Span(array)); + + if (new global::System.Span((void*)((byte*)ptr + 4), 1)[0] > 0) { + global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span((void*)((byte*)ptr + 0), 1)[0]); + } + + foreach (var cleanup in cleanups) + { + cleanup(); + } + return array; + + } + +} diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.io.v0_2_8.PollImportsInterop.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.io.v0_2_8.PollImportsInterop.cs new file mode 100644 index 00000000000000..26072dd6ddc84a --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.io.v0_2_8.PollImportsInterop.cs @@ -0,0 +1,35 @@ +// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT! +// +#nullable enable + +using System; + +namespace WasiPollWorld.wit.Imports.wasi.io.v0_2_8 +{ + internal static class PollImportsInterop { + + internal static class Pollable + { + + public static class ReadyWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/poll@0.2.8", EntryPoint = "[method]pollable.ready"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern int wasmImportReady(int p0); + } + + public static class BlockWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/poll@0.2.8", EntryPoint = "[method]pollable.block"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportBlock(int p0); + } + + } + + public static class PollWasmInterop + { + [global::System.Runtime.InteropServices.DllImportAttribute("wasi:io/poll@0.2.8", EntryPoint = "poll"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute] + public static extern void wasmImportPoll(nint p0, int p1, nint p2); + } + + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop.cs deleted file mode 100644 index e08ae5bc6d61f5..00000000000000 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop.cs +++ /dev/null @@ -1,81 +0,0 @@ -// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT! -// -#nullable enable - -using System; -using System.Runtime.CompilerServices; -using System.Collections; -using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace WasiPollWorld.wit.imports.wasi.clocks.v0_2_0 -{ - internal static class MonotonicClockInterop { - - internal static class NowWasmInterop - { - [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "now"), WasmImportLinkage] - internal static extern long wasmImportNow(); - - } - - internal static unsafe ulong Now() - { - var result = NowWasmInterop.wasmImportNow(); - return unchecked((ulong)(result)); - - //TODO: free alloc handle (interopString) if exists - } - - internal static class ResolutionWasmInterop - { - [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "resolution"), WasmImportLinkage] - internal static extern long wasmImportResolution(); - - } - - internal static unsafe ulong Resolution() - { - var result = ResolutionWasmInterop.wasmImportResolution(); - return unchecked((ulong)(result)); - - //TODO: free alloc handle (interopString) if exists - } - - internal static class SubscribeInstantWasmInterop - { - [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "subscribe-instant"), WasmImportLinkage] - internal static extern int wasmImportSubscribeInstant(long p0); - - } - - internal static unsafe global::WasiPollWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable SubscribeInstant(ulong when) - { - var result = SubscribeInstantWasmInterop.wasmImportSubscribeInstant(unchecked((long)(when))); - var resource = new global::WasiPollWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::WasiPollWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result)); - return resource; - - //TODO: free alloc handle (interopString) if exists - } - - internal static class SubscribeDurationWasmInterop - { - [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "subscribe-duration"), WasmImportLinkage] - internal static extern int wasmImportSubscribeDuration(long p0); - - } - - internal static unsafe global::WasiPollWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable SubscribeDuration(ulong when) - { - var result = SubscribeDurationWasmInterop.wasmImportSubscribeDuration(unchecked((long)(when))); - var resource = new global::WasiPollWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::WasiPollWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result)); - return resource; - - //TODO: free alloc handle (interopString) if exists - } - - } -} diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_0.IPoll.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_0.IPoll.cs deleted file mode 100644 index 689c515e0b57f5..00000000000000 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_0.IPoll.cs +++ /dev/null @@ -1,78 +0,0 @@ -// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT! -// -#nullable enable - -using System; -using System.Runtime.CompilerServices; -using System.Collections; -using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace WasiPollWorld.wit.imports.wasi.io.v0_2_0; - -internal interface IPoll { - - /** - * `pollable` represents a single I/O event which may be ready, or not. - */ - - internal class Pollable: IDisposable { - internal int Handle { get; set; } - - internal readonly record struct THandle(int Handle); - - internal 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); - - } - - internal unsafe bool Ready() - { - var handle = this.Handle; - var result = ReadyWasmInterop.wasmImportReady(handle); - return (result != 0); - - //TODO: free alloc handle (interopString) if exists - } - - internal static class BlockWasmInterop - { - [DllImport("wasi:io/poll@0.2.0", EntryPoint = "[method]pollable.block"), WasmImportLinkage] - internal static extern void wasmImportBlock(int p0); - - } - - internal unsafe void Block() - { - var handle = this.Handle; - BlockWasmInterop.wasmImportBlock(handle); - - //TODO: free alloc handle (interopString) if exists - } - - } - -} diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_0.PollInterop.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_0.PollInterop.cs deleted file mode 100644 index 796018f6fbcef2..00000000000000 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_0.PollInterop.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT! -// -#nullable enable - -using System; -using System.Runtime.CompilerServices; -using System.Collections; -using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace WasiPollWorld.wit.imports.wasi.io.v0_2_0 -{ - internal 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); - - } - - internal static unsafe uint[] Poll(List @in) - { - - byte[] buffer = new byte[4 * @in.Count]; - var gcHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - var address = gcHandle.AddrOfPinnedObject(); - - for (int index = 0; index < @in.Count; ++index) { - global::WasiPollWorld.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), unchecked((int)handle)); - - } - - var retArea = new uint[2]; - fixed (uint* retAreaByte0 = &retArea[0]) - { - var ptr = (nint)retAreaByte0; - 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)); - gcHandle.Free(); - return array; - } - - //TODO: free alloc handle (interopString) if exists - } - - } -} diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.ps1 b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.ps1 index b3b5adf9933b2f..989e3c61b48016 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.ps1 +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.ps1 @@ -10,12 +10,12 @@ $dir = Split-Path $scriptpath Push-Location $dir -cargo install --locked --no-default-features --features csharp --version 0.32.0 wit-bindgen-cli -Invoke-WebRequest -UseBasicParsing -Uri https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.0.tar.gz -OutFile v0.2.0.tar.gz -tar xzf v0.2.0.tar.gz -cp world.wit wasi-http-0.2.0/wit/world.wit -wit-bindgen c-sharp -w wasi-poll -r native-aot --internal --skip-support-files wasi-http-0.2.0/wit -rm -r wasi-http-0.2.0 -rm v0.2.0.tar.gz +cargo install --locked --no-default-features --features csharp --version 0.57.1 wit-bindgen-cli +Invoke-WebRequest -UseBasicParsing -Uri https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.8.tar.gz -OutFile v0.2.8.tar.gz +tar xzf v0.2.8.tar.gz +cp world.wit wasi-http-0.2.8/wit/world.wit +wit-bindgen c-sharp -w wasi-poll -r native-aot --internal --skip-support-files wasi-http-0.2.8/wit +rm -r wasi-http-0.2.8 +rm v0.2.8.tar.gz Pop-Location diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.sh b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.sh index 70da6f369110dc..54f5db15f513c3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.sh +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.sh @@ -11,9 +11,9 @@ set -ex # [cargo](https://rustup.rs/) # [curl](https://curl.se/download.html) -cargo install --locked --no-default-features --features csharp --version 0.32.0 wit-bindgen-cli -curl -OL https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.0.tar.gz -tar xzf v0.2.0.tar.gz -cp world.wit wasi-http-0.2.0/wit/world.wit -wit-bindgen c-sharp -w wasi-poll -r native-aot --internal --skip-support-files wasi-http-0.2.0/wit -rm -r wasi-http-0.2.0 v0.2.0.tar.gz +cargo install --locked --no-default-features --features csharp --version 0.57.1 wit-bindgen-cli +curl -OL https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.8.tar.gz +tar xzf v0.2.8.tar.gz +cp world.wit wasi-http-0.2.8/wit/world.wit +wit-bindgen c-sharp -w wasi-poll -r native-aot --internal --skip-support-files wasi-http-0.2.8/wit +rm -r wasi-http-0.2.8 v0.2.8.tar.gz diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/world.wit b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/world.wit index 2dfe1c6f5cd47f..d8769d8438ebb9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/world.wit +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/world.wit @@ -1,4 +1,4 @@ world wasi-poll { - import wasi:io/poll@0.2.0; - import wasi:clocks/monotonic-clock@0.2.0; + import wasi:io/poll@0.2.8; + import wasi:clocks/monotonic-clock@0.2.8; } diff --git a/src/mono/mono/mini/interp/interp-nosimd.c b/src/mono/mono/mini/interp/interp-nosimd.c index 63bcf2783ec087..215864eaac4976 100644 --- a/src/mono/mono/mini/interp/interp-nosimd.c +++ b/src/mono/mono/mini/interp/interp-nosimd.c @@ -6,7 +6,7 @@ gboolean interp_simd_enabled = FALSE; -#ifdef HOST_BROWSER +#if HOST_BROWSER || HOST_WASI int interp_simd_p_p_wasm_opcode_table [] = { }; @@ -17,7 +17,7 @@ int interp_simd_p_pp_wasm_opcode_table [] = { int interp_simd_p_ppp_wasm_opcode_table [] = { }; -#endif // HOST_BROWSER +#endif // HOST_BROWSER || HOST_WASI PP_SIMD_Method interp_simd_p_p_table [] = { }; diff --git a/src/mono/mono/mini/interp/interp-simd-intrins.def b/src/mono/mono/mini/interp/interp-simd-intrins.def index 82aa7f3ea1a0dc..4fefb8e395445b 100644 --- a/src/mono/mono/mini/interp/interp-simd-intrins.def +++ b/src/mono/mono/mini/interp/interp-simd-intrins.def @@ -1,5 +1,4 @@ -// FIXME: SIMD causes compile errors on WASI -#ifdef HOST_BROWSER +#if defined(HOST_BROWSER) || defined(HOST_WASI) #ifndef INTERP_WASM_SIMD_INTRINSIC_V_P #define INTERP_WASM_SIMD_INTRINSIC_V_P(name, arg1, c_intrinsic, wasm_opcode) INTERP_SIMD_INTRINSIC_P_P(INTERP_SIMD_INTRINSIC_ ## name ## arg1, _mono_interp_simd_ ## c_intrinsic, wasm_opcode) #endif @@ -27,7 +26,7 @@ #ifndef INTERP_WASM_SIMD_INTRINSIC_V_C3 #define INTERP_WASM_SIMD_INTRINSIC_V_C3(name, arg1, c_function, wasm_opcode) INTERP_SIMD_INTRINSIC_P_PPP(INTERP_SIMD_INTRINSIC_ ## name ## arg1, c_function, wasm_opcode) #endif -#else // HOST_BROWSER +#else // defined(HOST_BROWSER) || defined(HOST_WASI) #define INTERP_WASM_SIMD_INTRINSIC_V_P(name, arg1, c_intrinsic, wasm_opcode) #define INTERP_WASM_SIMD_INTRINSIC_V_V(name, arg1, c_intrinsic, wasm_opcode) #define INTERP_WASM_SIMD_INTRINSIC_V_C1(name, arg1, c_function, wasm_opcode) @@ -37,7 +36,7 @@ #define INTERP_WASM_SIMD_INTRINSIC_V_C2(name, arg1, c_function, wasm_opcode) #define INTERP_WASM_SIMD_INTRINSIC_V_VVV(name, arg1, c_intrinsic, wasm_opcode) #define INTERP_WASM_SIMD_INTRINSIC_V_C3(name, arg1, c_function, wasm_opcode) -#endif // HOST_BROWSER +#endif // defined(HOST_BROWSER) || defined(HOST_WASI) // The third argument is the wasm opcode that corresponds to this simd intrinsic, if any. // Specify -1 if there is no exact 1:1 mapping (the opcode can still be implemented manually in the jiterpreter.) diff --git a/src/mono/mono/mini/interp/interp-simd.c b/src/mono/mono/mini/interp/interp-simd.c index cdc6a951c5f92a..b779813fa745d3 100644 --- a/src/mono/mono/mini/interp/interp-simd.c +++ b/src/mono/mono/mini/interp/interp-simd.c @@ -2,7 +2,7 @@ #include "interp-internals.h" #include "interp-simd.h" -#if HOST_BROWSER +#if HOST_BROWSER || HOST_WASI #include #endif @@ -611,6 +611,12 @@ interp_v128_i8_shuffle (gpointer res, gpointer v1, gpointer v2) // https://github.com/llvm/llvm-project/blob/main/clang/lib/Headers/wasm_simd128.h // In this context V means Vector128 and P means void* pointer. #ifdef HOST_BROWSER +#define HOST_WASM_SIMD 1 +#elif defined(HOST_WASI) +#define HOST_WASM_SIMD 1 +#endif + +#if HOST_WASM_SIMD static v128_t _interp_wasm_simd_assert_not_reached (v128_t lhs, v128_t rhs) { @@ -931,7 +937,7 @@ int interp_simd_p_ppp_wasm_opcode_table [] = { #undef INTERP_SIMD_INTRINSIC_P_PPP #define INTERP_SIMD_INTRINSIC_P_PPP(a,b,c) -#endif // HOST_BROWSER +#endif // HOST_WASM_SIMD #undef INTERP_SIMD_INTRINSIC_P_P #define INTERP_SIMD_INTRINSIC_P_P(a,b,c) b, diff --git a/src/mono/mono/mini/interp/interp-simd.h b/src/mono/mono/mini/interp/interp-simd.h index 8e0222613e44a2..92bf8b849aee09 100644 --- a/src/mono/mono/mini/interp/interp-simd.h +++ b/src/mono/mono/mini/interp/interp-simd.h @@ -13,7 +13,7 @@ extern PP_SIMD_Method interp_simd_p_p_table []; extern PPP_SIMD_Method interp_simd_p_pp_table []; extern PPPP_SIMD_Method interp_simd_p_ppp_table []; -#if HOST_BROWSER +#if HOST_BROWSER || HOST_WASI extern int interp_simd_p_p_wasm_opcode_table []; extern int interp_simd_p_pp_wasm_opcode_table []; extern int interp_simd_p_ppp_wasm_opcode_table []; diff --git a/src/mono/mono/mini/interp/transform-simd.c b/src/mono/mono/mini/interp/transform-simd.c index 6f689433361847..b41bfc796d20fd 100644 --- a/src/mono/mono/mini/interp/transform-simd.c +++ b/src/mono/mono/mini/interp/transform-simd.c @@ -517,7 +517,7 @@ emit_sri_vector128 (TransformData *td, MonoMethod *cmethod, MonoMethodSignature if (csignature->hasthis) return FALSE; -#ifdef HOST_BROWSER +#if defined(HOST_BROWSER) || defined(HOST_WASI) if (emit_sri_packedsimd (td, cmethod, csignature)) return TRUE; #endif @@ -731,7 +731,7 @@ emit_sri_vector128 (TransformData *td, MonoMethod *cmethod, MonoMethodSignature static gboolean emit_sri_vector128_t (TransformData *td, MonoMethod *cmethod, MonoMethodSignature *csignature) { -#ifdef HOST_BROWSER +#if defined(HOST_BROWSER) || defined(HOST_WASI) if (emit_sri_packedsimd (td, cmethod, csignature)) return TRUE; #endif @@ -775,7 +775,7 @@ emit_sri_vector128_t (TransformData *td, MonoMethod *cmethod, MonoMethodSignatur static gboolean emit_sn_vector_t (TransformData *td, MonoMethod *cmethod, MonoMethodSignature *csignature, gboolean newobj) { -#ifdef HOST_BROWSER +#if defined(HOST_BROWSER) || defined(HOST_WASI) if (emit_sri_packedsimd (td, cmethod, csignature)) return TRUE; #endif @@ -876,7 +876,7 @@ emit_sn_vector4 (TransformData *td, MonoMethod *cmethod, MonoMethodSignature *cs return TRUE; } -#if HOST_BROWSER +#if defined(HOST_BROWSER) || defined(HOST_WASI) #define PSIMD_ARGTYPE_I1 MONO_TYPE_I1 #define PSIMD_ARGTYPE_I2 MONO_TYPE_I2 @@ -1122,7 +1122,7 @@ emit_sri_packedsimd (TransformData *td, MonoMethod *cmethod, MonoMethodSignature // We don't want to emit the IsSupported or IsHardwareAccelerated methods for Vector* here return FALSE; } -#if HOST_BROWSER +#if defined(HOST_BROWSER) || defined(HOST_WASI) interp_add_ins (td, MINT_LDC_I4_1); #else interp_add_ins (td, MINT_LDC_I4_0); @@ -1133,7 +1133,7 @@ emit_sri_packedsimd (TransformData *td, MonoMethod *cmethod, MonoMethodSignature if (!get_common_simd_info (vector_klass, csignature, &atype, &vector_size, &arg_size, &scalar_arg)) return FALSE; -#if HOST_BROWSER +#if defined(HOST_BROWSER) || defined(HOST_WASI) if (!is_packedsimd) { // transform the method name from the Vector(128|) name to the packed simd name // FIXME: This is a hack, but it works for now. @@ -1311,9 +1311,9 @@ emit_sri_packedsimd (TransformData *td, MonoMethod *cmethod, MonoMethodSignature interp_add_ins (td, simd_opcode); td->last_ins->data [0] = simd_intrins; -#else // HOST_BROWSER +#else // defined(HOST_BROWSER) || defined(HOST_WASI) return FALSE; -#endif // HOST_BROWSER +#endif // defined(HOST_BROWSER) || defined(HOST_WASI) opcode_added: emit_common_simd_epilogue (td, vector_klass, csignature, vector_size, TRUE); diff --git a/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk.pkgproj b/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk.pkgproj index 54dc01747f7d07..5ca1aa5809efec 100644 --- a/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk.pkgproj +++ b/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk.pkgproj @@ -15,6 +15,9 @@ + + + diff --git a/src/mono/wasi/build/WasiApp.targets b/src/mono/wasi/build/WasiApp.targets index 6b8bb0547302c4..04a215b174163e 100644 --- a/src/mono/wasi/build/WasiApp.targets +++ b/src/mono/wasi/build/WasiApp.targets @@ -1,4 +1,8 @@ + + Mono + + @@ -27,7 +31,6 @@ _GetWasiGenerateAppBundleDependencies; _WasiGenerateAppBundle; _GenerateRunWasmtimeScript; - _WasmGenerateNodeScripts; @@ -46,6 +49,15 @@ false full + + <_WasiIntrinsicsSubstitutionsDir Condition="Exists('$(MSBuildThisFileDirectory)ILLink.Substitutions.WasmIntrinsics.xml')">$(MSBuildThisFileDirectory) + <_WasiIntrinsicsSubstitutionsDir Condition="'$(_WasiIntrinsicsSubstitutionsDir)' == '' and '$(BrowserProjectRoot)' != ''">$(BrowserProjectRoot)build\ + + <_ExtraTrimmerArgs Condition="'$(WasmEnableSIMD)' != 'false' and '$(_WasiIntrinsicsSubstitutionsDir)' != ''">$(_ExtraTrimmerArgs) --substitutions "$(_WasiIntrinsicsSubstitutionsDir)ILLink.Substitutions.WasmIntrinsics.xml" + <_ExtraTrimmerArgs Condition="'$(WasmEnableSIMD)' == 'false' and '$(_WasiIntrinsicsSubstitutionsDir)' != ''">$(_ExtraTrimmerArgs) --substitutions "$(_WasiIntrinsicsSubstitutionsDir)ILLink.Substitutions.NoWasmIntrinsics.xml" + false @@ -152,8 +164,8 @@ - <_ExpectedWasiSdkVersion>25.0 - <_FoundExpectedWasiSdkVersion Condition="'%(_WasiSdkVersionLines.Identity)' == '$(_ExpectedWasiSdkVersion)'">true + <_ExpectedWasiSdkVersion>33.0 + <_FoundExpectedWasiSdkVersion Condition="$([System.String]::Copy('%(_WasiSdkVersionLines.Identity)').StartsWith('$(_ExpectedWasiSdkVersion)'))">true <_ToolchainMissingErrorMessage Condition="'$(_FoundExpectedWasiSdkVersion)' == ''">Please use wasi-sdk version $(_ExpectedWasiSdkVersion) and set %24(WASI_SDK_PATH) . It can be obtained from https://github.com/WebAssembly/wasi-sdk/releases <_ToolchainMissingErrorMessage Condition="'$(WASI_SDK_PATH)' == '' or !Exists('$(WASI_SDK_PATH)/VERSION')">Could not find wasi-sdk. Install wasi-sdk and set %24(WASI_SDK_PATH) . It can be obtained from https://github.com/WebAssembly/wasi-sdk/releases <_ToolchainMissingErrorMessage Condition="'$(_ToolchainMissingErrorMessage)' == '' and '$(_ToolchainMissingPaths)' != ''">Using WASI_SDK_PATH=$(WASI_SDK_PATH), cannot find $(_ToolchainMissingPaths) . @@ -245,7 +257,7 @@ <_WasiClangCommonFlags Include="-v" Condition="'$(WasiClangVerbose)' != 'false'" /> - + <_WasiClangCommonFlags Include="-msimd128" Condition="'$(WasmEnableSIMD)' == 'true'" /> <_WasmCommonCFlags Include="-DGEN_PINVOKE=1" /> <_WasmCommonCFlags Condition="'$(_WasmShouldAOT)' == 'true'" Include="-DENABLE_AOT=1" /> @@ -407,7 +419,7 @@ <_WasiLinkStepArgs Condition="'$(OS)' != 'Windows_NT'" Include="@(_WasiFilePathForFixup -> '"%(Identity)"')" /> - <_WasiLinkStepArgs Include="-Wl,-z,stack-size=8388608,-lwasi-emulated-process-clocks,-lwasi-emulated-signal,-lwasi-emulated-mman,-lwasi-emulated-pthread"/> + <_WasiLinkStepArgs Include="-Wl,-z,stack-size=8388608,-lwasi-emulated-process-clocks,-lwasi-emulated-signal,-lwasi-emulated-mman"/> - <_WasiLinkFlags Include="-Wl,-z,stack-size=8388608,--initial-memory=52428800,-lwasi-emulated-process-clocks,-lwasi-emulated-signal,-lwasi-emulated-mman,-lwasi-emulated-pthread"/> + <_WasiLinkFlags Include="-Wl,-z,stack-size=8388608,--initial-memory=52428800,-lwasi-emulated-process-clocks,-lwasi-emulated-signal,-lwasi-emulated-mman"/> diff --git a/src/mono/wasi/wasmtime-version.txt b/src/mono/wasi/wasmtime-version.txt index 008c39a438806b..74578d1f9f8eeb 100644 --- a/src/mono/wasi/wasmtime-version.txt +++ b/src/mono/wasi/wasmtime-version.txt @@ -1 +1 @@ -27.0.0 +45.0.0 diff --git a/src/native/libs/System.Native/entrypoints.c b/src/native/libs/System.Native/entrypoints.c index 2195d91e051ecd..78e08565015511 100644 --- a/src/native/libs/System.Native/entrypoints.c +++ b/src/native/libs/System.Native/entrypoints.c @@ -196,6 +196,7 @@ static const Entry s_sysNative[] = DllImportEntry(SystemNative_TryChangeSocketEventRegistration) DllImportEntry(SystemNative_WaitForSocketEvents) DllImportEntry(SystemNative_GetWasiSocketDescriptor) + DllImportEntry(SystemNative_WasiSubscribeSocketPollable) DllImportEntry(SystemNative_PlatformSupportsDualModeIPv4PacketInfo) DllImportEntry(SystemNative_GetDomainSocketSizes) DllImportEntry(SystemNative_GetMaximumAddressSize) diff --git a/src/native/libs/System.Native/pal_networking.c b/src/native/libs/System.Native/pal_networking.c index 512520015fdc51..b88e18aaf3770a 100644 --- a/src/native/libs/System.Native/pal_networking.c +++ b/src/native/libs/System.Native/pal_networking.c @@ -3461,33 +3461,112 @@ static int32_t WaitForSocketEventsInner(int32_t port, SocketEvent* buffer, int32 #endif // !HAVE_KQUEUE !HAVE_EPOLL #if defined(TARGET_WASI) -// from https://github.com/WebAssembly/wasi-libc/blob/230d4be6c54bec93181050f9e25c87150506bdd0/libc-bottom-half/headers/private/wasi/descriptor_table.h -bool descriptor_table_get_ref(int fd, void **entry); +// from https://github.com/WebAssembly/wasi-libc/blob/161b3195fc25/libc-bottom-half/headers/private/wasi/descriptor_table.h +// The descriptor table entry is a "fat pointer": +// typedef struct { void* data; descriptor_vtable_t* vtable; } descriptor_table_entry_t; +// where `data` points to the descriptor-specific state (a tcp_socket_t* or udp_socket_t*). +void* descriptor_table_get_ref(int fd); // this method is invading private implementation details of wasi-libc // we could get rid of it when https://github.com/WebAssembly/wasi-libc/issues/542 is resolved // or after WASIp3 promises are implemented, whatever comes first -int32_t SystemNative_GetWasiSocketDescriptor(intptr_t socket, void** entry) +// +// Returns the descriptor-specific `data` pointer in *entry and the kind of socket in +// *socketType (1 = TCP/stream, 2 = UDP/datagram, 0 = unknown). The vtable that identifies +// the socket kind is a private static symbol in wasi-libc, so we discriminate via SO_TYPE. +int32_t SystemNative_GetWasiSocketDescriptor(intptr_t socket, void** entry, int32_t* socketType) { - if (entry == NULL) + if (entry == NULL || socketType == NULL) { return Error_EFAULT; } int fd = ToFileDescriptor(socket); - if(!descriptor_table_get_ref(fd, entry)) + // The returned pointer is a descriptor_table_entry_t*; its first word is the `data` pointer. + void** ref = (void**)descriptor_table_get_ref(fd); + if (ref == NULL) { - return Error_EFAULT; + // The fd is not present in the descriptor table (e.g. closed or not a socket). + return Error_EBADF; + } + *entry = ref[0]; + + int type = 0; + socklen_t length = sizeof(type); + if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &length) != 0) + { + return SystemNative_ConvertErrorPlatformToPal(errno); + } + + if (type == SOCK_STREAM) + { + *socketType = 1; + } + else if (type == SOCK_DGRAM) + { + *socketType = 2; } + else + { + *socketType = 0; + } + return Error_SUCCESS; } + +// In the new wasi-libc descriptor-table design, the pollables embedded in the socket state +// (socket_pollable / input_pollable / output_pollable / incoming_pollable / outgoing_pollable) +// are created lazily: their handle is 0 until the corresponding `subscribe` import is called. +// The managed event loop needs the actual pollable handle to merge it into wasi:io/poll.poll, +// so it asks us to lazily subscribe when it observes a 0 handle. +// +// All of the wasi component-model handle types are ABI-identical: a struct wrapping a single +// int32_t handle, passed and returned directly. We mirror that with WasiPollHandle_t so we can +// call the (private) wasi-libc subscribe imports without pulling in the generated headers. +typedef struct { int32_t __handle; } WasiPollHandle_t; +extern WasiPollHandle_t streams_method_input_stream_subscribe(WasiPollHandle_t self); +extern WasiPollHandle_t streams_method_output_stream_subscribe(WasiPollHandle_t self); +extern WasiPollHandle_t tcp_method_tcp_socket_subscribe(WasiPollHandle_t self); +extern WasiPollHandle_t udp_method_udp_socket_subscribe(WasiPollHandle_t self); +extern WasiPollHandle_t udp_method_incoming_datagram_stream_subscribe(WasiPollHandle_t self); +extern WasiPollHandle_t udp_method_outgoing_datagram_stream_subscribe(WasiPollHandle_t self); + +// kind: 0 = input-stream, 1 = output-stream, 2 = tcp-socket, 3 = udp-socket, +// 4 = incoming-datagram-stream, 5 = outgoing-datagram-stream +// `handle` is the borrowed stream/socket handle read from the socket state. Returns the newly +// created pollable handle (the caller stores it back into the socket state so wasi-libc owns +// and eventually drops it), or 0 for an unknown kind. +int32_t SystemNative_WasiSubscribeSocketPollable(int32_t kind, int32_t handle) +{ + WasiPollHandle_t self = { handle }; + WasiPollHandle_t pollable; + switch (kind) + { + case 0: pollable = streams_method_input_stream_subscribe(self); break; + case 1: pollable = streams_method_output_stream_subscribe(self); break; + case 2: pollable = tcp_method_tcp_socket_subscribe(self); break; + case 3: pollable = udp_method_udp_socket_subscribe(self); break; + case 4: pollable = udp_method_incoming_datagram_stream_subscribe(self); break; + case 5: pollable = udp_method_outgoing_datagram_stream_subscribe(self); break; + default: return 0; + } + return pollable.__handle; +} #else -int32_t SystemNative_GetWasiSocketDescriptor(intptr_t socket, void** entry) +int32_t SystemNative_GetWasiSocketDescriptor(intptr_t socket, void** entry, int32_t* socketType) { (void)socket; (void)entry; + (void)socketType; return Error_ENOSYS; } + +int32_t SystemNative_WasiSubscribeSocketPollable(int32_t kind, int32_t handle) +{ + (void)kind; + (void)handle; + return 0; +} #endif // TARGET_WASI int32_t SystemNative_CreateSocketEventPort(intptr_t* port) diff --git a/src/native/libs/System.Native/pal_networking.h b/src/native/libs/System.Native/pal_networking.h index 2a42329fc02fe1..2351826846d57a 100644 --- a/src/native/libs/System.Native/pal_networking.h +++ b/src/native/libs/System.Native/pal_networking.h @@ -405,7 +405,9 @@ PALEXPORT int32_t SystemNative_GetAtOutOfBandMark(intptr_t socket, int32_t* avai PALEXPORT int32_t SystemNative_GetBytesAvailable(intptr_t socket, int32_t* available); -PALEXPORT int32_t SystemNative_GetWasiSocketDescriptor(intptr_t socket, void** entry); +PALEXPORT int32_t SystemNative_GetWasiSocketDescriptor(intptr_t socket, void** entry, int32_t* socketType); + +PALEXPORT int32_t SystemNative_WasiSubscribeSocketPollable(int32_t kind, int32_t handle); PALEXPORT int32_t SystemNative_CreateSocketEventPort(intptr_t* port); diff --git a/src/native/libs/System.Native/pal_networking_browser.c b/src/native/libs/System.Native/pal_networking_browser.c index 3f1de935f0e5ed..d2069f6f0caf24 100644 --- a/src/native/libs/System.Native/pal_networking_browser.c +++ b/src/native/libs/System.Native/pal_networking_browser.c @@ -416,13 +416,21 @@ int32_t SystemNative_GetBytesAvailable(intptr_t socket, int32_t* available) return Error_ENOTSUP; } -int32_t SystemNative_GetWasiSocketDescriptor(intptr_t socket, void** entry) +int32_t SystemNative_GetWasiSocketDescriptor(intptr_t socket, void** entry, int32_t* socketType) { (void)socket; (void)entry; + (void)socketType; return Error_ENOTSUP; } +int32_t SystemNative_WasiSubscribeSocketPollable(int32_t kind, int32_t handle) +{ + (void)kind; + (void)handle; + return 0; +} + int32_t SystemNative_CreateSocketEventPort(intptr_t* port) { (void)port; diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index 87a37cca4af0b3..22c3837bce100b 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -593,6 +593,7 @@ elseif(CLR_CMAKE_TARGET_ANDROID) elseif(CLR_CMAKE_TARGET_WASI) set(HAVE_FORK 0) unset(HAVE_GETNAMEINFO) # WASIp2 libc has empty function with TODO and abort() + unset(HAVE_GETHOSTNAME) # WASI sysroot declares gethostname in unistd.h but libc.a has no definition elseif(CLR_CMAKE_TARGET_BROWSER) set(HAVE_FORK 0) else()