| OLD | NEW |
| 1 #region Copyright notice and license | 1 #region Copyright notice and license |
| 2 // Protocol Buffers - Google's data interchange format | 2 // Copyright 2015, Google Inc. |
| 3 // Copyright 2008 Google Inc. All rights reserved. | 3 // All rights reserved. |
| 4 // https://developers.google.com/protocol-buffers/ | 4 // |
| 5 // | |
| 6 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 7 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 8 // met: | 7 // met: |
| 9 // | 8 // |
| 10 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 11 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| 12 // * Redistributions in binary form must reproduce the above | 11 // * Redistributions in binary form must reproduce the above |
| 13 // copyright notice, this list of conditions and the following disclaimer | 12 // copyright notice, this list of conditions and the following disclaimer |
| 14 // in the documentation and/or other materials provided with the | 13 // in the documentation and/or other materials provided with the |
| 15 // distribution. | 14 // distribution. |
| 16 // * Neither the name of Google Inc. nor the names of its | 15 // * Neither the name of Google Inc. nor the names of its |
| 17 // contributors may be used to endorse or promote products derived from | 16 // contributors may be used to endorse or promote products derived from |
| 18 // this software without specific prior written permission. | 17 // this software without specific prior written permission. |
| 19 // | 18 // |
| 20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 #endregion | 30 #endregion |
| 31 using System; |
| 32 using System.Threading.Tasks; |
| 33 using Grpc.Core.Internal; |
| 32 | 34 |
| 33 using System; | 35 namespace Grpc.Core.Internal |
| 34 using System.IO; | |
| 35 | |
| 36 namespace Google.Protobuf.ProtoDump | |
| 37 { | 36 { |
| 38 /// <summary> | 37 /// <summary> |
| 39 /// Small utility to load a binary message and dump it in JSON format. | 38 /// Writes requests asynchronously to an underlying AsyncCall object. |
| 40 /// </summary> | 39 /// </summary> |
| 41 internal class Program | 40 internal class ClientRequestStream<TRequest, TResponse> : IClientStreamWrite
r<TRequest> |
| 42 { | 41 { |
| 43 private static int Main(string[] args) | 42 readonly AsyncCall<TRequest, TResponse> call; |
| 43 WriteOptions writeOptions; |
| 44 |
| 45 public ClientRequestStream(AsyncCall<TRequest, TResponse> call) |
| 44 { | 46 { |
| 45 if (args.Length != 2) | 47 this.call = call; |
| 48 this.writeOptions = call.Details.Options.WriteOptions; |
| 49 } |
| 50 |
| 51 public Task WriteAsync(TRequest message) |
| 52 { |
| 53 var taskSource = new AsyncCompletionTaskSource<object>(); |
| 54 call.StartSendMessage(message, GetWriteFlags(), taskSource.Completio
nDelegate); |
| 55 return taskSource.Task; |
| 56 } |
| 57 |
| 58 public Task CompleteAsync() |
| 59 { |
| 60 var taskSource = new AsyncCompletionTaskSource<object>(); |
| 61 call.StartSendCloseFromClient(taskSource.CompletionDelegate); |
| 62 return taskSource.Task; |
| 63 } |
| 64 |
| 65 public WriteOptions WriteOptions |
| 66 { |
| 67 get |
| 46 { | 68 { |
| 47 Console.Error.WriteLine("Usage: Google.Protobuf.JsonDump <descri
ptor type name> <input data>"); | 69 return this.writeOptions; |
| 48 Console.Error.WriteLine("The descriptor type name is the fully-q
ualified message name,"); | |
| 49 Console.Error.WriteLine("including assembly e.g. ProjectNamespac
e.Message,Company.Project"); | |
| 50 return 1; | |
| 51 } | 70 } |
| 52 Type type = Type.GetType(args[0]); | 71 |
| 53 if (type == null) | 72 set |
| 54 { | 73 { |
| 55 Console.Error.WriteLine("Unable to load type {0}.", args[0]); | 74 writeOptions = value; |
| 56 return 1; | |
| 57 } | 75 } |
| 58 if (!typeof(IMessage).IsAssignableFrom(type)) | 76 } |
| 59 { | 77 |
| 60 Console.Error.WriteLine("Type {0} doesn't implement IMessage.",
args[0]); | 78 private WriteFlags GetWriteFlags() |
| 61 return 1; | 79 { |
| 62 } | 80 var options = writeOptions; |
| 63 IMessage message = (IMessage) Activator.CreateInstance(type); | 81 return options != null ? options.Flags : default(WriteFlags); |
| 64 using (var input = File.OpenRead(args[1])) | |
| 65 { | |
| 66 message.MergeFrom(input); | |
| 67 } | |
| 68 Console.WriteLine(message); | |
| 69 return 0; | |
| 70 } | 82 } |
| 71 } | 83 } |
| 72 } | 84 } |
| OLD | NEW |