]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/cpp/src/thrift/protocol/TProtocolTap.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / thrift / lib / cpp / src / thrift / protocol / TProtocolTap.h
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 #ifndef _THRIFT_PROTOCOL_TPROTOCOLTAP_H_
21 #define _THRIFT_PROTOCOL_TPROTOCOLTAP_H_ 1
22
23 #include <thrift/protocol/TVirtualProtocol.h>
24
25 namespace apache {
26 namespace thrift {
27 namespace protocol {
28
29 using apache::thrift::transport::TTransport;
30
31 /**
32 * Puts a wiretap on a protocol object. Any reads to this class are passed
33 * through to an enclosed protocol object, but also mirrored as write to a
34 * second protocol object.
35 *
36 */
37 class TProtocolTap : public TVirtualProtocol<TProtocolTap> {
38 public:
39 TProtocolTap(std::shared_ptr<TProtocol> source, std::shared_ptr<TProtocol> sink)
40 : TVirtualProtocol<TProtocolTap>(source->getTransport()), source_(source), sink_(sink) {}
41
42 uint32_t readMessageBegin(std::string& name, TMessageType& messageType, int32_t& seqid) {
43 uint32_t rv = source_->readMessageBegin(name, messageType, seqid);
44 sink_->writeMessageBegin(name, messageType, seqid);
45 return rv;
46 }
47
48 uint32_t readMessageEnd() {
49 uint32_t rv = source_->readMessageEnd();
50 sink_->writeMessageEnd();
51 return rv;
52 }
53
54 uint32_t readStructBegin(std::string& name) {
55 uint32_t rv = source_->readStructBegin(name);
56 sink_->writeStructBegin(name.c_str());
57 return rv;
58 }
59
60 uint32_t readStructEnd() {
61 uint32_t rv = source_->readStructEnd();
62 sink_->writeStructEnd();
63 return rv;
64 }
65
66 uint32_t readFieldBegin(std::string& name, TType& fieldType, int16_t& fieldId) {
67 uint32_t rv = source_->readFieldBegin(name, fieldType, fieldId);
68 if (fieldType == T_STOP) {
69 sink_->writeFieldStop();
70 } else {
71 sink_->writeFieldBegin(name.c_str(), fieldType, fieldId);
72 }
73 return rv;
74 }
75
76 uint32_t readFieldEnd() {
77 uint32_t rv = source_->readFieldEnd();
78 sink_->writeFieldEnd();
79 return rv;
80 }
81
82 uint32_t readMapBegin(TType& keyType, TType& valType, uint32_t& size) {
83 uint32_t rv = source_->readMapBegin(keyType, valType, size);
84 sink_->writeMapBegin(keyType, valType, size);
85 return rv;
86 }
87
88 uint32_t readMapEnd() {
89 uint32_t rv = source_->readMapEnd();
90 sink_->writeMapEnd();
91 return rv;
92 }
93
94 uint32_t readListBegin(TType& elemType, uint32_t& size) {
95 uint32_t rv = source_->readListBegin(elemType, size);
96 sink_->writeListBegin(elemType, size);
97 return rv;
98 }
99
100 uint32_t readListEnd() {
101 uint32_t rv = source_->readListEnd();
102 sink_->writeListEnd();
103 return rv;
104 }
105
106 uint32_t readSetBegin(TType& elemType, uint32_t& size) {
107 uint32_t rv = source_->readSetBegin(elemType, size);
108 sink_->writeSetBegin(elemType, size);
109 return rv;
110 }
111
112 uint32_t readSetEnd() {
113 uint32_t rv = source_->readSetEnd();
114 sink_->writeSetEnd();
115 return rv;
116 }
117
118 uint32_t readBool(bool& value) {
119 uint32_t rv = source_->readBool(value);
120 sink_->writeBool(value);
121 return rv;
122 }
123
124 // Provide the default readBool() implementation for std::vector<bool>
125 using TVirtualProtocol<TProtocolTap>::readBool;
126
127 uint32_t readByte(int8_t& byte) {
128 uint32_t rv = source_->readByte(byte);
129 sink_->writeByte(byte);
130 return rv;
131 }
132
133 uint32_t readI16(int16_t& i16) {
134 uint32_t rv = source_->readI16(i16);
135 sink_->writeI16(i16);
136 return rv;
137 }
138
139 uint32_t readI32(int32_t& i32) {
140 uint32_t rv = source_->readI32(i32);
141 sink_->writeI32(i32);
142 return rv;
143 }
144
145 uint32_t readI64(int64_t& i64) {
146 uint32_t rv = source_->readI64(i64);
147 sink_->writeI64(i64);
148 return rv;
149 }
150
151 uint32_t readDouble(double& dub) {
152 uint32_t rv = source_->readDouble(dub);
153 sink_->writeDouble(dub);
154 return rv;
155 }
156
157 uint32_t readString(std::string& str) {
158 uint32_t rv = source_->readString(str);
159 sink_->writeString(str);
160 return rv;
161 }
162
163 uint32_t readBinary(std::string& str) {
164 uint32_t rv = source_->readBinary(str);
165 sink_->writeBinary(str);
166 return rv;
167 }
168
169 private:
170 std::shared_ptr<TProtocol> source_;
171 std::shared_ptr<TProtocol> sink_;
172 };
173 }
174 }
175 } // apache::thrift::protocol
176
177 #endif // #define _THRIFT_PROTOCOL_TPROTOCOLTAP_H_ 1