blob: ca69b44be50174ecc74447240f571b23b5639ef1 [file] [log] [blame]
David Reissbbdb06e2008-04-08 05:07:14 +00001// Copyright (c) 2006- Facebook
2// Distributed under the Thrift Software License
3//
4// See accompanying file LICENSE or visit the Thrift site at:
5// http://developers.facebook.com/thrift/
6
7#include <cstdlib>
8#include <iostream>
9
David Reiss28f298d2008-05-01 06:17:36 +000010#include <transport/TBufferTransports.h>
David Reissbbdb06e2008-04-08 05:07:14 +000011#include <transport/TFDTransport.h>
12#include <protocol/TBinaryProtocol.h>
13#include <protocol/TDebugProtocol.h>
14#include <protocol/TProtocolTap.h>
15
16using namespace std;
17using boost::shared_ptr;
David Reiss3a25cac2009-03-30 21:22:54 +000018using namespace apache::thrift::transport;
19using namespace apache::thrift::protocol;
David Reissbbdb06e2008-04-08 05:07:14 +000020
21void usage() {
22 fprintf(stderr,
23 "usage: thrift_dump {-b|-f|-s} < input > ouput\n"
24 " -b TBufferedTransport messages\n"
25 " -f TFramedTransport messages\n"
26 " -s Raw structures\n");
27 exit(EXIT_FAILURE);
28}
29
30int main(int argc, char *argv[]) {
31 if (argc != 2) {
32 usage();
33 }
34
35 shared_ptr<TTransport> stdin_trans(new TFDTransport(STDIN_FILENO));
36 shared_ptr<TTransport> itrans;
37
38 if (argv[1] == std::string("-b") || argv[1] == std::string("-s")) {
39 itrans.reset(new TBufferedTransport(stdin_trans));
40 } else if (argv[1] == std::string("-f")) {
41 itrans.reset(new TFramedTransport(stdin_trans));
42 } else {
43 usage();
44 }
45
46 shared_ptr<TProtocol> iprot(new TBinaryProtocol(itrans));
47 shared_ptr<TProtocol> oprot(
48 new TDebugProtocol(
49 shared_ptr<TTransport>(new TBufferedTransport(
50 shared_ptr<TTransport>(new TFDTransport(STDOUT_FILENO))))));
51
52 TProtocolTap tap(iprot, oprot);
53
54 try {
55 if (argv[1] == std::string("-s")) {
56 for (;;) {
57 tap.skip(T_STRUCT);
58 }
59 } else {
60 std::string name;
61 TMessageType messageType;
62 int32_t seqid;
63 for (;;) {
64 tap.readMessageBegin(name, messageType, seqid);
65 tap.skip(T_STRUCT);
66 tap.readMessageEnd();
67 }
68 }
69 } catch (TProtocolException exn) {
70 cout << "Protocol Exception: " << exn.what() << endl;
71 } catch (...) {
72 }
73
74 cout << endl;
75
76 return 0;
77}