source: ntrip/trunk/GnssCenter/thrift/rtnet_sdo_example/rtnet_sdo_example_dump.cpp@ 6920

Last change on this file since 6920 was 4941, checked in by mervart, 12 years ago
File size: 2.7 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#include <cstdlib>
21#include <iostream>
22
23#include <transport/TBufferTransports.h>
24#include <transport/TFDTransport.h>
25#include <transport/TZlibTransport.h>
26#include <protocol/TBinaryProtocol.h>
27#include <protocol/TDebugProtocol.h>
28#include <protocol/TProtocolTap.h>
29
30using namespace std;
31using boost::shared_ptr;
32using namespace apache::thrift::transport;
33using namespace apache::thrift::protocol;
34
35void usage() {
36 fprintf(stderr,
37 "usage: thrift_dump {-b|-f|-s} < input > ouput\n"
38 " -b TBufferedTransport messages\n"
39 " -f TFramedTransport messages\n"
40 " -z TZlibTransport messages\n"
41 " -s Raw structures\n");
42 exit(EXIT_FAILURE);
43}
44
45int main(int argc, char *argv[]) {
46 if (argc != 2) {
47 usage();
48 }
49
50 shared_ptr<TTransport> stdin_trans(new TFDTransport(STDIN_FILENO));
51 shared_ptr<TTransport> itrans;
52
53 if (argv[1] == std::string("-b") || argv[1] == std::string("-s")) {
54 itrans.reset(new TBufferedTransport(stdin_trans));
55 } else if (argv[1] == std::string("-z")) {
56 itrans.reset(new TZlibTransport(stdin_trans));
57 } else if (argv[1] == std::string("-f")) {
58 itrans.reset(new TFramedTransport(stdin_trans));
59 } else {
60 usage();
61 }
62
63 shared_ptr<TProtocol> iprot(new TBinaryProtocol(itrans));
64 shared_ptr<TProtocol> oprot(
65 new TDebugProtocol(
66 shared_ptr<TTransport>(new TBufferedTransport(
67 shared_ptr<TTransport>(new TFDTransport(STDOUT_FILENO))))));
68
69 TProtocolTap tap(iprot, oprot);
70
71 try {
72 if (argv[1] == std::string("-s")) {
73 for (;;) {
74 tap.skip(T_STRUCT);
75 }
76 } else {
77 std::string name;
78 TMessageType messageType;
79 int32_t seqid;
80 for (;;) {
81 tap.readMessageBegin(name, messageType, seqid);
82 tap.skip(T_STRUCT);
83 tap.readMessageEnd();
84 }
85 }
86 } catch (TProtocolException exn) {
87 cout << "Protocol Exception: " << exn.what() << endl;
88 } catch (...) {
89 oprot->getTransport()->flush();
90 }
91
92 cout << endl;
93
94 return 0;
95}
Note: See TracBrowser for help on using the repository browser.