Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: third_party/grpc/src/csharp/Grpc.Core/Internal/ServerRequestStream.cs

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/grpc/src/csharp/Grpc.Core/Internal/ServerRequestStream.cs
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Program.cs b/third_party/grpc/src/csharp/Grpc.Core/Internal/ServerRequestStream.cs
similarity index 53%
copy from third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Program.cs
copy to third_party/grpc/src/csharp/Grpc.Core/Internal/ServerRequestStream.cs
index e8a6073e2bcb6b6f47dafb1f67f31de9b4a8671a..e7be82c31857e44e3830fc52a647cfbb537fd50c 100644
--- a/third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Program.cs
+++ b/third_party/grpc/src/csharp/Grpc.Core/Internal/ServerRequestStream.cs
@@ -1,7 +1,7 @@
#region Copyright notice and license
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
+
+// Copyright 2015, Google Inc.
+// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@@ -28,45 +28,56 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
#endregion
using System;
-using System.IO;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
-namespace Google.Protobuf.ProtoDump
+namespace Grpc.Core.Internal
{
- /// <summary>
- /// Small utility to load a binary message and dump it in JSON format.
- /// </summary>
- internal class Program
+ internal class ServerRequestStream<TRequest, TResponse> : IAsyncStreamReader<TRequest>
+ where TRequest : class
+ where TResponse : class
{
- private static int Main(string[] args)
+ readonly AsyncCallServer<TRequest, TResponse> call;
+ TRequest current;
+
+ public ServerRequestStream(AsyncCallServer<TRequest, TResponse> call)
{
- if (args.Length != 2)
- {
- Console.Error.WriteLine("Usage: Google.Protobuf.JsonDump <descriptor type name> <input data>");
- Console.Error.WriteLine("The descriptor type name is the fully-qualified message name,");
- Console.Error.WriteLine("including assembly e.g. ProjectNamespace.Message,Company.Project");
- return 1;
- }
- Type type = Type.GetType(args[0]);
- if (type == null)
- {
- Console.Error.WriteLine("Unable to load type {0}.", args[0]);
- return 1;
- }
- if (!typeof(IMessage).IsAssignableFrom(type))
+ this.call = call;
+ }
+
+ public TRequest Current
+ {
+ get
{
- Console.Error.WriteLine("Type {0} doesn't implement IMessage.", args[0]);
- return 1;
+ if (current == null)
+ {
+ throw new InvalidOperationException("No current element is available.");
+ }
+ return current;
}
- IMessage message = (IMessage) Activator.CreateInstance(type);
- using (var input = File.OpenRead(args[1]))
+ }
+
+ public async Task<bool> MoveNext(CancellationToken token)
+ {
+ if (token != CancellationToken.None)
{
- message.MergeFrom(input);
+ throw new InvalidOperationException("Cancellation of individual reads is not supported.");
}
- Console.WriteLine(message);
- return 0;
+ var taskSource = new AsyncCompletionTaskSource<TRequest>();
+ call.StartReadMessage(taskSource.CompletionDelegate);
+ var result = await taskSource.Task.ConfigureAwait(false);
+ this.current = result;
+ return result != null;
+ }
+
+ public void Dispose()
+ {
+ // TODO(jtattermusch): implement the semantics of stream disposal.
}
}
-}
+}

Powered by Google App Engine
This is Rietveld 408576698