blob: 3224a2508bb29f6d8c3296655cb48bf813ceaf62 [file] [log] [blame]
Jon Skeetad748532009-06-25 16:55:58 +01001// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc. All rights reserved.
3// http://github.com/jskeet/dotnet-protobufs/
4// Original C++/Java/Python code:
5// http://code.google.com/p/protobuf/
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions are
9// met:
10//
11// * Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// * Redistributions in binary form must reproduce the above
14// copyright notice, this list of conditions and the following disclaimer
15// in the documentation and/or other materials provided with the
16// distribution.
17// * Neither the name of Google Inc. nor the names of its
18// contributors may be used to endorse or promote products derived from
19// this software without specific prior written permission.
20//
21// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32using System;
Jon Skeet8f8186a2009-01-16 10:57:40 +000033using System.IO;
Jon Skeet8f8186a2009-01-16 10:57:40 +000034
Jon Skeeta3767342009-01-16 18:06:56 +000035namespace Google.ProtocolBuffers.ProtoDump
36{
Jon Skeet8f8186a2009-01-16 10:57:40 +000037 /// <summary>
38 /// Small utility to load a binary message and dump it in text form
39 /// </summary>
40 class Program {
41 static int Main(string[] args) {
42 if (args.Length != 2) {
43 Console.Error.WriteLine("Usage: ProtoDump <descriptor type name> <input data>");
44 Console.Error.WriteLine("The descriptor type name is the fully-qualified message name,");
45 Console.Error.WriteLine("including assembly e.g. ProjectNamespace.Message,Company.Project");
46 return 1;
47 }
48 IMessage defaultMessage;
49 try {
50 defaultMessage = MessageUtil.GetDefaultMessage(args[0]);
51 } catch (ArgumentException e) {
52 Console.Error.WriteLine(e.Message);
53 return 1;
54 }
55 try {
56 IBuilder builder = defaultMessage.WeakCreateBuilderForType();
57 if (builder == null) {
58 Console.Error.WriteLine("Unable to create builder");
59 return 1;
60 }
61 byte[] inputData = File.ReadAllBytes(args[1]);
62 builder.WeakMergeFrom(ByteString.CopyFrom(inputData));
63 Console.WriteLine(TextFormat.PrintToString(builder.WeakBuild()));
64 return 0;
65 } catch (Exception e) {
66 Console.Error.WriteLine("Error: {0}", e.Message);
67 Console.Error.WriteLine();
68 Console.Error.WriteLine("Detailed exception information: {0}", e);
69 return 1;
70 }
71 }
72 }
Jon Skeeta3767342009-01-16 18:06:56 +000073}