├── grpc-example-server ├── settings.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── src │ └── main │ │ ├── proto │ │ └── hello.proto │ │ └── java │ │ └── net │ │ └── grpc │ │ └── example │ │ ├── ClientRequestInterceptor.java │ │ ├── ServerResponseInterceptor.java │ │ ├── HelloWorldServer.java │ │ └── HelloWorldServiceImpl.java ├── build.gradle ├── cert.pem ├── gradlew.bat ├── key.pem └── gradlew ├── screenshot.png ├── Assets ├── GRPC.NET │ ├── Plugins │ │ ├── GRPC │ │ │ ├── Grpc.Core.Api.dll │ │ │ ├── Google.Protobuf.dll │ │ │ ├── Grpc.Net.Client.dll │ │ │ ├── Grpc.Net.Common.dll │ │ │ ├── System.Diagnostics.DiagnosticSource.dll │ │ │ ├── System.Runtime.CompilerServices.Unsafe.dll │ │ │ ├── Microsoft.Extensions.Logging.Abstractions.dll │ │ │ ├── Grpc.Core.Api.dll.meta │ │ │ ├── Google.Protobuf.dll.meta │ │ │ ├── Grpc.Net.Client.dll.meta │ │ │ ├── Grpc.Net.Common.dll.meta │ │ │ ├── System.Diagnostics.DiagnosticSource.dll.meta │ │ │ ├── System.Runtime.CompilerServices.Unsafe.dll.meta │ │ │ └── Microsoft.Extensions.Logging.Abstractions.dll.meta │ │ └── GRPC.meta │ ├── Example.meta │ ├── Example │ │ ├── Proto │ │ │ ├── hello.proto.meta │ │ │ ├── Hello.cs.meta │ │ │ ├── HelloGrpc.cs.meta │ │ │ ├── hello.proto │ │ │ ├── HelloGrpc.cs │ │ │ └── Hello.cs │ │ ├── GRPCExampleTestScene.unity.meta │ │ ├── Proto.meta │ │ ├── GRPCExampleLogger.cs.meta │ │ ├── GRPCExampleTestController.cs.meta │ │ ├── GRPCExampleLogger.cs │ │ ├── GRPCExampleTestScene.unity │ │ └── GRPCExampleTestController.cs │ ├── Plugins.meta │ ├── Scripts.meta │ └── Scripts │ │ ├── PushPullStream.cs.meta │ │ ├── GRPCBestHttpHandler.cs.meta │ │ ├── ServerStreamHttpContent.cs.meta │ │ ├── ServerStreamHttpContent.cs │ │ ├── PushPullStream.cs │ │ └── GRPCBestHttpHandler.cs └── GRPC.NET.meta ├── LICENSE ├── README.md ├── .gitignore └── Third-Party Notices.txt /grpc-example-server/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'grpc-example-server' 2 | 3 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doctorseus/grpc-dotnet-unity/HEAD/screenshot.png -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins/GRPC/Grpc.Core.Api.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doctorseus/grpc-dotnet-unity/HEAD/Assets/GRPC.NET/Plugins/GRPC/Grpc.Core.Api.dll -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins/GRPC/Google.Protobuf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doctorseus/grpc-dotnet-unity/HEAD/Assets/GRPC.NET/Plugins/GRPC/Google.Protobuf.dll -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins/GRPC/Grpc.Net.Client.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doctorseus/grpc-dotnet-unity/HEAD/Assets/GRPC.NET/Plugins/GRPC/Grpc.Net.Client.dll -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins/GRPC/Grpc.Net.Common.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doctorseus/grpc-dotnet-unity/HEAD/Assets/GRPC.NET/Plugins/GRPC/Grpc.Net.Common.dll -------------------------------------------------------------------------------- /grpc-example-server/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doctorseus/grpc-dotnet-unity/HEAD/grpc-example-server/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins/GRPC/System.Diagnostics.DiagnosticSource.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doctorseus/grpc-dotnet-unity/HEAD/Assets/GRPC.NET/Plugins/GRPC/System.Diagnostics.DiagnosticSource.dll -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins/GRPC/System.Runtime.CompilerServices.Unsafe.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doctorseus/grpc-dotnet-unity/HEAD/Assets/GRPC.NET/Plugins/GRPC/System.Runtime.CompilerServices.Unsafe.dll -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins/GRPC/Microsoft.Extensions.Logging.Abstractions.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doctorseus/grpc-dotnet-unity/HEAD/Assets/GRPC.NET/Plugins/GRPC/Microsoft.Extensions.Logging.Abstractions.dll -------------------------------------------------------------------------------- /Assets/GRPC.NET.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6b17138435c286249a504c1b0f99771c 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Example.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1d1e79c47773f934e8343eb22794c896 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Example/Proto/hello.proto.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7bcd15b9bcac40cd9fc79a765292d4d2 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1c1c737ec6a155642a834780b5b56f38 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e3362769b52c56644a2a1f8b94c09936 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Example/GRPCExampleTestScene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d54bef518f645449869e1e1aa84e5b1 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Example/Proto.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 40a2fcb651c8ca946b549b7504eb1199 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins/GRPC.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 871168bd192161d44bb69fdfe9d337b5 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /grpc-example-server/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Example/Proto/Hello.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d22dacc410da1fb47bb7404af12dde42 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Example/GRPCExampleLogger.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a3ee91ccdea477745bf75a26256ca056 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Example/Proto/HelloGrpc.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5d508a35ac05ce640be0cdf861a744d7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Scripts/PushPullStream.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d79a1c6c4a30a5141a8c0a9db9f64541 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Scripts/GRPCBestHttpHandler.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0047e1c60859e62409c156d6a3083704 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Example/GRPCExampleTestController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fe10f905eef63224f97c892c491430ac 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Scripts/ServerStreamHttpContent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dee83a7198828434c822ccef2f8d80c3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /grpc-example-server/src/main/proto/hello.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option java_multiple_files = true; 4 | option java_package = "net.grpc.example.protos"; 5 | 6 | service HelloWorldService { 7 | rpc hello(HelloRequest) returns (HelloResponse) { }; 8 | rpc helloServer(HelloRequest) returns (stream HelloResponse); 9 | rpc helloClient(stream HelloRequest) returns (HelloResponse); 10 | rpc helloBoth(stream HelloRequest) returns (stream HelloResponse); 11 | } 12 | 13 | message HelloRequest { 14 | string text = 1; 15 | } 16 | 17 | message HelloResponse { 18 | string text = 1; 19 | } 20 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Example/Proto/hello.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option java_multiple_files = true; 4 | option java_package = "net.grpc.example.protos"; 5 | option csharp_namespace = "TestProto"; 6 | 7 | service HelloWorldService { 8 | rpc hello(HelloRequest) returns (HelloResponse) { }; 9 | rpc helloServer(HelloRequest) returns (stream HelloResponse); 10 | rpc helloClient(stream HelloRequest) returns (HelloResponse); 11 | rpc helloBoth(stream HelloRequest) returns (stream HelloResponse); 12 | } 13 | 14 | message HelloRequest { 15 | string text = 1; 16 | } 17 | 18 | message HelloResponse { 19 | string text = 1; 20 | } 21 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins/GRPC/Grpc.Core.Api.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f2180523d422a64d9a267ab35722f92 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 1 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 0 23 | settings: 24 | DefaultValueInitialized: true 25 | - first: 26 | Windows Store Apps: WindowsStoreApps 27 | second: 28 | enabled: 0 29 | settings: 30 | CPU: AnyCPU 31 | userData: 32 | assetBundleName: 33 | assetBundleVariant: 34 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins/GRPC/Google.Protobuf.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 89954ba0c2024f54e847912d1d0701e0 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 1 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 0 23 | settings: 24 | DefaultValueInitialized: true 25 | - first: 26 | Windows Store Apps: WindowsStoreApps 27 | second: 28 | enabled: 0 29 | settings: 30 | CPU: AnyCPU 31 | userData: 32 | assetBundleName: 33 | assetBundleVariant: 34 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins/GRPC/Grpc.Net.Client.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4d44190cb4dd37c419e8353b877896f7 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 1 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 0 23 | settings: 24 | DefaultValueInitialized: true 25 | - first: 26 | Windows Store Apps: WindowsStoreApps 27 | second: 28 | enabled: 0 29 | settings: 30 | CPU: AnyCPU 31 | userData: 32 | assetBundleName: 33 | assetBundleVariant: 34 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins/GRPC/Grpc.Net.Common.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 05f29ba94f7b29a4ab94f8ad5e7d0eb5 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 1 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 0 23 | settings: 24 | DefaultValueInitialized: true 25 | - first: 26 | Windows Store Apps: WindowsStoreApps 27 | second: 28 | enabled: 0 29 | settings: 30 | CPU: AnyCPU 31 | userData: 32 | assetBundleName: 33 | assetBundleVariant: 34 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins/GRPC/System.Diagnostics.DiagnosticSource.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8118c5248b00f4e49923f6c57f281bdd 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 1 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 0 23 | settings: 24 | DefaultValueInitialized: true 25 | - first: 26 | Windows Store Apps: WindowsStoreApps 27 | second: 28 | enabled: 0 29 | settings: 30 | CPU: AnyCPU 31 | userData: 32 | assetBundleName: 33 | assetBundleVariant: 34 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins/GRPC/System.Runtime.CompilerServices.Unsafe.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bb613b0bb11c1dd429ba52c9c4769b70 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 1 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 0 23 | settings: 24 | DefaultValueInitialized: true 25 | - first: 26 | Windows Store Apps: WindowsStoreApps 27 | second: 28 | enabled: 0 29 | settings: 30 | CPU: AnyCPU 31 | userData: 32 | assetBundleName: 33 | assetBundleVariant: 34 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Plugins/GRPC/Microsoft.Extensions.Logging.Abstractions.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 214654f46d524a64eb197335c5359d73 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 1 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 0 23 | settings: 24 | DefaultValueInitialized: true 25 | - first: 26 | Windows Store Apps: WindowsStoreApps 27 | second: 28 | enabled: 0 29 | settings: 30 | CPU: AnyCPU 31 | userData: 32 | assetBundleName: 33 | assetBundleVariant: 34 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Scripts/ServerStreamHttpContent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Net.Http; 5 | using System.Threading.Tasks; 6 | 7 | namespace GRPC.NET 8 | { 9 | public class ServerStreamHttpContent : HttpContent 10 | { 11 | private readonly Stream m_Stream; 12 | 13 | public ServerStreamHttpContent(Stream memoryStream) => m_Stream = memoryStream; 14 | 15 | protected override Task SerializeToStreamAsync(Stream stream, TransportContext context) => throw new NotSupportedException(); 16 | 17 | protected override bool TryComputeLength(out long length) => throw new NotSupportedException(); 18 | 19 | protected override Task CreateContentReadStreamAsync() => Task.FromResult(m_Stream); 20 | 21 | protected override void Dispose(bool disposing) { } // is called for single grpc messages 22 | } 23 | } -------------------------------------------------------------------------------- /grpc-example-server/src/main/java/net/grpc/example/ClientRequestInterceptor.java: -------------------------------------------------------------------------------- 1 | package net.grpc.example; 2 | 3 | import io.grpc.*; 4 | public class ClientRequestInterceptor implements ServerInterceptor { 5 | 6 | public static final Context.Key USER_IDENTITY = Context.key("identity"); 7 | @Override 8 | public ServerCall.Listener interceptCall(ServerCall call, Metadata headers, ServerCallHandler next) { 9 | System.out.println(" > intercept request headers=" + headers); 10 | 11 | String identity = headers.get(Metadata.Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER)); 12 | if (identity == null) { 13 | call.close(Status.UNAUTHENTICATED.withDescription("No token found in header"), new Metadata()); 14 | return new ServerCall.Listener() {}; 15 | } 16 | 17 | Context context = Context.current().withValue(USER_IDENTITY, identity); 18 | return Contexts.interceptCall(context, call, headers, next); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 doctorseus@devlabs.pro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /grpc-example-server/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'com.google.protobuf' 3 | 4 | buildscript { 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath 'com.google.protobuf:protobuf-gradle-plugin:0.9.1' 10 | } 11 | } 12 | 13 | sourceSets { 14 | src { 15 | main { 16 | java { 17 | srcDirs 'build/generated/source/proto/main/grpc' 18 | srcDirs 'build/generated/source/proto/main/java' 19 | } 20 | } 21 | } 22 | } 23 | 24 | group 'net.grpc.example' 25 | version '1.0-SNAPSHOT' 26 | 27 | repositories { 28 | mavenCentral() 29 | } 30 | 31 | dependencies { 32 | implementation 'io.grpc:grpc-netty:1.49.2' 33 | implementation "io.grpc:grpc-protobuf:1.49.2" 34 | implementation "io.grpc:grpc-stub:1.49.2" 35 | implementation "javax.annotation:javax.annotation-api:1.3.2" 36 | } 37 | 38 | protobuf { 39 | protoc { 40 | artifact = 'com.google.protobuf:protoc:3.21.6' 41 | } 42 | 43 | plugins { 44 | grpc { 45 | artifact = "io.grpc:protoc-gen-grpc-java:1.49.2" 46 | } 47 | } 48 | generateProtoTasks { 49 | all()*.plugins { 50 | grpc {} 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Example/GRPCExampleLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace GRPC.NET.Example 5 | { 6 | public class GRPCExampleLogger : MonoBehaviour 7 | { 8 | private const int MAX_SIZE = 16382; 9 | private string m_LogContent = ""; 10 | private Vector2 m_LogScrollView = Vector2.zero; 11 | 12 | public void WriteLogOutput(string s) 13 | { 14 | m_LogContent += s + "\n"; 15 | while (m_LogContent.Length > MAX_SIZE) 16 | { 17 | var index = m_LogContent.IndexOf("\n", StringComparison.Ordinal); 18 | m_LogContent = m_LogContent.Substring(index + 1); 19 | } 20 | m_LogScrollView.y = int.MaxValue; 21 | } 22 | 23 | void GUIDisplayLog() 24 | { 25 | m_LogScrollView = GUILayout.BeginScrollView(m_LogScrollView); 26 | 27 | GUIStyle textStyle = new GUIStyle(); 28 | textStyle.wordWrap = true; 29 | textStyle.richText = true; 30 | GUILayout.Label(m_LogContent, textStyle); 31 | GUILayout.EndScrollView(); 32 | } 33 | 34 | void OnGUI() 35 | { 36 | const int pad = 10; 37 | 38 | var logArea = new Rect(pad, Screen.height * (1.0f / 2.0f), Screen.width - 2 * pad, Screen.height * (1.0f / 2.0f) - pad); 39 | GUILayout.BeginArea(logArea); 40 | GUIDisplayLog(); 41 | GUILayout.EndArea(); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /grpc-example-server/src/main/java/net/grpc/example/ServerResponseInterceptor.java: -------------------------------------------------------------------------------- 1 | package net.grpc.example; 2 | 3 | 4 | import io.grpc.*; 5 | 6 | import java.util.Date; 7 | 8 | public class ServerResponseInterceptor implements ServerInterceptor { 9 | 10 | class ServerMetadataCall extends ForwardingServerCall.SimpleForwardingServerCall { 11 | 12 | protected ServerMetadataCall(ServerCall delegate) { 13 | super(delegate); 14 | } 15 | 16 | @Override 17 | public void sendHeaders(Metadata headers) { 18 | headers.put(Metadata.Key.of("server-version", Metadata.ASCII_STRING_MARSHALLER), "1.0.0"); 19 | System.out.println(" > wire headers [" + headers.keys().size() + "]"); 20 | super.sendHeaders(headers); 21 | } 22 | 23 | @Override 24 | public void sendMessage(RespT message) { 25 | System.out.println(" > wire message"); 26 | super.sendMessage(message); 27 | } 28 | 29 | @Override 30 | public void close(Status status, Metadata trailers) { 31 | trailers.put(Metadata.Key.of("time", Metadata.ASCII_STRING_MARSHALLER), new Date().toString()); 32 | System.out.println(" > wire close [" + trailers.keys().size() + "]"); 33 | super.close(status, trailers); 34 | } 35 | } 36 | 37 | @Override 38 | public ServerCall.Listener interceptCall(ServerCall call, Metadata headers, ServerCallHandler next) { 39 | ServerMetadataCall customServerCall = new ServerMetadataCall<>(call); 40 | return next.startCall(customServerCall, headers); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /grpc-example-server/cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFCTCCAvGgAwIBAgIUXtlBBxO2HLbowGaAiwSHZ4FHZR0wDQYJKoZIhvcNAQEL 3 | BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTIyMTExOTE5NTg1NVoXDTIzMTEx 4 | OTE5NTg1NVowFDESMBAGA1UEAwwJbG9jYWxob3N0MIICIjANBgkqhkiG9w0BAQEF 5 | AAOCAg8AMIICCgKCAgEAyLvVUmizAyzobjc3I1iItjB/EAvOPSosKb7HKo8KSuIO 6 | c2P15ylf4D7ZsaNHa5p2jY0tSaYTOszw5pTAbZw4PRcQpTYUu47McmOezmePMGbH 7 | +xWQXxlRsGQljXu/MbVr/xIk8/yyyZqLs/zsjb/6xxRrfxRqPwvygc5nVNTKTal9 8 | cz/fvldGwVsharg9gaImYfOJZOod+1mm+KkX57MSrfan+wJMYIwlrblVuJPzCMR6 9 | 9c/d/jBD715b309PLOBFN26XK5tOAoPKrHxAhbiZVTu1K6I1yQdkgJUZnwTZUSSx 10 | IENyu31YAHy1T1++RF4AkOnUr90CTB2BYfLpHSioY3nKv3v28JrRuPTmx8mfuhh9 11 | daHe+pihnT1N3WkmlgIvhx1h+1gafvtl6oli7qeV/COGdQIiEXtVHfUTYPSOp6Gv 12 | wGNMTj0sOFsHm9hmuaZzOIJGPK2FN1ygXX35m2fUDoU9492/LG66wEksMXbrRMwj 13 | ov3DJvON7oTh59tQTogHQu4xPjgVTbbsflz5n66EQRsil+bABN7eZYM6NUojhGWF 14 | GGiTuYcHzcBAKVbnin5NMGTEKF3nN1nhpriPP0yrLrvtIaomQRxGDL5HJ/MbeZ60 15 | hhkU9ndqc+u0nswsurSrWW1+6uFo1fYz4LkWb03oaojWfJV57avuaqdo58J8kYUC 16 | AwEAAaNTMFEwHQYDVR0OBBYEFO0zOSUWvA/phIuNuoEIJHZzk8F6MB8GA1UdIwQY 17 | MBaAFO0zOSUWvA/phIuNuoEIJHZzk8F6MA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZI 18 | hvcNAQELBQADggIBAJ0f8eTAO3OkbbrDYdwwJLsUY1CWsWuG5Bd6HNrsWgI8v5/f 19 | AucpqxvZxj5d9CTr85qWfdNTxm9pnCE5WpsdAJbvWP+E98voNsAQRBSPNYJSJKQ2 20 | b4YH2uOeZy7ukJGzRRS9BpI9Edu58cuRt1KUZru0co46CKGo5MhQip7Wc1QrA8Tc 21 | 4+ZDyzmeFyukWhN5hthAudNjMJSvRopISPnYobzery/39bnXtiCX6rTQ1Nv94YG1 22 | LCQgiPJZUHYmxLT2GbeiKGtsWmtYTnHKl4VJpevuV4VMUXgvkgcUdM0NCMgRC7CM 23 | HS1YGrBcjK4sDUgrzdILNf+hbhFTVwByc3dWHRjocROql3TfQjA643T3e6c6XeA/ 24 | mWjHZkY16BOhQUGtf7FxabBEbEM+wIYtfYiSj8+gdblyaAA6tNKi7BUQTrU0Achb 25 | hfiZP42st2dM2AokfnsCq8AZkKykKTS4cLKxnijVHuLCW5ySHj+X4zS8HoCVUE3+ 26 | AzcNRz7YQYi4+mNJC7taUpOxw3h+rwVhP+iYoheh+DXmiUhbPm/EV32/chhIKs2O 27 | AYKBNsD4M/wryGpnWf7ySb9tJ1IKWdpkRi4rlRoYaj1X7TyEjcFQYr3iz7P+CNev 28 | FxkeenqF5Kni6lplSB6cBO4KuXE6cNoYl/Br2bfWk9H+JSkkOONPO8/KAMY9 29 | -----END CERTIFICATE----- 30 | -------------------------------------------------------------------------------- /grpc-example-server/src/main/java/net/grpc/example/HelloWorldServer.java: -------------------------------------------------------------------------------- 1 | package net.grpc.example; 2 | 3 | import io.grpc.*; 4 | import io.grpc.netty.GrpcSslContexts; 5 | import io.grpc.netty.NettyServerBuilder; 6 | import io.netty.handler.codec.http2.Http2SecurityUtil; 7 | import io.netty.handler.ssl.*; 8 | 9 | import java.io.File; 10 | import java.io.IOException; 11 | import java.net.InetSocketAddress; 12 | import java.net.SocketAddress; 13 | import java.util.ArrayList; 14 | 15 | public class HelloWorldServer { 16 | private static final int PORT = 50051; 17 | private Server server; 18 | 19 | public void start() throws IOException { 20 | 21 | SslContextBuilder scb = SslContextBuilder.forServer(new File("cert.pem"), new File("key.pem")); 22 | GrpcSslContexts.configure(scb, SslProvider.JDK); 23 | 24 | ArrayList allCiphers = new ArrayList<>(Http2SecurityUtil.CIPHERS); 25 | allCiphers.add(Ciphers.TLS_RSA_WITH_AES_128_GCM_SHA256); 26 | allCiphers.add(Ciphers.TLS_RSA_WITH_AES_128_CBC_SHA256); 27 | allCiphers.add(Ciphers.TLS_RSA_WITH_AES_128_CBC_SHA); 28 | scb.ciphers(allCiphers, SupportedCipherSuiteFilter.INSTANCE); 29 | 30 | SslContext sslContext = scb.build(); 31 | SocketAddress socketAddress = new InetSocketAddress("127.0.0.1", PORT); 32 | 33 | HelloWorldServiceImpl service = new HelloWorldServiceImpl(); 34 | ServerServiceDefinition requestInterceptor = ServerInterceptors.intercept(service, new ClientRequestInterceptor()); 35 | ServerServiceDefinition responseInterceptor = ServerInterceptors.intercept(requestInterceptor, new ServerResponseInterceptor()); 36 | 37 | server = NettyServerBuilder.forAddress(socketAddress) 38 | .sslContext(sslContext) 39 | .addService(responseInterceptor) 40 | .build(); 41 | server.start(); 42 | } 43 | 44 | public void blockUntilShutdown() throws InterruptedException { 45 | if (server == null) return; 46 | server.awaitTermination(); 47 | } 48 | 49 | public static void main(String[] args) throws InterruptedException, IOException { 50 | HelloWorldServer server = new HelloWorldServer(); 51 | server.start(); 52 | server.blockUntilShutdown(); 53 | } 54 | } -------------------------------------------------------------------------------- /grpc-example-server/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /grpc-example-server/key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQDIu9VSaLMDLOhu 3 | NzcjWIi2MH8QC849KiwpvscqjwpK4g5zY/XnKV/gPtmxo0drmnaNjS1JphM6zPDm 4 | lMBtnDg9FxClNhS7jsxyY57OZ48wZsf7FZBfGVGwZCWNe78xtWv/EiTz/LLJmouz 5 | /OyNv/rHFGt/FGo/C/KBzmdU1MpNqX1zP9++V0bBWyFquD2BoiZh84lk6h37Wab4 6 | qRfnsxKt9qf7AkxgjCWtuVW4k/MIxHr1z93+MEPvXlvfT08s4EU3bpcrm04Cg8qs 7 | fECFuJlVO7UrojXJB2SAlRmfBNlRJLEgQ3K7fVgAfLVPX75EXgCQ6dSv3QJMHYFh 8 | 8ukdKKhjecq/e/bwmtG49ObHyZ+6GH11od76mKGdPU3daSaWAi+HHWH7WBp++2Xq 9 | iWLup5X8I4Z1AiIRe1Ud9RNg9I6noa/AY0xOPSw4Wweb2Ga5pnM4gkY8rYU3XKBd 10 | ffmbZ9QOhT3j3b8sbrrASSwxdutEzCOi/cMm843uhOHn21BOiAdC7jE+OBVNtux+ 11 | XPmfroRBGyKX5sAE3t5lgzo1SiOEZYUYaJO5hwfNwEApVueKfk0wZMQoXec3WeGm 12 | uI8/TKsuu+0hqiZBHEYMvkcn8xt5nrSGGRT2d2pz67SezCy6tKtZbX7q4WjV9jPg 13 | uRZvTehqiNZ8lXntq+5qp2jnwnyRhQIDAQABAoICACjuxI1NdFONcMgo0kGO6DHe 14 | qcpn3eJzGxZYJNz01jB28GNvWtGMilR7/IBQv1ud39b1luqRxxISgH1EkAjJ9l3e 15 | ujI2WPv2HpKk5dlJHNXN37G/r/T0gMfrZAz50v8b863L0WU/fmXF8f798G7nWwgF 16 | jfYX/6JjmUwG/uM5kRdNHJvHxqRVv8PmBWZxs3kfy5vlwXqmkv6SRY4nTQyeY4y9 17 | 43s3+MMnUPef927wHHsJNdmyTZ5r0S6amzlqPsbz5KltD76AqOOyZD3QCIg8IGhV 18 | CJihNz6LF19xCAx5PKdjSAtANcEtyigvRfmtmGrwkET8qbZC5xkGWz/R/N9JTyy9 19 | SHtZUTAKNiKyngCbUn/IUK84/VjFHDu77zT1Bz/94QAzWPY0nUePYabsBAMAERC6 20 | DbualZqDeydo1AGPPewt6U2mC5qfAQwpDyobT/e4sEg/cbqU6YiSbTegEnXO9tt8 21 | WDqtJE0LIS2CxTotm+usANsKrYelvp3hljjegiBKAS4e1mremiB+oQGPJ8P7Vo2E 22 | dWkywyhub6aBy6R9h4/+tnxxA4FkILul22X990Gv5m3g1gxJDW0JyTbxt81CQL/w 23 | ClsOH5o4MnWPR1ddm13ds28TyOVB3eTMkER/NXZ1M3IA8k0Sy/7/CPhNfd+yHJXN 24 | Chkj7e8irT1w3SszRk0BAoIBAQDpBBXxuyaVnKLXmWpeV9YIbDmgP/aQ+mHZJX+J 25 | qwrmnb+UHrL9g3fdILUl4y06fPEOCa2zvcSonZKx0bbpIfs8/XMea7RNRZf0DfBl 26 | MiAmuTIQYaNbclYp7lfdR6NudX2bwUghEcyORgVYCx6igVEYK5OukWWlLaEIqsil 27 | C+qYVHvfyqMrxbNW8NTLPJiatIBqaCctYvRMRSOgFrgyiI9sIuffhske094VRGxI 28 | 9W+mHm5nXRFyKcfwNwNMN/pCScduz4qDtEZRvjr68H757mWNrmN5q2i/XYMXNeu7 29 | kG5CgmZx/mUjadDV4TnJG3e5obSd8MzpvXGdo7THnaE70Ef1AoIBAQDciJW8kKmL 30 | GqI+sl6yQGYdsolJovdqocaJashMg6VeNo6st6T2OQHRi/b8J21eTuUE0B0KyViG 31 | mP4Lo4st/eLz4L6IDWnYE8YjLRmqB0HAjOA3Ag9sgbnQbfDWhZFFXg80DBEZLoU0 32 | FioMH/uO89mnAmwcE0p6AiOlDcZQfeGYx2MP2KpuEFQ/7PJvdlIIWJYbQX8MpZD2 33 | qvB8MRV5c+0dbQJ+ejwx6Z2N4nSebylXrq92Aomk1IkYyQtE07nt1oTwgpkOfNqJ 34 | T4s8YwW/HptJeIUFyD2YHV0hBYl33KFygbHYP9AzDopRIgI5zdAeRS4IUpp73TiJ 35 | 4PenWVWwZ3lRAoIBACPFkczba0/6jPFGRxMWru/6FVqplyOonI7md87dqD3BJ+EI 36 | WXgbz7HtzIF1f8MD3UnHaJg4YNF150hPJqJhqh0x15Nq+3IFZg98eFRAvrjTI4Fq 37 | S9bFFb84LNr2nXtepBreMEGLZvjMfROIGXrfGWD5h6F8Bru15ovbFBRqYOhjx+SS 38 | Sjx1DFQjgrd0pQTTAwfS13jbQR/YWWDBPCPd3Q6/yRMCsSt/YQ+owmrs6uf4sgBC 39 | RGRfT6dr+qCf01aL1wcG63/OlCEGcC2H8CZUV9jJVdIe42TFaVON3pOb16F0PV/w 40 | qvwlyX6cJe/evKGN1pmMlxinEaMet6kRZOg20GUCggEAWsPIRPSRIxRSJFXLTbfd 41 | j2l0wZ7WD8gHa3VMfNlNzWnM7N8kgMZTrkfZ3kvn4oG8FnAFE/Rsf/El1ep4lPRC 42 | XTdpk5tZrbntuXqNboJQGIyil2E8sd7ueA9XqSMN+CvPPA+fVerkndxlb9oV8e8A 43 | 7JC9qAx0gaSxwPPbZDN7DyM47UOyWVxVIH5IBYIAHzk+hnc9cBoQgMU39xVIjlUd 44 | CRhdh2qNrclFtCi48KA1tsXJp1tCBVoIFvBft/MgOfgpfMdzcRgH5a2cU705l0Bk 45 | jyeQMCIK37luI/IgcvmWZQdmB+ezq9/XI69IlTvU5TB50qkUtdgFthGmO/UzpEfi 46 | EQKCAQEAr0HZBzmRzZII654tYoAtoX5+kgENfXupV39pNUu8JR0lhQ8cE3nETnmH 47 | L46bjO3245APsKg0QJoZIxhSvckdLoChfTXQI4yQqnRCErR8ybGGMa8AW5mslKv4 48 | nzgAnZ2dO6FxGHaoKchLLfp1Nn/kzdFH+Jzq7k1662WNl0/wvvHP7UJQ3OZSDmJa 49 | oCoa9uKo/Syuc/NxvI/MX1bQTtOFO6oo2bQoxbcEG66VYgX4YEnM+sQYkk3fhKFV 50 | 3EU5EIQDduAkKRqwsdYgTfi0nIEGnVweWc9KCiIUYub/VWOlWi2ycTAYZ8RuIRiv 51 | bqw5CNwWS1xY9sMpXRcpHsjYLDV6BQ== 52 | -----END PRIVATE KEY----- 53 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Scripts/PushPullStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Threading; 5 | 6 | namespace GRPC.NET 7 | { 8 | public class PushPullStream : Stream 9 | { 10 | private const long MAX_BUFFER_LENGTH = 5 * 1024 * 1024; // 5 MB 11 | 12 | public bool NonBlockingRead = false; 13 | 14 | private readonly string m_Name; 15 | 16 | private readonly Queue m_Buffer = new Queue(); 17 | 18 | private bool m_Flushed; 19 | private bool m_Closed; 20 | 21 | private Exception m_Exception; 22 | 23 | public Action OnStreamFlushCallback; 24 | 25 | public PushPullStream(string name) 26 | { 27 | m_Name = name; 28 | } 29 | 30 | public override int Read(byte[] buffer, int offset, int count) 31 | { 32 | if (count == 0) 33 | return 0; 34 | 35 | var readLength = 0; 36 | lock (m_Buffer) 37 | { 38 | while (!ReadAvailable(count)) 39 | Monitor.Wait(m_Buffer); 40 | 41 | for (; readLength < count && Length > 0 && m_Buffer.Count > 0; readLength++) 42 | { 43 | buffer[readLength] = m_Buffer.Dequeue(); 44 | } 45 | 46 | Monitor.Pulse(m_Buffer); 47 | } 48 | 49 | // BestHTTP expects us to return -1 when we have no data (but have not reached EOF yet). 50 | if (readLength == 0 && !m_Closed) 51 | return -1; 52 | 53 | return readLength; 54 | } 55 | 56 | private bool ReadAvailable(int count) 57 | { 58 | if (m_Exception != null) 59 | throw m_Exception; 60 | 61 | // Either we have data to read, or we got flushed (e.g. stream got closed) 62 | // or we are in non blocking read mode. 63 | return Length >= count && m_Flushed || m_Closed || NonBlockingRead; 64 | } 65 | 66 | public override long Length => m_Buffer.Count; 67 | public override long Position 68 | { 69 | get => 0; 70 | set => throw new NotSupportedException(); 71 | } 72 | 73 | public override void Write(byte[] buffer, int offset, int count) 74 | { 75 | lock (m_Buffer) 76 | { 77 | while (Length >= MAX_BUFFER_LENGTH) 78 | Monitor.Wait(m_Buffer); 79 | 80 | for (var i = offset; i < offset + count; i++) m_Buffer.Enqueue(buffer[i]); 81 | 82 | m_Flushed = false; 83 | Monitor.Pulse(m_Buffer); 84 | } 85 | } 86 | 87 | public override void Flush() 88 | { 89 | m_Flushed = true; 90 | lock (m_Buffer) 91 | Monitor.Pulse(m_Buffer); 92 | OnStreamFlushCallback?.Invoke(); 93 | } 94 | 95 | public override void Close() => CloseWithException(null); 96 | 97 | public void CloseWithException(Exception ex) 98 | { 99 | m_Exception = ex; 100 | m_Closed = true; 101 | Flush(); 102 | } 103 | 104 | public override long Seek(long offset, SeekOrigin origin) => throw new System.NotSupportedException(); 105 | public override void SetLength(long value) => throw new System.NotSupportedException(); 106 | public override bool CanRead => true; 107 | public override bool CanSeek => false; 108 | public override bool CanWrite => true; 109 | } 110 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # grpc-dotnet via HTTP2 for Unity 2 | ![Test Scene Screenshot](screenshot.png) 3 | 4 | ## TODO 5 | - Verify all supported platforms (iOS, Android, ...) 6 | 7 | ***Note:** Pull requests improving coverage of functionality are very welcome. But in any case, if you notice the lack of some features or any other issues please open a ticket.* 8 | 9 | ## Introduction 10 | 11 | **Important:** This package requires to have at least version 2.8.2 of [BestHTTP/2 by Tivadar György Nagy](https://assetstore.unity.com/packages/tools/network/best-http-2-155981) [https://github.com/doctorseus/grpc-dotnet-unity/issues/1]! 12 | 13 | Up to this point the only way to use gRPC with Unity was to use gRPC.Core. This implementation requires native platform-specific unmanaged libraries to support the HTTP2 communication and as of today is [planned to be deprecated in May 2023](https://grpc.io/blog/grpc-csharp-future/). 14 | 15 | [The way forward and future to support gRPC within .NET/C# lays with grpc-dotnet.](https://forum.unity.com/threads/unity-future-net-development-status.1092205/) Unfortunately this new implementation (exclusively using managed code and without any platform-specific requirements) is not compatible with Unity as of now. This is because Unity currently does not support HTTP2 natively until the [move to .NET 6/7](https://forum.unity.com/threads/unity-future-net-development-status.1092205/) is completed. 16 | 17 | This package uses the custom [BestHTTP/2](https://assetstore.unity.com/packages/tools/network/best-http-2-155981) package as HTTP2 client to replace the transport layer of grpc-dotnet and enable support of **unary, client-streaming, server-streaming and bidirectional-streams** across supported platforms. 18 | 19 | **Important:** Any gRPC server implementation is not supported! Only gRPC client mode. 20 | 21 | Apart of the glue code to enable this, this package also includes a test scene and code used to verify gRPC functionality and as an example of usage of the gRPC async API. 22 | 23 | Latest versions of grpc-dotnet and additional required dependencies are also included. 24 | 25 | The documentation for gRPC and it's API can be found on https://grpc.io/docs/languages/csharp/. 26 | 27 | ## gRPC Setup 28 | 29 | After importing this package also import the latest version of **BestHTTP/2** via the package manager. 30 | When creating a connection with gRPC the only thing required is to provide an instance of `GRPCBestHttpHandler` to `GrpcChannelOptions.HttpHandler` when initiating a new channel. 31 | 32 | This will make sure that BestHTTP/2 is used when creating a new HTTP2 channel to the server. 33 | This class will make sure that all outgoing and ingoing communication from grpc-dotnet is handled by BestHTTP/2. 34 | 35 | ``` 36 | GRPCBestHttpHandler httpHandler = new GRPCBestHttpHandler(); 37 | m_Channel = GrpcChannel.ForAddress(ServerAddressInput, new GrpcChannelOptions 38 | { 39 | HttpHandler = httpHandler 40 | }); 41 | 42 | m_Client = new HelloWorldService.HelloWorldServiceClient(m_Channel); 43 | ``` 44 | 45 | ## Demo Scene 46 | 47 | The Demo Scene provides the possibility to send unary, client-streaming, server-streaming and bidirectional-streaming calls to one (or two via a secondary channel) gRPC server. The proto file used for this service can be found in `GRPC.NET/Example/Proto/hello.proto`. 48 | 49 | 50 | ### Demo Server (Java) 51 | 52 | This package also includes a gradle based Java gRPC server project (`grpc-example-server/`) for testing purposes with this client. 53 | 54 | If you are not familiar with Java, it is recommended to use https://www.jetbrains.com/idea/ to open and run the example server class `net.grpc.example.HelloWorldServer`. 55 | 56 | # Release Notes 57 | 58 | ## FAQ 59 | 60 | - *Are connections with **ChannelCredentials.Insecure** supported?* 61 | - No, BestHTTP does not support plaintext http2 aka "h2c with prior knowledge" which is assumed when gRPC is used with insecure credentials. You will have to setup SSL on your gRPC server. 62 | - *Some versions of external dependencies listed below are deprecated, can I replace them with newer versions?* 63 | - Yes, although gRPC is build against the versions listed below, they also work with newer versions. However, you might have to disable `Validate References` within Unity if you get a `X references strong named Y, versions has to match.` build error. 64 | 65 | ## Version 1.2.0 66 | - Fixed handling of metadata and trailing headers. [https://github.com/doctorseus/grpc-dotnet-unity/issues/5] 67 | - Dependencies: 68 | - grpc.core.api.2.51.0 (netstandard2.1) 69 | - grpc.net.client.2.51.0 (netstandard2.1) [note: https://github.com/doctorseus/grpc-dotnet-unity/issues/2] 70 | - grpc.net.common.2.51.0 (netstandard2.1) 71 | - google.protobuf.3.21.9 (netstandard2.0) 72 | - system.runtime.compilerservices.unsafe.4.5.2 (netstandard2.0) 73 | - microsoft.extensions.logging.abstractions.3.0.3 (netstandard2.0) 74 | - system.diagnostics.diagnosticsource.4.5.1 (netstandard1.3) 75 | 76 | ## Version 1.1.0 77 | - Updated gRPC to version 2.51.0 78 | - Improved handling of server disconnects / unreachable servers. 79 | - Added support for trailer-only responses (gRPC error handling). 80 | - Added gRPC call cancellation support. 81 | - Dependencies: 82 | - grpc.core.api.2.51.0 (netstandard2.1) 83 | - grpc.net.client.2.51.0 (netstandard2.1) [note: https://github.com/doctorseus/grpc-dotnet-unity/issues/2] 84 | - grpc.net.common.2.51.0 (netstandard2.1) 85 | - google.protobuf.3.21.9 (netstandard2.0) 86 | - system.runtime.compilerservices.unsafe.4.5.2 (netstandard2.0) 87 | - microsoft.extensions.logging.abstractions.3.0.3 (netstandard2.0) 88 | - system.diagnostics.diagnosticsource.4.5.1 (netstandard1.3) 89 | 90 | ## Version 1.0.0 91 | - Initial Release 92 | - Dependencies: 93 | - grpc.core.api.2.50.0 (netstandard2.1) 94 | - grpc.net.client.2.50.0 (netstandard2.1) [note: https://github.com/doctorseus/grpc-dotnet-unity/issues/2] 95 | - grpc.net.common.2.50.0 (netstandard2.1) 96 | - google.protobuf.3.21.9 (netstandard2.0) 97 | - system.runtime.compilerservices.unsafe.4.5.2 (netstandard2.0) 98 | - microsoft.extensions.logging.abstractions.3.0.3 (netstandard2.0) 99 | - system.diagnostics.diagnosticsource.4.5.1 (netstandard1.3) 100 | -------------------------------------------------------------------------------- /grpc-example-server/src/main/java/net/grpc/example/HelloWorldServiceImpl.java: -------------------------------------------------------------------------------- 1 | package net.grpc.example; 2 | 3 | import io.grpc.Metadata; 4 | import io.grpc.Status; 5 | import io.grpc.stub.StreamObserver; 6 | import net.grpc.example.protos.HelloRequest; 7 | import net.grpc.example.protos.HelloResponse; 8 | import net.grpc.example.protos.HelloWorldServiceGrpc; 9 | 10 | import java.util.concurrent.Executors; 11 | import java.util.concurrent.ScheduledExecutorService; 12 | import java.util.concurrent.TimeUnit; 13 | 14 | public class HelloWorldServiceImpl extends HelloWorldServiceGrpc.HelloWorldServiceImplBase { 15 | 16 | private ScheduledExecutorService e = Executors.newSingleThreadScheduledExecutor(); 17 | 18 | @Override 19 | public void hello(HelloRequest request, StreamObserver responseObserver) { 20 | String message = request.getText(); 21 | System.out.println("hello() called"); 22 | System.out.println(" > received " + message); 23 | 24 | if (!message.contains("[no-response]")) { 25 | if (message.contains("[exception-before]")) { 26 | responseObserver.onError(Status.INVALID_ARGUMENT.withDescription("Before Response Exception").asException()); 27 | return; 28 | } else if (message.contains("[exception-before-meta]")) { 29 | Metadata metadata = new Metadata(); 30 | metadata.put(Metadata.Key.of("metadata-key", Metadata.ASCII_STRING_MARSHALLER), "metadata-value"); 31 | metadata.put(Metadata.Key.of("metadata-key1", Metadata.ASCII_STRING_MARSHALLER), "metadata-value1"); 32 | responseObserver.onError(Status.INVALID_ARGUMENT.withDescription("Before Response Exception with Metadata").asException(metadata)); 33 | return; 34 | } 35 | 36 | String txt = "Hello " + message; 37 | System.out.println(" > send " + txt + " + done"); 38 | responseObserver.onNext(HelloResponse.newBuilder().setText(txt).build()); 39 | 40 | if (message.contains("[exception-after]")) { 41 | responseObserver.onError(Status.INTERNAL.withDescription("After Response Exception").asException()); 42 | return; 43 | } else if (message.contains("[exception-after-meta]")) { 44 | Metadata metadata = new Metadata(); 45 | metadata.put(Metadata.Key.of("metadata-key", Metadata.ASCII_STRING_MARSHALLER), "metadata-value"); 46 | metadata.put(Metadata.Key.of("metadata-key1", Metadata.ASCII_STRING_MARSHALLER), "metadata-value1"); 47 | responseObserver.onError(Status.INTERNAL.withDescription("After Response Exception with Metadata").asException(metadata)); 48 | return; 49 | } 50 | } 51 | 52 | responseObserver.onCompleted(); 53 | } 54 | 55 | 56 | private void sendMessageFor(StreamObserver responseObserver, String message, int number) { 57 | if (number > 0) { 58 | String txt = message + " ["+ number + "]"; 59 | System.out.println(" > send " + txt); 60 | responseObserver.onNext(HelloResponse.newBuilder().setText(txt).build()); 61 | e.schedule(() -> sendMessageFor(responseObserver, message, number -1), 3, TimeUnit.SECONDS); 62 | } else { 63 | System.out.println(" > end of stream "); 64 | responseObserver.onCompleted(); 65 | } 66 | } 67 | 68 | @Override 69 | public void helloServer(HelloRequest request, StreamObserver responseObserver) { 70 | System.out.println("helloServer() called"); 71 | System.out.println(" > received " + request.getText()); 72 | sendMessageFor(responseObserver, "Hello " + request.getText(), 4); 73 | } 74 | 75 | @Override 76 | public StreamObserver helloClient(StreamObserver responseObserver) { 77 | System.out.println("helloClient() called"); 78 | return new StreamObserver() { 79 | 80 | int count = 0; 81 | 82 | @Override 83 | public void onNext(HelloRequest request) { 84 | String message = request.getText(); 85 | System.out.println(" > received " + message); 86 | 87 | if (message.contains("[stop]")) { 88 | responseObserver.onError(Status.INTERNAL.withDescription("Abort from Server side").asException()); 89 | } 90 | 91 | count++; 92 | } 93 | 94 | @Override 95 | public void onError(Throwable t) { 96 | System.out.println(" > received error: " + t.getMessage()); 97 | } 98 | 99 | @Override 100 | public void onCompleted() { 101 | System.out.println(" > received total of " + count + " messages"); 102 | responseObserver.onNext(HelloResponse.newBuilder().setText("Hello to all " + count).build()); 103 | responseObserver.onCompleted(); 104 | } 105 | }; 106 | } 107 | 108 | @Override 109 | public StreamObserver helloBoth(StreamObserver responseObserver) { 110 | System.out.println("helloBoth() called"); 111 | return new StreamObserver() { 112 | 113 | int count = 0; 114 | 115 | @Override 116 | public void onNext(HelloRequest request) { 117 | String message = request.getText(); 118 | System.out.println(" > received " + request.getText()); 119 | String txt = message + " ["+ count + "]"; 120 | System.out.println(" > send " + txt); 121 | responseObserver.onNext(HelloResponse.newBuilder().setText(txt).build()); 122 | count++; 123 | } 124 | 125 | @Override 126 | public void onError(Throwable t) { 127 | System.out.println(" > received error: " + t.getMessage()); 128 | } 129 | 130 | @Override 131 | public void onCompleted() { 132 | System.out.println(" > received and send total of " + count + " messages"); 133 | responseObserver.onCompleted(); 134 | } 135 | }; 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/intellij,unity,rider,java,gradle 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=intellij,unity,rider,java,gradle 3 | 4 | ### Intellij ### 5 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 6 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 7 | 8 | **/.idea/** 9 | 10 | # User-specific stuff 11 | .idea/**/workspace.xml 12 | .idea/**/tasks.xml 13 | .idea/**/usage.statistics.xml 14 | .idea/**/dictionaries 15 | .idea/**/shelf 16 | 17 | # AWS User-specific 18 | .idea/**/aws.xml 19 | 20 | # Generated files 21 | .idea/**/contentModel.xml 22 | 23 | # Sensitive or high-churn files 24 | .idea/**/dataSources/ 25 | .idea/**/dataSources.ids 26 | .idea/**/dataSources.local.xml 27 | .idea/**/sqlDataSources.xml 28 | .idea/**/dynamic.xml 29 | .idea/**/uiDesigner.xml 30 | .idea/**/dbnavigator.xml 31 | 32 | # Gradle 33 | .idea/**/gradle.xml 34 | .idea/**/libraries 35 | 36 | # Gradle and Maven with auto-import 37 | # When using Gradle or Maven with auto-import, you should exclude module files, 38 | # since they will be recreated, and may cause churn. Uncomment if using 39 | # auto-import. 40 | # .idea/artifacts 41 | # .idea/compiler.xml 42 | # .idea/jarRepositories.xml 43 | # .idea/modules.xml 44 | # .idea/*.iml 45 | # .idea/modules 46 | # *.iml 47 | # *.ipr 48 | 49 | # CMake 50 | cmake-build-*/ 51 | 52 | # Mongo Explorer plugin 53 | .idea/**/mongoSettings.xml 54 | 55 | # File-based project format 56 | *.iws 57 | 58 | # IntelliJ 59 | out/ 60 | 61 | # mpeltonen/sbt-idea plugin 62 | .idea_modules/ 63 | 64 | # JIRA plugin 65 | atlassian-ide-plugin.xml 66 | 67 | # Cursive Clojure plugin 68 | .idea/replstate.xml 69 | 70 | # SonarLint plugin 71 | .idea/sonarlint/ 72 | 73 | # Crashlytics plugin (for Android Studio and IntelliJ) 74 | com_crashlytics_export_strings.xml 75 | crashlytics.properties 76 | crashlytics-build.properties 77 | fabric.properties 78 | 79 | # Editor-based Rest Client 80 | .idea/httpRequests 81 | 82 | # Android studio 3.1+ serialized cache file 83 | .idea/caches/build_file_checksums.ser 84 | 85 | ### Intellij Patch ### 86 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 87 | 88 | # *.iml 89 | # modules.xml 90 | # .idea/misc.xml 91 | # *.ipr 92 | 93 | # Sonarlint plugin 94 | # https://plugins.jetbrains.com/plugin/7973-sonarlint 95 | .idea/**/sonarlint/ 96 | 97 | # SonarQube Plugin 98 | # https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin 99 | .idea/**/sonarIssues.xml 100 | 101 | # Markdown Navigator plugin 102 | # https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced 103 | .idea/**/markdown-navigator.xml 104 | .idea/**/markdown-navigator-enh.xml 105 | .idea/**/markdown-navigator/ 106 | 107 | # Cache file creation bug 108 | # See https://youtrack.jetbrains.com/issue/JBR-2257 109 | .idea/$CACHE_FILE$ 110 | 111 | # CodeStream plugin 112 | # https://plugins.jetbrains.com/plugin/12206-codestream 113 | .idea/codestream.xml 114 | 115 | # Azure Toolkit for IntelliJ plugin 116 | # https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij 117 | .idea/**/azureSettings.xml 118 | 119 | ### Java ### 120 | # Compiled class file 121 | *.class 122 | 123 | # Log file 124 | *.log 125 | 126 | # BlueJ files 127 | *.ctxt 128 | 129 | # Mobile Tools for Java (J2ME) 130 | .mtj.tmp/ 131 | 132 | # Package Files # 133 | *.jar 134 | *.war 135 | *.nar 136 | *.ear 137 | *.zip 138 | *.tar.gz 139 | *.rar 140 | 141 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 142 | hs_err_pid* 143 | replay_pid* 144 | 145 | ### Rider ### 146 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 147 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 148 | 149 | # User-specific stuff 150 | 151 | # AWS User-specific 152 | 153 | # Generated files 154 | 155 | # Sensitive or high-churn files 156 | 157 | # Gradle 158 | 159 | # Gradle and Maven with auto-import 160 | # When using Gradle or Maven with auto-import, you should exclude module files, 161 | # since they will be recreated, and may cause churn. Uncomment if using 162 | # auto-import. 163 | # .idea/artifacts 164 | # .idea/compiler.xml 165 | # .idea/jarRepositories.xml 166 | # .idea/modules.xml 167 | # .idea/*.iml 168 | # .idea/modules 169 | # *.iml 170 | # *.ipr 171 | 172 | # CMake 173 | 174 | # Mongo Explorer plugin 175 | 176 | # File-based project format 177 | 178 | # IntelliJ 179 | 180 | # mpeltonen/sbt-idea plugin 181 | 182 | # JIRA plugin 183 | 184 | # Cursive Clojure plugin 185 | 186 | # SonarLint plugin 187 | 188 | # Crashlytics plugin (for Android Studio and IntelliJ) 189 | 190 | # Editor-based Rest Client 191 | 192 | # Android studio 3.1+ serialized cache file 193 | 194 | ### Unity ### 195 | # This .gitignore file should be placed at the root of your Unity project directory 196 | # 197 | # Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore 198 | /[Ll]ibrary/ 199 | /[Tt]emp/ 200 | /[Oo]bj/ 201 | /[Bb]uild/ 202 | /[Bb]uilds/ 203 | /[Ll]ogs/ 204 | /[Uu]ser[Ss]ettings/ 205 | 206 | # MemoryCaptures can get excessive in size. 207 | # They also could contain extremely sensitive data 208 | /[Mm]emoryCaptures/ 209 | 210 | # Recordings can get excessive in size 211 | /[Rr]ecordings/ 212 | 213 | # Uncomment this line if you wish to ignore the asset store tools plugin 214 | # /[Aa]ssets/AssetStoreTools* 215 | 216 | # Autogenerated Jetbrains Rider plugin 217 | /[Aa]ssets/Plugins/Editor/JetBrains* 218 | 219 | # Visual Studio cache directory 220 | .vs/ 221 | 222 | # Gradle cache directory 223 | .gradle/ 224 | 225 | # Autogenerated VS/MD/Consulo solution and project files 226 | ExportedObj/ 227 | .consulo/ 228 | *.csproj 229 | *.unityproj 230 | *.sln 231 | *.suo 232 | *.tmp 233 | *.user 234 | *.userprefs 235 | *.pidb 236 | *.booproj 237 | *.svd 238 | *.pdb 239 | *.mdb 240 | *.opendb 241 | *.VC.db 242 | 243 | # Unity3D generated meta files 244 | *.pidb.meta 245 | *.pdb.meta 246 | *.mdb.meta 247 | 248 | # Unity3D generated file on crash reports 249 | sysinfo.txt 250 | 251 | # Builds 252 | *.apk 253 | *.aab 254 | *.unitypackage 255 | *.app 256 | 257 | # Crashlytics generated file 258 | 259 | # Packed Addressables 260 | /[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin* 261 | 262 | # Temporary auto-generated Android Assets 263 | /[Aa]ssets/[Ss]treamingAssets/aa.meta 264 | /[Aa]ssets/[Ss]treamingAssets/aa/* 265 | 266 | ### Gradle ### 267 | .gradle 268 | **/build/ 269 | !src/**/build/ 270 | 271 | # Ignore Gradle GUI config 272 | gradle-app.setting 273 | 274 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 275 | !gradle-wrapper.jar 276 | 277 | # Avoid ignore Gradle wrappper properties 278 | !gradle-wrapper.properties 279 | 280 | # Cache of project 281 | .gradletasknamecache 282 | 283 | # Eclipse Gradle plugin generated files 284 | # Eclipse Core 285 | .project 286 | # JDT-specific (Eclipse Java Development Tools) 287 | .classpath 288 | 289 | ### Gradle Patch ### 290 | # Java heap dump 291 | *.hprof 292 | 293 | # End of https://www.toptal.com/developers/gitignore/api/intellij,unity,rider,java,gradle 294 | 295 | # Never commit BestHTTP2 to git 296 | **/Best HTTP** 297 | -------------------------------------------------------------------------------- /grpc-example-server/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Scripts/GRPCBestHttpHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Net.Http; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using BestHTTP; 9 | using BestHTTP.Connections; 10 | using BestHTTP.Connections.HTTP2; 11 | 12 | namespace GRPC.NET 13 | { 14 | public class GRPCBestHttpHandler : HttpClientHandler 15 | { 16 | private static readonly string ContentType = "Content-Type"; 17 | 18 | /** 19 | * This function is called by gRPC when establishing a new channel to a gRPC server. 20 | * We are mapping HttpRequestMessage and HttpResponseMessage to its BestHTTP equivalent. 21 | */ 22 | protected override Task SendAsync(HttpRequestMessage grpcRequest, CancellationToken cancellationToken) 23 | { 24 | if (grpcRequest.Method != HttpMethod.Post) 25 | throw new NotSupportedException("gRPC only supports POST method."); 26 | 27 | // 28 | // Create outgoing HTTP2 request 29 | // 30 | HTTPRequest bestRequest = new HTTPRequest(grpcRequest.RequestUri, HTTPMethods.Post); 31 | 32 | // Disable internal retry 33 | bestRequest.MaxRetries = 0; 34 | 35 | // 36 | // Prepare outgoing HEADER and HttpContent 37 | // 38 | 39 | // Copy over all request headers 40 | foreach (var kv in grpcRequest.Headers) 41 | { 42 | foreach (var headerItem in kv.Value) bestRequest.AddHeader(kv.Key, headerItem); 43 | } 44 | 45 | // Contained in grpcRequest.Content.Headers but we set it hardcoded here 46 | bestRequest.AddHeader(ContentType, "application/grpc"); 47 | 48 | 49 | // Create outgoing data stream 50 | PushPullStream outgoingDataStream = new PushPullStream("outgoing"); 51 | 52 | // BestHTTP does not perform blocking reads. Instead it will expect -1 to be returned if no data is yet 53 | // available. Each time the internal loop is triggered it will try to read from the stream again to check 54 | // if there is new data available. 55 | // This is why we have to trigger Http2Handler on each new DATA package when the stream was flushed. 56 | outgoingDataStream.NonBlockingRead = true; 57 | bestRequest.UploadStream = outgoingDataStream; 58 | 59 | // StreamFragmentSize will be ignored and downloaded chunks will be sent immediately. 60 | bestRequest.StreamChunksImmediately = true; 61 | bestRequest.ReadBufferSizeOverride = 0; 62 | bestRequest.UseUploadStreamLength = false; // avoid sending content-length=0 (EOF) 63 | 64 | // CopyToAsync can replace the underlying Stream of a HttpContent object as long as no write() call 65 | // was yet initiated/completed on it. This will allow us to provide our own Stream to gRPC on which 66 | // it then performs its writes on, allowing us to act on these calls. 67 | grpcRequest.Content.CopyToAsync(outgoingDataStream); 68 | 69 | // Each time gRPC flushes the stream the Http2Handler will have to be triggered so it writes the available 70 | // DATA package to the wire. But to get the http2Handler object we have to have an active HTTP2 connection 71 | // available first so we wait for the headers to be sent to set the OnStreamFlushCallback. 72 | bestRequest.OnBeforeHeaderSend += _ => 73 | { 74 | string connectionKey = BestHTTP.Core.HostDefinition.GetKeyFor(grpcRequest.RequestUri, null); 75 | HTTPConnection httpConnection = BestHTTP.Core.HostManager 76 | .GetHost(grpcRequest.RequestUri.Host) 77 | .GetHostDefinition(connectionKey).Find(c => (c as HTTPConnection)?.requestHandler != null) as HTTPConnection; 78 | HTTP2Handler http2Handler = httpConnection?.requestHandler as HTTP2Handler; 79 | 80 | // Signal Http2Handler each time a new DATA package should be written to the wire 81 | outgoingDataStream.OnStreamFlushCallback += () => http2Handler?.SignalRunnerThread(); 82 | 83 | // This will complete when we reached EOS of the gRPC request 84 | grpcRequest.Content.ReadAsStreamAsync().ContinueWith(_ => 85 | { 86 | outgoingDataStream.Close(); 87 | }, cancellationToken); 88 | }; 89 | 90 | 91 | // 92 | // Prepare HttpResponseMessage mapping incoming HEADER and DATA to forward to gRPC 93 | // 94 | TaskCompletionSource grpcResponseTask = new TaskCompletionSource(); 95 | 96 | PushPullStream incomingDataStream = new PushPullStream("incoming"); 97 | HttpResponseMessage grpcResponseMessage = new HttpResponseMessage 98 | { 99 | RequestMessage = grpcRequest, 100 | // HttpContent wrapper around incoming DATA package stream 101 | Content = new ServerStreamHttpContent(incomingDataStream) 102 | }; 103 | 104 | // Write incoming headers OR trailing headers 105 | bool isHeader = true; 106 | bestRequest.OnHeadersReceived += (HTTPRequest _, HTTPResponse response, Dictionary> headers) => 107 | { 108 | // If we haven't received headers yet and grpc-status is included then its a trailers only response. 109 | bool trailersOnly = isHeader && headers.Keys.Contains("grpc-status"); 110 | 111 | // https://github.com/grpc/grpc-dotnet/blob/master/src/Grpc.Net.Client/Internal/GrpcCall.cs#L311 112 | foreach (KeyValuePair> kvp in headers) 113 | { 114 | // Content.Headers is used for content-type and other well known headers, always populate them 115 | grpcResponseMessage.Content.Headers.TryAddWithoutValidation(kvp.Key, kvp.Value); 116 | 117 | // Trailer only responses have all the headers in both, metadata and trailers. 118 | // If we add them to Headers, gRPC will take care of that for us. In any other case add them 119 | // to the TrailingHeaders. 120 | if (isHeader || trailersOnly) 121 | { 122 | // Add headers 123 | grpcResponseMessage.Headers.TryAddWithoutValidation(kvp.Key, kvp.Value); 124 | } 125 | else 126 | { 127 | grpcResponseMessage.TrailingHeaders.TryAddWithoutValidation(kvp.Key, kvp.Value); 128 | } 129 | } 130 | 131 | // Copy HTTP status fields 132 | if (isHeader) 133 | { 134 | grpcResponseMessage.ReasonPhrase = response.Message; 135 | grpcResponseMessage.StatusCode = (HttpStatusCode) response.StatusCode; 136 | grpcResponseMessage.Version = new Version(response.VersionMajor, response.VersionMinor); 137 | } 138 | 139 | // Complete Response on first HEADER package (before DATA arrived) to trigger gRPC 140 | if (!grpcResponseTask.Task.IsCompleted) 141 | grpcResponseTask.SetResult(grpcResponseMessage); 142 | 143 | // From now on everything we get are trailers 144 | isHeader = false; 145 | }; 146 | 147 | 148 | // For each incoming DATA package we write data trough to gRPC 149 | bestRequest.OnStreamingData += (_, _, fragment, length) => 150 | { 151 | // Write incoming DATA package and immediately flush 152 | incomingDataStream.Write(fragment, 0, length); 153 | incomingDataStream.Flush(); 154 | return true; 155 | }; 156 | 157 | // When gRPC call is canceled by the application we abort the request 158 | var cancellationTokenRegistration = cancellationToken.Register(() => 159 | { 160 | bestRequest.Abort(); 161 | }); 162 | 163 | bestRequest.Callback += (request, response) => 164 | { 165 | // We might have to handle an error when his callback is called after the request completed 166 | if (request.State != HTTPRequestStates.Finished) 167 | { 168 | var ex = request.Exception ?? new Exception($"Unknown error while processing grpc req/resp (state={request.State})."); 169 | 170 | // If the call was aborted instead we set the exception accordingly 171 | if (request.State == HTTPRequestStates.Aborted) 172 | { 173 | ex = new Exception("gRPC call aborted by client."); 174 | } 175 | 176 | // If response IS NOT set we never got a HEADER response (arrives before any DATA) 177 | if (!grpcResponseTask.Task.IsCompleted) 178 | { 179 | grpcResponseTask.SetException(ex); 180 | } 181 | // If response IS set we instead throw an exception in the blocking read() and write() thread 182 | else 183 | { 184 | incomingDataStream.CloseWithException(ex); 185 | } 186 | } 187 | // but in any case we want to close the stream to indicate to grpc that we are done 188 | else 189 | { 190 | incomingDataStream.Close(); 191 | } 192 | 193 | // Unregister cancellation token once we are done 194 | cancellationTokenRegistration.Dispose(); 195 | }; 196 | 197 | // Finally send request to initiate transfer 198 | bestRequest.Send(); 199 | 200 | return grpcResponseTask.Task; 201 | } 202 | } 203 | } -------------------------------------------------------------------------------- /Assets/GRPC.NET/Example/GRPCExampleTestScene.unity: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!29 &1 4 | OcclusionCullingSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_OcclusionBakeSettings: 8 | smallestOccluder: 5 9 | smallestHole: 0.25 10 | backfaceThreshold: 100 11 | m_SceneGUID: 00000000000000000000000000000000 12 | m_OcclusionCullingData: {fileID: 0} 13 | --- !u!104 &2 14 | RenderSettings: 15 | m_ObjectHideFlags: 0 16 | serializedVersion: 9 17 | m_Fog: 0 18 | m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} 19 | m_FogMode: 3 20 | m_FogDensity: 0.01 21 | m_LinearFogStart: 0 22 | m_LinearFogEnd: 300 23 | m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} 24 | m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} 25 | m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} 26 | m_AmbientIntensity: 1 27 | m_AmbientMode: 0 28 | m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} 29 | m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} 30 | m_HaloStrength: 0.5 31 | m_FlareStrength: 1 32 | m_FlareFadeSpeed: 3 33 | m_HaloTexture: {fileID: 0} 34 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 35 | m_DefaultReflectionMode: 0 36 | m_DefaultReflectionResolution: 128 37 | m_ReflectionBounces: 1 38 | m_ReflectionIntensity: 1 39 | m_CustomReflection: {fileID: 0} 40 | m_Sun: {fileID: 0} 41 | m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} 42 | m_UseRadianceAmbientProbe: 0 43 | --- !u!157 &3 44 | LightmapSettings: 45 | m_ObjectHideFlags: 0 46 | serializedVersion: 12 47 | m_GIWorkflowMode: 1 48 | m_GISettings: 49 | serializedVersion: 2 50 | m_BounceScale: 1 51 | m_IndirectOutputScale: 1 52 | m_AlbedoBoost: 1 53 | m_EnvironmentLightingMode: 0 54 | m_EnableBakedLightmaps: 1 55 | m_EnableRealtimeLightmaps: 0 56 | m_LightmapEditorSettings: 57 | serializedVersion: 12 58 | m_Resolution: 2 59 | m_BakeResolution: 40 60 | m_AtlasSize: 1024 61 | m_AO: 0 62 | m_AOMaxDistance: 1 63 | m_CompAOExponent: 1 64 | m_CompAOExponentDirect: 0 65 | m_ExtractAmbientOcclusion: 0 66 | m_Padding: 2 67 | m_LightmapParameters: {fileID: 0} 68 | m_LightmapsBakeMode: 1 69 | m_TextureCompression: 1 70 | m_FinalGather: 0 71 | m_FinalGatherFiltering: 1 72 | m_FinalGatherRayCount: 256 73 | m_ReflectionCompression: 2 74 | m_MixedBakeMode: 2 75 | m_BakeBackend: 1 76 | m_PVRSampling: 1 77 | m_PVRDirectSampleCount: 32 78 | m_PVRSampleCount: 512 79 | m_PVRBounces: 2 80 | m_PVREnvironmentSampleCount: 256 81 | m_PVREnvironmentReferencePointCount: 2048 82 | m_PVRFilteringMode: 1 83 | m_PVRDenoiserTypeDirect: 1 84 | m_PVRDenoiserTypeIndirect: 1 85 | m_PVRDenoiserTypeAO: 1 86 | m_PVRFilterTypeDirect: 0 87 | m_PVRFilterTypeIndirect: 0 88 | m_PVRFilterTypeAO: 0 89 | m_PVREnvironmentMIS: 1 90 | m_PVRCulling: 1 91 | m_PVRFilteringGaussRadiusDirect: 1 92 | m_PVRFilteringGaussRadiusIndirect: 5 93 | m_PVRFilteringGaussRadiusAO: 2 94 | m_PVRFilteringAtrousPositionSigmaDirect: 0.5 95 | m_PVRFilteringAtrousPositionSigmaIndirect: 2 96 | m_PVRFilteringAtrousPositionSigmaAO: 1 97 | m_ExportTrainingData: 0 98 | m_TrainingDataDestination: TrainingData 99 | m_LightProbeSampleCountMultiplier: 4 100 | m_LightingDataAsset: {fileID: 0} 101 | m_LightingSettings: {fileID: 0} 102 | --- !u!196 &4 103 | NavMeshSettings: 104 | serializedVersion: 2 105 | m_ObjectHideFlags: 0 106 | m_BuildSettings: 107 | serializedVersion: 2 108 | agentTypeID: 0 109 | agentRadius: 0.5 110 | agentHeight: 2 111 | agentSlope: 45 112 | agentClimb: 0.4 113 | ledgeDropHeight: 0 114 | maxJumpAcrossDistance: 0 115 | minRegionArea: 2 116 | manualCellSize: 0 117 | cellSize: 0.16666667 118 | manualTileSize: 0 119 | tileSize: 256 120 | accuratePlacement: 0 121 | maxJobWorkers: 0 122 | preserveTilesOutsideBounds: 0 123 | debug: 124 | m_Flags: 0 125 | m_NavMeshData: {fileID: 0} 126 | --- !u!1 &824283419 127 | GameObject: 128 | m_ObjectHideFlags: 0 129 | m_CorrespondingSourceObject: {fileID: 0} 130 | m_PrefabInstance: {fileID: 0} 131 | m_PrefabAsset: {fileID: 0} 132 | serializedVersion: 6 133 | m_Component: 134 | - component: {fileID: 824283422} 135 | - component: {fileID: 824283421} 136 | - component: {fileID: 824283420} 137 | m_Layer: 0 138 | m_Name: Main Camera 139 | m_TagString: MainCamera 140 | m_Icon: {fileID: 0} 141 | m_NavMeshLayer: 0 142 | m_StaticEditorFlags: 0 143 | m_IsActive: 1 144 | --- !u!81 &824283420 145 | AudioListener: 146 | m_ObjectHideFlags: 0 147 | m_CorrespondingSourceObject: {fileID: 0} 148 | m_PrefabInstance: {fileID: 0} 149 | m_PrefabAsset: {fileID: 0} 150 | m_GameObject: {fileID: 824283419} 151 | m_Enabled: 1 152 | --- !u!20 &824283421 153 | Camera: 154 | m_ObjectHideFlags: 0 155 | m_CorrespondingSourceObject: {fileID: 0} 156 | m_PrefabInstance: {fileID: 0} 157 | m_PrefabAsset: {fileID: 0} 158 | m_GameObject: {fileID: 824283419} 159 | m_Enabled: 1 160 | serializedVersion: 2 161 | m_ClearFlags: 2 162 | m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} 163 | m_projectionMatrixMode: 1 164 | m_GateFitMode: 2 165 | m_FOVAxisMode: 0 166 | m_SensorSize: {x: 36, y: 24} 167 | m_LensShift: {x: 0, y: 0} 168 | m_FocalLength: 50 169 | m_NormalizedViewPortRect: 170 | serializedVersion: 2 171 | x: 0 172 | y: 0 173 | width: 1 174 | height: 1 175 | near clip plane: 0.3 176 | far clip plane: 1000 177 | field of view: 60 178 | orthographic: 0 179 | orthographic size: 5 180 | m_Depth: -1 181 | m_CullingMask: 182 | serializedVersion: 2 183 | m_Bits: 4294967295 184 | m_RenderingPath: -1 185 | m_TargetTexture: {fileID: 0} 186 | m_TargetDisplay: 0 187 | m_TargetEye: 3 188 | m_HDR: 1 189 | m_AllowMSAA: 1 190 | m_AllowDynamicResolution: 0 191 | m_ForceIntoRT: 0 192 | m_OcclusionCulling: 1 193 | m_StereoConvergence: 10 194 | m_StereoSeparation: 0.022 195 | --- !u!4 &824283422 196 | Transform: 197 | m_ObjectHideFlags: 0 198 | m_CorrespondingSourceObject: {fileID: 0} 199 | m_PrefabInstance: {fileID: 0} 200 | m_PrefabAsset: {fileID: 0} 201 | m_GameObject: {fileID: 824283419} 202 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 203 | m_LocalPosition: {x: 0, y: 1, z: -10} 204 | m_LocalScale: {x: 1, y: 1, z: 1} 205 | m_ConstrainProportionsScale: 0 206 | m_Children: [] 207 | m_Father: {fileID: 0} 208 | m_RootOrder: 0 209 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 210 | --- !u!1 &1434432829 211 | GameObject: 212 | m_ObjectHideFlags: 0 213 | m_CorrespondingSourceObject: {fileID: 0} 214 | m_PrefabInstance: {fileID: 0} 215 | m_PrefabAsset: {fileID: 0} 216 | serializedVersion: 6 217 | m_Component: 218 | - component: {fileID: 1434432831} 219 | - component: {fileID: 1434432833} 220 | - component: {fileID: 1434432832} 221 | m_Layer: 0 222 | m_Name: Controller 223 | m_TagString: Untagged 224 | m_Icon: {fileID: 0} 225 | m_NavMeshLayer: 0 226 | m_StaticEditorFlags: 0 227 | m_IsActive: 1 228 | --- !u!4 &1434432831 229 | Transform: 230 | m_ObjectHideFlags: 0 231 | m_CorrespondingSourceObject: {fileID: 0} 232 | m_PrefabInstance: {fileID: 0} 233 | m_PrefabAsset: {fileID: 0} 234 | m_GameObject: {fileID: 1434432829} 235 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 236 | m_LocalPosition: {x: 0, y: 0, z: 0} 237 | m_LocalScale: {x: 1, y: 1, z: 1} 238 | m_ConstrainProportionsScale: 0 239 | m_Children: [] 240 | m_Father: {fileID: 0} 241 | m_RootOrder: 2 242 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 243 | --- !u!114 &1434432832 244 | MonoBehaviour: 245 | m_ObjectHideFlags: 0 246 | m_CorrespondingSourceObject: {fileID: 0} 247 | m_PrefabInstance: {fileID: 0} 248 | m_PrefabAsset: {fileID: 0} 249 | m_GameObject: {fileID: 1434432829} 250 | m_Enabled: 1 251 | m_EditorHideFlags: 0 252 | m_Script: {fileID: 11500000, guid: a3ee91ccdea477745bf75a26256ca056, type: 3} 253 | m_Name: 254 | m_EditorClassIdentifier: 255 | --- !u!114 &1434432833 256 | MonoBehaviour: 257 | m_ObjectHideFlags: 0 258 | m_CorrespondingSourceObject: {fileID: 0} 259 | m_PrefabInstance: {fileID: 0} 260 | m_PrefabAsset: {fileID: 0} 261 | m_GameObject: {fileID: 1434432829} 262 | m_Enabled: 1 263 | m_EditorHideFlags: 0 264 | m_Script: {fileID: 11500000, guid: fe10f905eef63224f97c892c491430ac, type: 3} 265 | m_Name: 266 | m_EditorClassIdentifier: 267 | --- !u!1 &1797761636 268 | GameObject: 269 | m_ObjectHideFlags: 0 270 | m_CorrespondingSourceObject: {fileID: 0} 271 | m_PrefabInstance: {fileID: 0} 272 | m_PrefabAsset: {fileID: 0} 273 | serializedVersion: 6 274 | m_Component: 275 | - component: {fileID: 1797761638} 276 | - component: {fileID: 1797761637} 277 | m_Layer: 0 278 | m_Name: Directional Light 279 | m_TagString: Untagged 280 | m_Icon: {fileID: 0} 281 | m_NavMeshLayer: 0 282 | m_StaticEditorFlags: 0 283 | m_IsActive: 1 284 | --- !u!108 &1797761637 285 | Light: 286 | m_ObjectHideFlags: 0 287 | m_CorrespondingSourceObject: {fileID: 0} 288 | m_PrefabInstance: {fileID: 0} 289 | m_PrefabAsset: {fileID: 0} 290 | m_GameObject: {fileID: 1797761636} 291 | m_Enabled: 1 292 | serializedVersion: 10 293 | m_Type: 1 294 | m_Shape: 0 295 | m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} 296 | m_Intensity: 1 297 | m_Range: 10 298 | m_SpotAngle: 30 299 | m_InnerSpotAngle: 21.80208 300 | m_CookieSize: 10 301 | m_Shadows: 302 | m_Type: 2 303 | m_Resolution: -1 304 | m_CustomResolution: -1 305 | m_Strength: 1 306 | m_Bias: 0.05 307 | m_NormalBias: 0.4 308 | m_NearPlane: 0.2 309 | m_CullingMatrixOverride: 310 | e00: 1 311 | e01: 0 312 | e02: 0 313 | e03: 0 314 | e10: 0 315 | e11: 1 316 | e12: 0 317 | e13: 0 318 | e20: 0 319 | e21: 0 320 | e22: 1 321 | e23: 0 322 | e30: 0 323 | e31: 0 324 | e32: 0 325 | e33: 1 326 | m_UseCullingMatrixOverride: 0 327 | m_Cookie: {fileID: 0} 328 | m_DrawHalo: 0 329 | m_Flare: {fileID: 0} 330 | m_RenderMode: 0 331 | m_CullingMask: 332 | serializedVersion: 2 333 | m_Bits: 4294967295 334 | m_RenderingLayerMask: 1 335 | m_Lightmapping: 4 336 | m_LightShadowCasterMode: 0 337 | m_AreaSize: {x: 1, y: 1} 338 | m_BounceIntensity: 1 339 | m_ColorTemperature: 6570 340 | m_UseColorTemperature: 0 341 | m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} 342 | m_UseBoundingSphereOverride: 0 343 | m_UseViewFrustumForShadowCasterCull: 1 344 | m_ShadowRadius: 0 345 | m_ShadowAngle: 0 346 | --- !u!4 &1797761638 347 | Transform: 348 | m_ObjectHideFlags: 0 349 | m_CorrespondingSourceObject: {fileID: 0} 350 | m_PrefabInstance: {fileID: 0} 351 | m_PrefabAsset: {fileID: 0} 352 | m_GameObject: {fileID: 1797761636} 353 | m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} 354 | m_LocalPosition: {x: 0, y: 3, z: 0} 355 | m_LocalScale: {x: 1, y: 1, z: 1} 356 | m_ConstrainProportionsScale: 0 357 | m_Children: [] 358 | m_Father: {fileID: 0} 359 | m_RootOrder: 1 360 | m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} 361 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Example/Proto/HelloGrpc.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated by the protocol buffer compiler. DO NOT EDIT! 3 | // source: hello.proto 4 | // 5 | #pragma warning disable 0414, 1591, 8981 6 | #region Designer generated code 7 | 8 | using grpc = global::Grpc.Core; 9 | 10 | namespace TestProto { 11 | public static partial class HelloWorldService 12 | { 13 | static readonly string __ServiceName = "HelloWorldService"; 14 | 15 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 16 | static void __Helper_SerializeMessage(global::Google.Protobuf.IMessage message, grpc::SerializationContext context) 17 | { 18 | #if !GRPC_DISABLE_PROTOBUF_BUFFER_SERIALIZATION 19 | if (message is global::Google.Protobuf.IBufferMessage) 20 | { 21 | context.SetPayloadLength(message.CalculateSize()); 22 | global::Google.Protobuf.MessageExtensions.WriteTo(message, context.GetBufferWriter()); 23 | context.Complete(); 24 | return; 25 | } 26 | #endif 27 | context.Complete(global::Google.Protobuf.MessageExtensions.ToByteArray(message)); 28 | } 29 | 30 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 31 | static class __Helper_MessageCache 32 | { 33 | public static readonly bool IsBufferMessage = global::System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(global::Google.Protobuf.IBufferMessage)).IsAssignableFrom(typeof(T)); 34 | } 35 | 36 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 37 | static T __Helper_DeserializeMessage(grpc::DeserializationContext context, global::Google.Protobuf.MessageParser parser) where T : global::Google.Protobuf.IMessage 38 | { 39 | #if !GRPC_DISABLE_PROTOBUF_BUFFER_SERIALIZATION 40 | if (__Helper_MessageCache.IsBufferMessage) 41 | { 42 | return parser.ParseFrom(context.PayloadAsReadOnlySequence()); 43 | } 44 | #endif 45 | return parser.ParseFrom(context.PayloadAsNewBuffer()); 46 | } 47 | 48 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 49 | static readonly grpc::Marshaller __Marshaller_HelloRequest = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::TestProto.HelloRequest.Parser)); 50 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 51 | static readonly grpc::Marshaller __Marshaller_HelloResponse = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::TestProto.HelloResponse.Parser)); 52 | 53 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 54 | static readonly grpc::Method __Method_hello = new grpc::Method( 55 | grpc::MethodType.Unary, 56 | __ServiceName, 57 | "hello", 58 | __Marshaller_HelloRequest, 59 | __Marshaller_HelloResponse); 60 | 61 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 62 | static readonly grpc::Method __Method_helloServer = new grpc::Method( 63 | grpc::MethodType.ServerStreaming, 64 | __ServiceName, 65 | "helloServer", 66 | __Marshaller_HelloRequest, 67 | __Marshaller_HelloResponse); 68 | 69 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 70 | static readonly grpc::Method __Method_helloClient = new grpc::Method( 71 | grpc::MethodType.ClientStreaming, 72 | __ServiceName, 73 | "helloClient", 74 | __Marshaller_HelloRequest, 75 | __Marshaller_HelloResponse); 76 | 77 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 78 | static readonly grpc::Method __Method_helloBoth = new grpc::Method( 79 | grpc::MethodType.DuplexStreaming, 80 | __ServiceName, 81 | "helloBoth", 82 | __Marshaller_HelloRequest, 83 | __Marshaller_HelloResponse); 84 | 85 | /// Service descriptor 86 | public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor 87 | { 88 | get { return global::TestProto.HelloReflection.Descriptor.Services[0]; } 89 | } 90 | 91 | /// Base class for server-side implementations of HelloWorldService 92 | [grpc::BindServiceMethod(typeof(HelloWorldService), "BindService")] 93 | public abstract partial class HelloWorldServiceBase 94 | { 95 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 96 | public virtual global::System.Threading.Tasks.Task hello(global::TestProto.HelloRequest request, grpc::ServerCallContext context) 97 | { 98 | throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); 99 | } 100 | 101 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 102 | public virtual global::System.Threading.Tasks.Task helloServer(global::TestProto.HelloRequest request, grpc::IServerStreamWriter responseStream, grpc::ServerCallContext context) 103 | { 104 | throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); 105 | } 106 | 107 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 108 | public virtual global::System.Threading.Tasks.Task helloClient(grpc::IAsyncStreamReader requestStream, grpc::ServerCallContext context) 109 | { 110 | throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); 111 | } 112 | 113 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 114 | public virtual global::System.Threading.Tasks.Task helloBoth(grpc::IAsyncStreamReader requestStream, grpc::IServerStreamWriter responseStream, grpc::ServerCallContext context) 115 | { 116 | throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); 117 | } 118 | 119 | } 120 | 121 | /// Client for HelloWorldService 122 | public partial class HelloWorldServiceClient : grpc::ClientBase 123 | { 124 | /// Creates a new client for HelloWorldService 125 | /// The channel to use to make remote calls. 126 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 127 | public HelloWorldServiceClient(grpc::ChannelBase channel) : base(channel) 128 | { 129 | } 130 | /// Creates a new client for HelloWorldService that uses a custom CallInvoker. 131 | /// The callInvoker to use to make remote calls. 132 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 133 | public HelloWorldServiceClient(grpc::CallInvoker callInvoker) : base(callInvoker) 134 | { 135 | } 136 | /// Protected parameterless constructor to allow creation of test doubles. 137 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 138 | protected HelloWorldServiceClient() : base() 139 | { 140 | } 141 | /// Protected constructor to allow creation of configured clients. 142 | /// The client configuration. 143 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 144 | protected HelloWorldServiceClient(ClientBaseConfiguration configuration) : base(configuration) 145 | { 146 | } 147 | 148 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 149 | public virtual global::TestProto.HelloResponse hello(global::TestProto.HelloRequest request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) 150 | { 151 | return hello(request, new grpc::CallOptions(headers, deadline, cancellationToken)); 152 | } 153 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 154 | public virtual global::TestProto.HelloResponse hello(global::TestProto.HelloRequest request, grpc::CallOptions options) 155 | { 156 | return CallInvoker.BlockingUnaryCall(__Method_hello, null, options, request); 157 | } 158 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 159 | public virtual grpc::AsyncUnaryCall helloAsync(global::TestProto.HelloRequest request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) 160 | { 161 | return helloAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken)); 162 | } 163 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 164 | public virtual grpc::AsyncUnaryCall helloAsync(global::TestProto.HelloRequest request, grpc::CallOptions options) 165 | { 166 | return CallInvoker.AsyncUnaryCall(__Method_hello, null, options, request); 167 | } 168 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 169 | public virtual grpc::AsyncServerStreamingCall helloServer(global::TestProto.HelloRequest request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) 170 | { 171 | return helloServer(request, new grpc::CallOptions(headers, deadline, cancellationToken)); 172 | } 173 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 174 | public virtual grpc::AsyncServerStreamingCall helloServer(global::TestProto.HelloRequest request, grpc::CallOptions options) 175 | { 176 | return CallInvoker.AsyncServerStreamingCall(__Method_helloServer, null, options, request); 177 | } 178 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 179 | public virtual grpc::AsyncClientStreamingCall helloClient(grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) 180 | { 181 | return helloClient(new grpc::CallOptions(headers, deadline, cancellationToken)); 182 | } 183 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 184 | public virtual grpc::AsyncClientStreamingCall helloClient(grpc::CallOptions options) 185 | { 186 | return CallInvoker.AsyncClientStreamingCall(__Method_helloClient, null, options); 187 | } 188 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 189 | public virtual grpc::AsyncDuplexStreamingCall helloBoth(grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) 190 | { 191 | return helloBoth(new grpc::CallOptions(headers, deadline, cancellationToken)); 192 | } 193 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 194 | public virtual grpc::AsyncDuplexStreamingCall helloBoth(grpc::CallOptions options) 195 | { 196 | return CallInvoker.AsyncDuplexStreamingCall(__Method_helloBoth, null, options); 197 | } 198 | /// Creates a new instance of client from given ClientBaseConfiguration. 199 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 200 | protected override HelloWorldServiceClient NewInstance(ClientBaseConfiguration configuration) 201 | { 202 | return new HelloWorldServiceClient(configuration); 203 | } 204 | } 205 | 206 | /// Creates service definition that can be registered with a server 207 | /// An object implementing the server-side handling logic. 208 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 209 | public static grpc::ServerServiceDefinition BindService(HelloWorldServiceBase serviceImpl) 210 | { 211 | return grpc::ServerServiceDefinition.CreateBuilder() 212 | .AddMethod(__Method_hello, serviceImpl.hello) 213 | .AddMethod(__Method_helloServer, serviceImpl.helloServer) 214 | .AddMethod(__Method_helloClient, serviceImpl.helloClient) 215 | .AddMethod(__Method_helloBoth, serviceImpl.helloBoth).Build(); 216 | } 217 | 218 | /// Register service method with a service binder with or without implementation. Useful when customizing the service binding logic. 219 | /// Note: this method is part of an experimental API that can change or be removed without any prior notice. 220 | /// Service methods will be bound by calling AddMethod on this object. 221 | /// An object implementing the server-side handling logic. 222 | [global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)] 223 | public static void BindService(grpc::ServiceBinderBase serviceBinder, HelloWorldServiceBase serviceImpl) 224 | { 225 | serviceBinder.AddMethod(__Method_hello, serviceImpl == null ? null : new grpc::UnaryServerMethod(serviceImpl.hello)); 226 | serviceBinder.AddMethod(__Method_helloServer, serviceImpl == null ? null : new grpc::ServerStreamingServerMethod(serviceImpl.helloServer)); 227 | serviceBinder.AddMethod(__Method_helloClient, serviceImpl == null ? null : new grpc::ClientStreamingServerMethod(serviceImpl.helloClient)); 228 | serviceBinder.AddMethod(__Method_helloBoth, serviceImpl == null ? null : new grpc::DuplexStreamingServerMethod(serviceImpl.helloBoth)); 229 | } 230 | 231 | } 232 | } 233 | #endregion 234 | -------------------------------------------------------------------------------- /Third-Party Notices.txt: -------------------------------------------------------------------------------- 1 | This asset contains products with the following licenses: 2 | 3 | (a) System.Diagnostics.DiagnosticSource.dll - MIT 4 | (b) Microsoft.Extensions.Logging.Abstractions.dll - MIT 5 | (c) System.Runtime.CompilerServices.Unsafe.dll - MIT 6 | -------------- 7 | The MIT License (MIT) 8 | 9 | Copyright (c) .NET Foundation and Contributors 10 | 11 | All rights reserved. 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in all 21 | copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 29 | SOFTWARE. 30 | 31 | (d) Google.Protobuf.dll - BSD-3-Clause 32 | -------------- 33 | Copyright 2008 Google Inc. All rights reserved. 34 | 35 | Redistribution and use in source and binary forms, with or without 36 | modification, are permitted provided that the following conditions are 37 | met: 38 | 39 | * Redistributions of source code must retain the above copyright 40 | notice, this list of conditions and the following disclaimer. 41 | * Redistributions in binary form must reproduce the above 42 | copyright notice, this list of conditions and the following disclaimer 43 | in the documentation and/or other materials provided with the 44 | distribution. 45 | * Neither the name of Google Inc. nor the names of its 46 | contributors may be used to endorse or promote products derived from 47 | this software without specific prior written permission. 48 | 49 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | Code generated by the Protocol Buffer compiler is owned by the owner 62 | of the input file used when generating it. This code is not 63 | standalone and requires a support library to be linked with it. This 64 | support library is itself covered by the above license. 65 | 66 | (e) grpc-dotnet (Grpc.Core.Api.dll, Grpc.Net.Client.dll, Grpc.Net.Common.dll) - Apache-2.0 67 | -------------- 68 | Apache License 69 | Version 2.0, January 2004 70 | http://www.apache.org/licenses/ 71 | 72 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 73 | 74 | 1. Definitions. 75 | 76 | "License" shall mean the terms and conditions for use, reproduction, 77 | and distribution as defined by Sections 1 through 9 of this document. 78 | 79 | "Licensor" shall mean the copyright owner or entity authorized by 80 | the copyright owner that is granting the License. 81 | 82 | "Legal Entity" shall mean the union of the acting entity and all 83 | other entities that control, are controlled by, or are under common 84 | control with that entity. For the purposes of this definition, 85 | "control" means (i) the power, direct or indirect, to cause the 86 | direction or management of such entity, whether by contract or 87 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 88 | outstanding shares, or (iii) beneficial ownership of such entity. 89 | 90 | "You" (or "Your") shall mean an individual or Legal Entity 91 | exercising permissions granted by this License. 92 | 93 | "Source" form shall mean the preferred form for making modifications, 94 | including but not limited to software source code, documentation 95 | source, and configuration files. 96 | 97 | "Object" form shall mean any form resulting from mechanical 98 | transformation or translation of a Source form, including but 99 | not limited to compiled object code, generated documentation, 100 | and conversions to other media types. 101 | 102 | "Work" shall mean the work of authorship, whether in Source or 103 | Object form, made available under the License, as indicated by a 104 | copyright notice that is included in or attached to the work 105 | (an example is provided in the Appendix below). 106 | 107 | "Derivative Works" shall mean any work, whether in Source or Object 108 | form, that is based on (or derived from) the Work and for which the 109 | editorial revisions, annotations, elaborations, or other modifications 110 | represent, as a whole, an original work of authorship. For the purposes 111 | of this License, Derivative Works shall not include works that remain 112 | separable from, or merely link (or bind by name) to the interfaces of, 113 | the Work and Derivative Works thereof. 114 | 115 | "Contribution" shall mean any work of authorship, including 116 | the original version of the Work and any modifications or additions 117 | to that Work or Derivative Works thereof, that is intentionally 118 | submitted to Licensor for inclusion in the Work by the copyright owner 119 | or by an individual or Legal Entity authorized to submit on behalf of 120 | the copyright owner. For the purposes of this definition, "submitted" 121 | means any form of electronic, verbal, or written communication sent 122 | to the Licensor or its representatives, including but not limited to 123 | communication on electronic mailing lists, source code control systems, 124 | and issue tracking systems that are managed by, or on behalf of, the 125 | Licensor for the purpose of discussing and improving the Work, but 126 | excluding communication that is conspicuously marked or otherwise 127 | designated in writing by the copyright owner as "Not a Contribution." 128 | 129 | "Contributor" shall mean Licensor and any individual or Legal Entity 130 | on behalf of whom a Contribution has been received by Licensor and 131 | subsequently incorporated within the Work. 132 | 133 | 2. Grant of Copyright License. Subject to the terms and conditions of 134 | this License, each Contributor hereby grants to You a perpetual, 135 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 136 | copyright license to reproduce, prepare Derivative Works of, 137 | publicly display, publicly perform, sublicense, and distribute the 138 | Work and such Derivative Works in Source or Object form. 139 | 140 | 3. Grant of Patent License. Subject to the terms and conditions of 141 | this License, each Contributor hereby grants to You a perpetual, 142 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 143 | (except as stated in this section) patent license to make, have made, 144 | use, offer to sell, sell, import, and otherwise transfer the Work, 145 | where such license applies only to those patent claims licensable 146 | by such Contributor that are necessarily infringed by their 147 | Contribution(s) alone or by combination of their Contribution(s) 148 | with the Work to which such Contribution(s) was submitted. If You 149 | institute patent litigation against any entity (including a 150 | cross-claim or counterclaim in a lawsuit) alleging that the Work 151 | or a Contribution incorporated within the Work constitutes direct 152 | or contributory patent infringement, then any patent licenses 153 | granted to You under this License for that Work shall terminate 154 | as of the date such litigation is filed. 155 | 156 | 4. Redistribution. You may reproduce and distribute copies of the 157 | Work or Derivative Works thereof in any medium, with or without 158 | modifications, and in Source or Object form, provided that You 159 | meet the following conditions: 160 | 161 | (a) You must give any other recipients of the Work or 162 | Derivative Works a copy of this License; and 163 | 164 | (b) You must cause any modified files to carry prominent notices 165 | stating that You changed the files; and 166 | 167 | (c) You must retain, in the Source form of any Derivative Works 168 | that You distribute, all copyright, patent, trademark, and 169 | attribution notices from the Source form of the Work, 170 | excluding those notices that do not pertain to any part of 171 | the Derivative Works; and 172 | 173 | (d) If the Work includes a "NOTICE" text file as part of its 174 | distribution, then any Derivative Works that You distribute must 175 | include a readable copy of the attribution notices contained 176 | within such NOTICE file, excluding those notices that do not 177 | pertain to any part of the Derivative Works, in at least one 178 | of the following places: within a NOTICE text file distributed 179 | as part of the Derivative Works; within the Source form or 180 | documentation, if provided along with the Derivative Works; or, 181 | within a display generated by the Derivative Works, if and 182 | wherever such third-party notices normally appear. The contents 183 | of the NOTICE file are for informational purposes only and 184 | do not modify the License. You may add Your own attribution 185 | notices within Derivative Works that You distribute, alongside 186 | or as an addendum to the NOTICE text from the Work, provided 187 | that such additional attribution notices cannot be construed 188 | as modifying the License. 189 | 190 | You may add Your own copyright statement to Your modifications and 191 | may provide additional or different license terms and conditions 192 | for use, reproduction, or distribution of Your modifications, or 193 | for any such Derivative Works as a whole, provided Your use, 194 | reproduction, and distribution of the Work otherwise complies with 195 | the conditions stated in this License. 196 | 197 | 5. Submission of Contributions. Unless You explicitly state otherwise, 198 | any Contribution intentionally submitted for inclusion in the Work 199 | by You to the Licensor shall be under the terms and conditions of 200 | this License, without any additional terms or conditions. 201 | Notwithstanding the above, nothing herein shall supersede or modify 202 | the terms of any separate license agreement you may have executed 203 | with Licensor regarding such Contributions. 204 | 205 | 6. Trademarks. This License does not grant permission to use the trade 206 | names, trademarks, service marks, or product names of the Licensor, 207 | except as required for reasonable and customary use in describing the 208 | origin of the Work and reproducing the content of the NOTICE file. 209 | 210 | 7. Disclaimer of Warranty. Unless required by applicable law or 211 | agreed to in writing, Licensor provides the Work (and each 212 | Contributor provides its Contributions) on an "AS IS" BASIS, 213 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 214 | implied, including, without limitation, any warranties or conditions 215 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 216 | PARTICULAR PURPOSE. You are solely responsible for determining the 217 | appropriateness of using or redistributing the Work and assume any 218 | risks associated with Your exercise of permissions under this License. 219 | 220 | 8. Limitation of Liability. In no event and under no legal theory, 221 | whether in tort (including negligence), contract, or otherwise, 222 | unless required by applicable law (such as deliberate and grossly 223 | negligent acts) or agreed to in writing, shall any Contributor be 224 | liable to You for damages, including any direct, indirect, special, 225 | incidental, or consequential damages of any character arising as a 226 | result of this License or out of the use or inability to use the 227 | Work (including but not limited to damages for loss of goodwill, 228 | work stoppage, computer failure or malfunction, or any and all 229 | other commercial damages or losses), even if such Contributor 230 | has been advised of the possibility of such damages. 231 | 232 | 9. Accepting Warranty or Additional Liability. While redistributing 233 | the Work or Derivative Works thereof, You may choose to offer, 234 | and charge a fee for, acceptance of support, warranty, indemnity, 235 | or other liability obligations and/or rights consistent with this 236 | License. However, in accepting such obligations, You may act only 237 | on Your own behalf and on Your sole responsibility, not on behalf 238 | of any other Contributor, and only if You agree to indemnify, 239 | defend, and hold each Contributor harmless for any liability 240 | incurred by, or claims asserted against, such Contributor by reason 241 | of your accepting any such warranty or additional liability. 242 | 243 | END OF TERMS AND CONDITIONS 244 | 245 | APPENDIX: How to apply the Apache License to your work. 246 | 247 | To apply the Apache License to your work, attach the following 248 | boilerplate notice, with the fields enclosed by brackets "[]" 249 | replaced with your own identifying information. (Don't include 250 | the brackets!) The text should be enclosed in the appropriate 251 | comment syntax for the file format. We also recommend that a 252 | file or class name and description of purpose be included on the 253 | same "printed page" as the copyright notice for easier 254 | identification within third-party archives. 255 | 256 | Copyright [yyyy] [name of copyright owner] 257 | 258 | Licensed under the Apache License, Version 2.0 (the "License"); 259 | you may not use this file except in compliance with the License. 260 | You may obtain a copy of the License at 261 | 262 | http://www.apache.org/licenses/LICENSE-2.0 263 | 264 | Unless required by applicable law or agreed to in writing, software 265 | distributed under the License is distributed on an "AS IS" BASIS, 266 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 267 | See the License for the specific language governing permissions and 268 | limitations under the License. -------------------------------------------------------------------------------- /Assets/GRPC.NET/Example/Proto/Hello.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated by the protocol buffer compiler. DO NOT EDIT! 3 | // source: hello.proto 4 | // 5 | #pragma warning disable 1591, 0612, 3021, 8981 6 | #region Designer generated code 7 | 8 | using pb = global::Google.Protobuf; 9 | using pbc = global::Google.Protobuf.Collections; 10 | using pbr = global::Google.Protobuf.Reflection; 11 | using scg = global::System.Collections.Generic; 12 | namespace TestProto { 13 | 14 | /// Holder for reflection information generated from hello.proto 15 | public static partial class HelloReflection { 16 | 17 | #region Descriptor 18 | /// File descriptor for hello.proto 19 | public static pbr::FileDescriptor Descriptor { 20 | get { return descriptor; } 21 | } 22 | private static pbr::FileDescriptor descriptor; 23 | 24 | static HelloReflection() { 25 | byte[] descriptorData = global::System.Convert.FromBase64String( 26 | string.Concat( 27 | "CgtoZWxsby5wcm90byIcCgxIZWxsb1JlcXVlc3QSDAoEdGV4dBgBIAEoCSId", 28 | "Cg1IZWxsb1Jlc3BvbnNlEgwKBHRleHQYASABKAkyzQEKEUhlbGxvV29ybGRT", 29 | "ZXJ2aWNlEigKBWhlbGxvEg0uSGVsbG9SZXF1ZXN0Gg4uSGVsbG9SZXNwb25z", 30 | "ZSIAEi4KC2hlbGxvU2VydmVyEg0uSGVsbG9SZXF1ZXN0Gg4uSGVsbG9SZXNw", 31 | "b25zZTABEi4KC2hlbGxvQ2xpZW50Eg0uSGVsbG9SZXF1ZXN0Gg4uSGVsbG9S", 32 | "ZXNwb25zZSgBEi4KCWhlbGxvQm90aBINLkhlbGxvUmVxdWVzdBoOLkhlbGxv", 33 | "UmVzcG9uc2UoATABQisKG2NvbS5leGFtcGxlLnR1dG9yaWFsLnByb3Rvc1AB", 34 | "qgIJVGVzdFByb3RvYgZwcm90bzM=")); 35 | descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, 36 | new pbr::FileDescriptor[] { }, 37 | new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { 38 | new pbr::GeneratedClrTypeInfo(typeof(global::TestProto.HelloRequest), global::TestProto.HelloRequest.Parser, new[]{ "Text" }, null, null, null, null), 39 | new pbr::GeneratedClrTypeInfo(typeof(global::TestProto.HelloResponse), global::TestProto.HelloResponse.Parser, new[]{ "Text" }, null, null, null, null) 40 | })); 41 | } 42 | #endregion 43 | 44 | } 45 | #region Messages 46 | public sealed partial class HelloRequest : pb::IMessage 47 | #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE 48 | , pb::IBufferMessage 49 | #endif 50 | { 51 | private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new HelloRequest()); 52 | private pb::UnknownFieldSet _unknownFields; 53 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 54 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 55 | public static pb::MessageParser Parser { get { return _parser; } } 56 | 57 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 58 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 59 | public static pbr::MessageDescriptor Descriptor { 60 | get { return global::TestProto.HelloReflection.Descriptor.MessageTypes[0]; } 61 | } 62 | 63 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 64 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 65 | pbr::MessageDescriptor pb::IMessage.Descriptor { 66 | get { return Descriptor; } 67 | } 68 | 69 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 70 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 71 | public HelloRequest() { 72 | OnConstruction(); 73 | } 74 | 75 | partial void OnConstruction(); 76 | 77 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 78 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 79 | public HelloRequest(HelloRequest other) : this() { 80 | text_ = other.text_; 81 | _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); 82 | } 83 | 84 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 85 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 86 | public HelloRequest Clone() { 87 | return new HelloRequest(this); 88 | } 89 | 90 | /// Field number for the "text" field. 91 | public const int TextFieldNumber = 1; 92 | private string text_ = ""; 93 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 94 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 95 | public string Text { 96 | get { return text_; } 97 | set { 98 | text_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); 99 | } 100 | } 101 | 102 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 103 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 104 | public override bool Equals(object other) { 105 | return Equals(other as HelloRequest); 106 | } 107 | 108 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 109 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 110 | public bool Equals(HelloRequest other) { 111 | if (ReferenceEquals(other, null)) { 112 | return false; 113 | } 114 | if (ReferenceEquals(other, this)) { 115 | return true; 116 | } 117 | if (Text != other.Text) return false; 118 | return Equals(_unknownFields, other._unknownFields); 119 | } 120 | 121 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 122 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 123 | public override int GetHashCode() { 124 | int hash = 1; 125 | if (Text.Length != 0) hash ^= Text.GetHashCode(); 126 | if (_unknownFields != null) { 127 | hash ^= _unknownFields.GetHashCode(); 128 | } 129 | return hash; 130 | } 131 | 132 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 133 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 134 | public override string ToString() { 135 | return pb::JsonFormatter.ToDiagnosticString(this); 136 | } 137 | 138 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 139 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 140 | public void WriteTo(pb::CodedOutputStream output) { 141 | #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE 142 | output.WriteRawMessage(this); 143 | #else 144 | if (Text.Length != 0) { 145 | output.WriteRawTag(10); 146 | output.WriteString(Text); 147 | } 148 | if (_unknownFields != null) { 149 | _unknownFields.WriteTo(output); 150 | } 151 | #endif 152 | } 153 | 154 | #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE 155 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 156 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 157 | void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { 158 | if (Text.Length != 0) { 159 | output.WriteRawTag(10); 160 | output.WriteString(Text); 161 | } 162 | if (_unknownFields != null) { 163 | _unknownFields.WriteTo(ref output); 164 | } 165 | } 166 | #endif 167 | 168 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 169 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 170 | public int CalculateSize() { 171 | int size = 0; 172 | if (Text.Length != 0) { 173 | size += 1 + pb::CodedOutputStream.ComputeStringSize(Text); 174 | } 175 | if (_unknownFields != null) { 176 | size += _unknownFields.CalculateSize(); 177 | } 178 | return size; 179 | } 180 | 181 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 182 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 183 | public void MergeFrom(HelloRequest other) { 184 | if (other == null) { 185 | return; 186 | } 187 | if (other.Text.Length != 0) { 188 | Text = other.Text; 189 | } 190 | _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); 191 | } 192 | 193 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 194 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 195 | public void MergeFrom(pb::CodedInputStream input) { 196 | #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE 197 | input.ReadRawMessage(this); 198 | #else 199 | uint tag; 200 | while ((tag = input.ReadTag()) != 0) { 201 | switch(tag) { 202 | default: 203 | _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); 204 | break; 205 | case 10: { 206 | Text = input.ReadString(); 207 | break; 208 | } 209 | } 210 | } 211 | #endif 212 | } 213 | 214 | #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE 215 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 216 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 217 | void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { 218 | uint tag; 219 | while ((tag = input.ReadTag()) != 0) { 220 | switch(tag) { 221 | default: 222 | _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); 223 | break; 224 | case 10: { 225 | Text = input.ReadString(); 226 | break; 227 | } 228 | } 229 | } 230 | } 231 | #endif 232 | 233 | } 234 | 235 | public sealed partial class HelloResponse : pb::IMessage 236 | #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE 237 | , pb::IBufferMessage 238 | #endif 239 | { 240 | private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new HelloResponse()); 241 | private pb::UnknownFieldSet _unknownFields; 242 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 243 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 244 | public static pb::MessageParser Parser { get { return _parser; } } 245 | 246 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 247 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 248 | public static pbr::MessageDescriptor Descriptor { 249 | get { return global::TestProto.HelloReflection.Descriptor.MessageTypes[1]; } 250 | } 251 | 252 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 253 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 254 | pbr::MessageDescriptor pb::IMessage.Descriptor { 255 | get { return Descriptor; } 256 | } 257 | 258 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 259 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 260 | public HelloResponse() { 261 | OnConstruction(); 262 | } 263 | 264 | partial void OnConstruction(); 265 | 266 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 267 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 268 | public HelloResponse(HelloResponse other) : this() { 269 | text_ = other.text_; 270 | _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); 271 | } 272 | 273 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 274 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 275 | public HelloResponse Clone() { 276 | return new HelloResponse(this); 277 | } 278 | 279 | /// Field number for the "text" field. 280 | public const int TextFieldNumber = 1; 281 | private string text_ = ""; 282 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 283 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 284 | public string Text { 285 | get { return text_; } 286 | set { 287 | text_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); 288 | } 289 | } 290 | 291 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 292 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 293 | public override bool Equals(object other) { 294 | return Equals(other as HelloResponse); 295 | } 296 | 297 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 298 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 299 | public bool Equals(HelloResponse other) { 300 | if (ReferenceEquals(other, null)) { 301 | return false; 302 | } 303 | if (ReferenceEquals(other, this)) { 304 | return true; 305 | } 306 | if (Text != other.Text) return false; 307 | return Equals(_unknownFields, other._unknownFields); 308 | } 309 | 310 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 311 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 312 | public override int GetHashCode() { 313 | int hash = 1; 314 | if (Text.Length != 0) hash ^= Text.GetHashCode(); 315 | if (_unknownFields != null) { 316 | hash ^= _unknownFields.GetHashCode(); 317 | } 318 | return hash; 319 | } 320 | 321 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 322 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 323 | public override string ToString() { 324 | return pb::JsonFormatter.ToDiagnosticString(this); 325 | } 326 | 327 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 328 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 329 | public void WriteTo(pb::CodedOutputStream output) { 330 | #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE 331 | output.WriteRawMessage(this); 332 | #else 333 | if (Text.Length != 0) { 334 | output.WriteRawTag(10); 335 | output.WriteString(Text); 336 | } 337 | if (_unknownFields != null) { 338 | _unknownFields.WriteTo(output); 339 | } 340 | #endif 341 | } 342 | 343 | #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE 344 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 345 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 346 | void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { 347 | if (Text.Length != 0) { 348 | output.WriteRawTag(10); 349 | output.WriteString(Text); 350 | } 351 | if (_unknownFields != null) { 352 | _unknownFields.WriteTo(ref output); 353 | } 354 | } 355 | #endif 356 | 357 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 358 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 359 | public int CalculateSize() { 360 | int size = 0; 361 | if (Text.Length != 0) { 362 | size += 1 + pb::CodedOutputStream.ComputeStringSize(Text); 363 | } 364 | if (_unknownFields != null) { 365 | size += _unknownFields.CalculateSize(); 366 | } 367 | return size; 368 | } 369 | 370 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 371 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 372 | public void MergeFrom(HelloResponse other) { 373 | if (other == null) { 374 | return; 375 | } 376 | if (other.Text.Length != 0) { 377 | Text = other.Text; 378 | } 379 | _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); 380 | } 381 | 382 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 383 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 384 | public void MergeFrom(pb::CodedInputStream input) { 385 | #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE 386 | input.ReadRawMessage(this); 387 | #else 388 | uint tag; 389 | while ((tag = input.ReadTag()) != 0) { 390 | switch(tag) { 391 | default: 392 | _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); 393 | break; 394 | case 10: { 395 | Text = input.ReadString(); 396 | break; 397 | } 398 | } 399 | } 400 | #endif 401 | } 402 | 403 | #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE 404 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 405 | [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] 406 | void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { 407 | uint tag; 408 | while ((tag = input.ReadTag()) != 0) { 409 | switch(tag) { 410 | default: 411 | _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); 412 | break; 413 | case 10: { 414 | Text = input.ReadString(); 415 | break; 416 | } 417 | } 418 | } 419 | } 420 | #endif 421 | 422 | } 423 | 424 | #endregion 425 | 426 | } 427 | 428 | #endregion Designer generated code 429 | -------------------------------------------------------------------------------- /Assets/GRPC.NET/Example/GRPCExampleTestController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using BestHTTP; 6 | using BestHTTP.Logger; 7 | using Grpc.Core; 8 | using Grpc.Net.Client; 9 | using TestProto; 10 | using UnityEngine; 11 | using ColorUtility = UnityEngine.ColorUtility; 12 | using Metadata = Grpc.Core.Metadata; 13 | 14 | namespace GRPC.NET.Example 15 | { 16 | public class GRPCExampleTestController : MonoBehaviour 17 | { 18 | private GRPCExampleLogger m_Logger; 19 | 20 | private GrpcTestCallIdFactory m_CallIdFactory; 21 | 22 | private GrpcTestCallFactory m_CallFactoryA; 23 | private GrpcTestCallFactory m_CallFactoryB; 24 | 25 | private void Awake() 26 | { 27 | m_Logger = gameObject.GetComponent(); 28 | 29 | // Setup BestHTTP 30 | HTTPManager.Setup(); 31 | HTTPManager.Logger.Level = Loglevels.All; // Enable all log levels 32 | 33 | // Shared Id call Factory 34 | m_CallIdFactory = new GrpcTestCallIdFactory(); 35 | 36 | m_CallFactoryA = new GrpcTestCallFactory(m_CallIdFactory, 'A', m_Logger); 37 | m_CallFactoryB = new GrpcTestCallFactory(m_CallIdFactory, 'B', m_Logger); 38 | } 39 | 40 | void Update() => m_CallIdFactory.Update(); 41 | 42 | private static string MetadataToString(Metadata metadata) 43 | { 44 | return string.Join(",", metadata); 45 | } 46 | 47 | private static readonly Metadata AuthMetadata = new Metadata { { "Authorization", "Bearer f623f5c2-46a8-4bdc-9ac5-45358a615a54" } }; 48 | 49 | private void RunTestCallUnary(GrpcTestCallFactory callFactory, Metadata metadata = null, string detail = null) 50 | { 51 | Debug.Log("RunTestCallUnary"); 52 | 53 | var call = callFactory.CreateUnary(metadata, detail); 54 | call.Call(); 55 | } 56 | 57 | private void RunTestCallServerStreaming(GrpcTestCallFactory callFactory) 58 | { 59 | Debug.Log("RunTestCallServerStreaming"); 60 | 61 | var call = callFactory.CreateServerStreaming(AuthMetadata); 62 | call.Call(); 63 | } 64 | 65 | private void RunTestCallClientStreaming(GrpcTestCallFactory callFactory) 66 | { 67 | Debug.Log("RunTestCallClientStreaming"); 68 | 69 | var call = callFactory.CreateClientStreaming(AuthMetadata); 70 | call.Call(); 71 | } 72 | 73 | private void RunTestCallBiStreaming(GrpcTestCallFactory callFactory) 74 | { 75 | Debug.Log("RunTestCallBiStreaming"); 76 | 77 | var call = callFactory.CreateBiStreaming(AuthMetadata); 78 | call.Call(); 79 | } 80 | 81 | private class UnaryGrpcTestCall : GrpcTestCall 82 | { 83 | private readonly string m_Detail; 84 | 85 | public UnaryGrpcTestCall(GRPCExampleLogger log, GrpcTestCallIdFactory callIdFactory, char factoryId, 86 | HelloWorldService.HelloWorldServiceClient client, Metadata metadata, string detail) : base(log, callIdFactory, factoryId, 87 | false, client, metadata) 88 | { 89 | m_Detail = detail; 90 | } 91 | 92 | protected override void CallImpl(CancellationToken cancelToken, CancellationToken _) 93 | { 94 | FireCallStarted("Unary"); 95 | 96 | var asyncCall = Client.helloAsync(new HelloRequest() 97 | { 98 | Text = "World" + (m_Detail != null ? $" [{m_Detail}]" : "") 99 | }, Metadata, cancellationToken: cancelToken); 100 | 101 | void PrintStatus() 102 | { 103 | var metadata = asyncCall.GetTrailers(); 104 | WriteLog($"Trailers[{metadata.Count}]: {MetadataToString(metadata)}"); 105 | WriteLog($"Status: {asyncCall.GetStatus()}"); 106 | } 107 | 108 | asyncCall.ResponseHeadersAsync.ContinueWith(ContinuationWithHeaders, cancelToken); 109 | asyncCall.ResponseAsync.ContinueWith(ContinuationWithResponse, cancelToken); 110 | 111 | // If we have no response we still complete the call here 112 | asyncCall.GetAwaiter().OnCompleted(() => FireCallCompleted(PrintStatus)); 113 | } 114 | } 115 | 116 | private class ServerStreamingGrpcTestCall : GrpcTestCall 117 | { 118 | public ServerStreamingGrpcTestCall(GRPCExampleLogger log, GrpcTestCallIdFactory callIdFactory, char factoryId, 119 | HelloWorldService.HelloWorldServiceClient client, Metadata metadata) : base(log, callIdFactory, factoryId, true, client, metadata) 120 | { } 121 | 122 | protected override void CallImpl(CancellationToken cancelToken, CancellationToken receiveCancelToken) 123 | { 124 | FireCallStarted("ServerStreaming"); 125 | 126 | var asyncCall = Client.helloServer(new HelloRequest() 127 | { 128 | Text = "World" 129 | }, Metadata, cancellationToken: cancelToken); 130 | 131 | void PrintStatus() 132 | { 133 | var metadata = asyncCall.GetTrailers(); 134 | WriteLog($"Trailers[{metadata.Count}]: {MetadataToString(metadata)}"); 135 | WriteLog($"Status: {asyncCall.GetStatus()}"); 136 | } 137 | 138 | asyncCall.ResponseHeadersAsync.ContinueWith(ContinuationWithHeaders, cancelToken); 139 | 140 | ProcessServerResponses(asyncCall.ResponseStream, receiveCancelToken, PrintStatus); 141 | } 142 | } 143 | 144 | private class ClientStreamingGrpcTestCall : GrpcTestCall 145 | { 146 | public ClientStreamingGrpcTestCall(GRPCExampleLogger log, GrpcTestCallIdFactory callIdFactory, char factoryId, 147 | HelloWorldService.HelloWorldServiceClient client, Metadata metadata) : base(log, callIdFactory, factoryId, false, client, metadata) 148 | { } 149 | 150 | protected override void CallImpl(CancellationToken cancelToken, CancellationToken _) 151 | { 152 | FireCallStarted("ClientStreaming"); 153 | 154 | var asyncCall = Client.helloClient(Metadata, cancellationToken: cancelToken); 155 | 156 | void PrintStatus() 157 | { 158 | var metadata = asyncCall.GetTrailers(); 159 | WriteLog($"Trailers[{metadata.Count}]: {MetadataToString(metadata)}"); 160 | WriteLog($"Status: {asyncCall.GetStatus()}"); 161 | } 162 | 163 | asyncCall.ResponseHeadersAsync.ContinueWith(ContinuationWithHeaders, cancelToken); 164 | asyncCall.ResponseAsync.ContinueWith(ContinuationWithResponse, cancelToken); 165 | 166 | SendClientRequests(asyncCall.RequestStream); 167 | 168 | // If we have no response we still complete the call here 169 | asyncCall.GetAwaiter().OnCompleted(() => FireCallCompleted(PrintStatus)); 170 | } 171 | } 172 | 173 | private class BiStreamingGrpcTestCall : GrpcTestCall 174 | { 175 | public BiStreamingGrpcTestCall(GRPCExampleLogger log, GrpcTestCallIdFactory callIdFactory, char factoryId, 176 | HelloWorldService.HelloWorldServiceClient client, Metadata metadata) : base(log, callIdFactory, factoryId, true, client, metadata) 177 | { } 178 | 179 | protected override void CallImpl(CancellationToken cancelToken, CancellationToken receiveCancelToken) 180 | { 181 | FireCallStarted("ClientStreaming"); 182 | 183 | var asyncCall = Client.helloBoth(Metadata, cancellationToken: cancelToken); 184 | 185 | void PrintStatus() 186 | { 187 | var metadata = asyncCall.GetTrailers(); 188 | WriteLog($"Trailers[{metadata.Count}]: {MetadataToString(metadata)}"); 189 | WriteLog($"Status: {asyncCall.GetStatus()}"); 190 | } 191 | 192 | asyncCall.ResponseHeadersAsync.ContinueWith(ContinuationWithHeaders, cancelToken); 193 | 194 | SendClientRequests(asyncCall.RequestStream); 195 | 196 | ProcessServerResponses(asyncCall.ResponseStream, receiveCancelToken, PrintStatus); 197 | } 198 | } 199 | 200 | private class GrpcTestCallIdFactory 201 | { 202 | private static Color Hex2Color(string hex) => ColorUtility.TryParseHtmlString(hex, out var color) ? color : Color.red; 203 | private static readonly Color[] ColorList = 204 | { 205 | Hex2Color("#db5f57"), Hex2Color("#dbc257"), Hex2Color("#91db57"), Hex2Color("#57db80"), 206 | Hex2Color("#57d3db"), Hex2Color("#5770db"), Hex2Color("#a157db"), Hex2Color("#db57b2"), 207 | }; 208 | 209 | private int m_Inc = 0; 210 | private int m_ColorPointer = 0; 211 | 212 | private List m_ActiveCalls = new List(); 213 | 214 | public (int, Color) CreateNext(GrpcTestCall call) 215 | { 216 | Interlocked.Increment(ref m_Inc); 217 | 218 | // Find unique color for this call 219 | var c = ColorList[m_ColorPointer]; 220 | m_ColorPointer++; 221 | if (m_ColorPointer >= ColorList.Length) 222 | m_ColorPointer = 0; 223 | 224 | // Add call to active list 225 | m_ActiveCalls.Add(call); 226 | 227 | return (m_Inc, c); 228 | } 229 | 230 | // Keep track of active calls 231 | public IEnumerable GetActiveCalls() => m_ActiveCalls; 232 | public void Completed(GrpcTestCall call) => m_ActiveCalls.Remove(call); 233 | 234 | // Timer utility callback to make delayed calls possible 235 | public event Action OnTimer; 236 | 237 | private float m_Time = 0; 238 | 239 | public void Update() 240 | { 241 | if (Time.realtimeSinceStartup >= m_Time) 242 | { 243 | m_Time = Time.realtimeSinceStartup + 1.0f; // 1 sec delay 244 | OnTimer?.Invoke(); 245 | } 246 | } 247 | } 248 | 249 | private class GrpcTestCallFactory 250 | { 251 | public string ServerAddressInput = "https://127.0.0.1:50051"; 252 | 253 | private readonly GrpcTestCallIdFactory m_IdFactory; 254 | private readonly char m_FactoryId; 255 | private readonly GRPCExampleLogger m_Logger; 256 | 257 | private GrpcChannel m_Channel; 258 | private HelloWorldService.HelloWorldServiceClient m_Client; 259 | 260 | public GrpcTestCallFactory(GrpcTestCallIdFactory idFactory, char factoryId, GRPCExampleLogger logger) 261 | { 262 | m_IdFactory = idFactory; 263 | m_FactoryId = factoryId; 264 | m_Logger = logger; 265 | } 266 | 267 | public GrpcTestCall CreateUnary(Metadata metadata, string detail = null) 268 | { 269 | EnsureClientConnection(); 270 | return new UnaryGrpcTestCall(m_Logger, m_IdFactory, m_FactoryId, m_Client, metadata, detail); 271 | } 272 | 273 | public GrpcTestCall CreateServerStreaming(Metadata metadata) 274 | { 275 | EnsureClientConnection(); 276 | return new ServerStreamingGrpcTestCall(m_Logger, m_IdFactory, m_FactoryId, m_Client, metadata); 277 | } 278 | 279 | public GrpcTestCall CreateClientStreaming(Metadata metadata) 280 | { 281 | EnsureClientConnection(); 282 | return new ClientStreamingGrpcTestCall(m_Logger, m_IdFactory, m_FactoryId, m_Client, metadata); 283 | } 284 | 285 | public GrpcTestCall CreateBiStreaming(Metadata metadata) 286 | { 287 | EnsureClientConnection(); 288 | return new BiStreamingGrpcTestCall(m_Logger, m_IdFactory, m_FactoryId, m_Client, metadata); 289 | } 290 | 291 | private void EnsureClientConnection() 292 | { 293 | // Setup GRPC channel 294 | GRPCBestHttpHandler httpHandler = new GRPCBestHttpHandler(); 295 | m_Channel = GrpcChannel.ForAddress(ServerAddressInput, new GrpcChannelOptions 296 | { 297 | HttpHandler = httpHandler 298 | }); 299 | 300 | m_Client = new HelloWorldService.HelloWorldServiceClient(m_Channel); 301 | } 302 | } 303 | 304 | private abstract class GrpcTestCall 305 | { 306 | protected readonly GRPCExampleLogger Log; 307 | protected readonly GrpcTestCallIdFactory CallIdFactory; 308 | public readonly char FactoryId; 309 | public readonly int Inc; 310 | public readonly Color Color; 311 | 312 | protected readonly bool UsesReceive; 313 | private CancellationTokenSource m_CancelToken; 314 | private CancellationTokenSource m_ReceiveCancelToken; 315 | 316 | protected readonly HelloWorldService.HelloWorldServiceClient Client; 317 | protected readonly Metadata Metadata; 318 | 319 | public GrpcTestCall(GRPCExampleLogger log, GrpcTestCallIdFactory callIdFactory, char factoryId, bool usesReceive, 320 | HelloWorldService.HelloWorldServiceClient client, Metadata metadata) 321 | { 322 | Log = log; 323 | FactoryId = factoryId; 324 | UsesReceive = usesReceive; 325 | CallIdFactory = callIdFactory; 326 | (Inc, Color) = callIdFactory.CreateNext(this); 327 | Client = client; 328 | Metadata = metadata; 329 | } 330 | 331 | protected abstract void CallImpl(CancellationToken cancelToken, CancellationToken receiveCancelToken); 332 | 333 | public void Call() 334 | { 335 | m_CancelToken = new CancellationTokenSource(); 336 | m_ReceiveCancelToken = new CancellationTokenSource(); 337 | CallImpl(m_CancelToken.Token, m_ReceiveCancelToken.Token); 338 | } 339 | 340 | public void Cancel() => m_CancelToken.Cancel(); 341 | 342 | public void CancelReceive() => m_ReceiveCancelToken.Cancel(); 343 | 344 | public bool SupportsReceiveCancellation() => UsesReceive; 345 | 346 | protected void WriteLog(string msg) 347 | { 348 | var colorHex = ColorUtility.ToHtmlStringRGBA(Color); 349 | Log.WriteLogOutput($"[{FactoryId}|{Inc}] {msg}"); 350 | } 351 | 352 | protected void FireCallStarted(string callName) 353 | { 354 | WriteLog($"Call {callName} started"); 355 | } 356 | 357 | protected void FireCallException(Exception ex) 358 | { 359 | WriteLog($"Call exception: {ex.Message}"); 360 | } 361 | 362 | protected void FireCallCompleted(Action printStatusFunc) 363 | { 364 | // If call did not complete we can not access status or trailers 365 | try 366 | { 367 | printStatusFunc(); 368 | } 369 | catch (Exception e) 370 | { 371 | // ignored 372 | _ = e; 373 | } 374 | WriteLog("Call completed"); 375 | CallIdFactory.Completed(this); 376 | } 377 | 378 | protected void ContinuationWithHeaders(Task task) 379 | { 380 | var metadata = task.Result; 381 | WriteLog($"Metadata[{metadata.Count}]: {string.Join(",", metadata)}"); 382 | } 383 | 384 | protected void ContinuationWithResponse(Task task) 385 | { 386 | if (task.Exception != null) 387 | { 388 | WriteLog($"Error: {task.Exception.Message}"); 389 | } 390 | else 391 | { 392 | var result = task.Result; 393 | WriteLog($"Received: {result.Text}"); 394 | } 395 | } 396 | 397 | protected async void ProcessServerResponses(IAsyncStreamReader responseStream, 398 | CancellationToken receiveCancelToken, Action printStatusFunc) 399 | { 400 | try 401 | { 402 | var idx = 0; 403 | while (await responseStream.MoveNext(receiveCancelToken)) 404 | { 405 | var response = responseStream.Current; 406 | WriteLog($"Received({idx++}): {response.Text}"); 407 | } 408 | } catch (Exception e) 409 | { 410 | FireCallException(e); 411 | } 412 | finally 413 | { 414 | FireCallCompleted(printStatusFunc); 415 | } 416 | } 417 | 418 | protected void SendClientRequests(IClientStreamWriter requestStream) 419 | { 420 | var idx = 0; 421 | 422 | async void OnTimerFunc() 423 | { 424 | try 425 | { 426 | if (idx < 5) 427 | { 428 | var msg = new HelloRequest() { Text = $"World {idx}" }; 429 | WriteLog($"Send({idx}): {msg.Text}"); 430 | await requestStream.WriteAsync(msg); 431 | idx += 1; 432 | } 433 | else 434 | { 435 | await requestStream.CompleteAsync(); 436 | CallIdFactory.OnTimer -= OnTimerFunc; 437 | } 438 | } 439 | catch (Exception e) 440 | { 441 | WriteLog($"Error Sending: {e.Message}"); 442 | CallIdFactory.OnTimer -= OnTimerFunc; 443 | } 444 | } 445 | 446 | CallIdFactory.OnTimer += OnTimerFunc; 447 | } 448 | } 449 | 450 | void GUITestButtonArea(GrpcTestCallFactory callFactory) 451 | { 452 | GUILayout.BeginVertical(); 453 | if (GUILayout.Button("Test Unary call")) 454 | { 455 | RunTestCallUnary(callFactory, AuthMetadata); 456 | } 457 | if (GUILayout.Button("Test Server-Streaming Call")) 458 | { 459 | RunTestCallServerStreaming(callFactory); 460 | } 461 | if (GUILayout.Button("Test Client-Streaming Call")) 462 | { 463 | RunTestCallClientStreaming(callFactory); 464 | } 465 | if (GUILayout.Button("Test Bidirectional-Streaming Call")) 466 | { 467 | RunTestCallBiStreaming(callFactory); 468 | } 469 | if (GUILayout.Button("Test Unary call (throw ex after resp)")) 470 | { 471 | RunTestCallUnary(callFactory, AuthMetadata, "exception-after"); 472 | } 473 | if (GUILayout.Button("Test Unary call (throw ex before resp)")) 474 | { 475 | RunTestCallUnary(callFactory, AuthMetadata, "exception-before"); 476 | } 477 | if (GUILayout.Button("Test Unary call (throw ex after with meta)")) 478 | { 479 | RunTestCallUnary(callFactory, AuthMetadata, "exception-after-meta"); 480 | } 481 | if (GUILayout.Button("Test Unary call (throw ex before with meta)")) 482 | { 483 | RunTestCallUnary(callFactory, AuthMetadata, "exception-before-meta"); 484 | } 485 | if (GUILayout.Button("Test Unary call (no response)")) 486 | { 487 | RunTestCallUnary(callFactory, AuthMetadata, "no-response"); 488 | } 489 | if (GUILayout.Button("Test Unary call (no auth token)")) 490 | { 491 | RunTestCallUnary(callFactory); 492 | } 493 | GUILayout.EndVertical(); 494 | } 495 | 496 | void GUICancelButtonArea(GrpcTestCallIdFactory callFactory) 497 | { 498 | GUILayout.BeginVertical(); 499 | foreach(var call in callFactory.GetActiveCalls()) // FIXME: modified while reading... 500 | { 501 | var colorHex = ColorUtility.ToHtmlStringRGBA(call.Color); 502 | 503 | if (call.SupportsReceiveCancellation()) 504 | GUILayout.BeginHorizontal(); 505 | 506 | if (GUILayout.Button($"[{call.FactoryId}|{call.Inc}] Cancel")) 507 | { 508 | call.Cancel(); 509 | } 510 | 511 | if (call.SupportsReceiveCancellation()) 512 | { 513 | if (GUILayout.Button($"[{call.FactoryId}|{call.Inc}] Cancel Receive")) 514 | { 515 | call.CancelReceive(); 516 | } 517 | GUILayout.EndHorizontal(); 518 | } 519 | } 520 | GUILayout.EndVertical(); 521 | } 522 | 523 | void OnGUI() 524 | { 525 | int pad = 10; 526 | int screenWidth = Screen.width - pad * 2; 527 | 528 | m_CallFactoryA.ServerAddressInput = GUI.TextField(new Rect(pad, pad, screenWidth * 0.25f, 20), m_CallFactoryA.ServerAddressInput, 400); 529 | m_CallFactoryB.ServerAddressInput = GUI.TextField(new Rect(pad + screenWidth * 0.25f, pad, screenWidth * 0.25f, 20), m_CallFactoryB.ServerAddressInput, 400); 530 | 531 | var buttonAreaA = new Rect(pad, pad + 24, screenWidth * 0.25f, Screen.height); 532 | GUILayout.BeginArea(buttonAreaA); 533 | GUITestButtonArea(m_CallFactoryA); 534 | GUILayout.EndArea(); 535 | 536 | var buttonAreaB = new Rect(pad + screenWidth * 0.25f, pad + 24, screenWidth * 0.25f, Screen.height); 537 | GUILayout.BeginArea(buttonAreaB); 538 | GUITestButtonArea(m_CallFactoryB); 539 | GUILayout.EndArea(); 540 | 541 | var cancelArea = new Rect(pad + screenWidth * 0.25f * 3, pad, screenWidth * 0.25f, Screen.height); 542 | GUILayout.BeginArea(cancelArea); 543 | GUICancelButtonArea(m_CallIdFactory); 544 | GUILayout.EndArea(); 545 | } 546 | 547 | } 548 | } 549 | --------------------------------------------------------------------------------