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

Unified Diff: third_party/grpc/src/csharp/Grpc.Core/Internal/ClientRequestStream.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/ClientRequestStream.cs
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Program.cs b/third_party/grpc/src/csharp/Grpc.Core/Internal/ClientRequestStream.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/ClientRequestStream.cs
index e8a6073e2bcb6b6f47dafb1f67f31de9b4a8671a..013f00ff6fc87c3b109c13fb7ece6d3e52e095f7 100644
--- a/third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Program.cs
+++ b/third_party/grpc/src/csharp/Grpc.Core/Internal/ClientRequestStream.cs
@@ -1,12 +1,11 @@
#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
// met:
-//
+//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
@@ -16,7 +15,7 @@
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
-//
+//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -29,44 +28,57 @@
// (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.Threading.Tasks;
+using Grpc.Core.Internal;
-namespace Google.Protobuf.ProtoDump
+namespace Grpc.Core.Internal
{
/// <summary>
- /// Small utility to load a binary message and dump it in JSON format.
+ /// Writes requests asynchronously to an underlying AsyncCall object.
/// </summary>
- internal class Program
+ internal class ClientRequestStream<TRequest, TResponse> : IClientStreamWriter<TRequest>
{
- private static int Main(string[] args)
+ readonly AsyncCall<TRequest, TResponse> call;
+ WriteOptions writeOptions;
+
+ public ClientRequestStream(AsyncCall<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;
+ this.writeOptions = call.Details.Options.WriteOptions;
+ }
+
+ public Task WriteAsync(TRequest message)
+ {
+ var taskSource = new AsyncCompletionTaskSource<object>();
+ call.StartSendMessage(message, GetWriteFlags(), taskSource.CompletionDelegate);
+ return taskSource.Task;
+ }
+
+ public Task CompleteAsync()
+ {
+ var taskSource = new AsyncCompletionTaskSource<object>();
+ call.StartSendCloseFromClient(taskSource.CompletionDelegate);
+ return taskSource.Task;
+ }
+
+ public WriteOptions WriteOptions
+ {
+ get
{
- Console.Error.WriteLine("Type {0} doesn't implement IMessage.", args[0]);
- return 1;
+ return this.writeOptions;
}
- IMessage message = (IMessage) Activator.CreateInstance(type);
- using (var input = File.OpenRead(args[1]))
+
+ set
{
- message.MergeFrom(input);
+ writeOptions = value;
}
- Console.WriteLine(message);
- return 0;
+ }
+
+ private WriteFlags GetWriteFlags()
+ {
+ var options = writeOptions;
+ return options != null ? options.Flags : default(WriteFlags);
}
}
-}
+}

Powered by Google App Engine
This is Rietveld 408576698