| OLD | NEW |
| 1 #region Copyright notice and license | 1 #region Copyright notice and license |
| 2 // Protocol Buffers - Google's data interchange format | 2 // Protocol Buffers - Google's data interchange format |
| 3 // Copyright 2008 Google Inc. All rights reserved. | 3 // Copyright 2008 Google Inc. All rights reserved. |
| 4 // https://developers.google.com/protocol-buffers/ | 4 // https://developers.google.com/protocol-buffers/ |
| 5 // | 5 // |
| 6 // Redistribution and use in source and binary forms, with or without | 6 // Redistribution and use in source and binary forms, with or without |
| 7 // modification, are permitted provided that the following conditions are | 7 // modification, are permitted provided that the following conditions are |
| 8 // met: | 8 // met: |
| 9 // | 9 // |
| 10 // * Redistributions of source code must retain the above copyright | 10 // * Redistributions of source code must retain the above copyright |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 29 // (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. | 30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 #endregion | 31 #endregion |
| 32 | 32 |
| 33 using System; | 33 using System; |
| 34 using System.IO; | 34 using System.IO; |
| 35 using System.Reflection; |
| 35 | 36 |
| 36 namespace Google.Protobuf.ProtoDump | 37 namespace Google.Protobuf.ProtoDump |
| 37 { | 38 { |
| 38 /// <summary> | 39 /// <summary> |
| 39 /// Small utility to load a binary message and dump it in JSON format. | 40 /// Small utility to load a binary message and dump it in JSON format. |
| 40 /// </summary> | 41 /// </summary> |
| 41 internal class Program | 42 internal class Program |
| 42 { | 43 { |
| 43 private static int Main(string[] args) | 44 private static int Main(string[] args) |
| 44 { | 45 { |
| 45 if (args.Length != 2) | 46 if (args.Length != 2) |
| 46 { | 47 { |
| 47 Console.Error.WriteLine("Usage: Google.Protobuf.JsonDump <descri
ptor type name> <input data>"); | 48 Console.Error.WriteLine("Usage: Google.Protobuf.JsonDump <descri
ptor type name> <input data>"); |
| 48 Console.Error.WriteLine("The descriptor type name is the fully-q
ualified message name,"); | 49 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 Console.Error.WriteLine("including assembly e.g. ProjectNamespac
e.Message,Company.Project"); |
| 50 return 1; | 51 return 1; |
| 51 } | 52 } |
| 52 Type type = Type.GetType(args[0]); | 53 Type type = Type.GetType(args[0]); |
| 53 if (type == null) | 54 if (type == null) |
| 54 { | 55 { |
| 55 Console.Error.WriteLine("Unable to load type {0}.", args[0]); | 56 Console.Error.WriteLine("Unable to load type {0}.", args[0]); |
| 56 return 1; | 57 return 1; |
| 57 } | 58 } |
| 58 if (!typeof(IMessage).IsAssignableFrom(type)) | 59 if (!typeof(IMessage).GetTypeInfo().IsAssignableFrom(type)) |
| 59 { | 60 { |
| 60 Console.Error.WriteLine("Type {0} doesn't implement IMessage.",
args[0]); | 61 Console.Error.WriteLine("Type {0} doesn't implement IMessage.",
args[0]); |
| 61 return 1; | 62 return 1; |
| 62 } | 63 } |
| 63 IMessage message = (IMessage) Activator.CreateInstance(type); | 64 IMessage message = (IMessage) Activator.CreateInstance(type); |
| 64 using (var input = File.OpenRead(args[1])) | 65 using (var input = File.OpenRead(args[1])) |
| 65 { | 66 { |
| 66 message.MergeFrom(input); | 67 message.MergeFrom(input); |
| 67 } | 68 } |
| 68 Console.WriteLine(message); | 69 Console.WriteLine(message); |
| 69 return 0; | 70 return 0; |
| 70 } | 71 } |
| 71 } | 72 } |
| 72 } | 73 } |
| OLD | NEW |