]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/cpp/src/thrift/protocol/THeaderProtocol.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / thrift / lib / cpp / src / thrift / protocol / THeaderProtocol.cpp
CommitLineData
f67539c2
TL
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#ifndef THRIFT_PROTOCOL_THEADERPROTOCOL_CPP_
20#define THRIFT_PROTOCOL_THEADERPROTOCOL_CPP_ 1
21
22#include <thrift/protocol/THeaderProtocol.h>
23#include <thrift/protocol/TCompactProtocol.h>
24#include <thrift/protocol/TBinaryProtocol.h>
25#include <thrift/TApplicationException.h>
26
27#include <limits>
28
29#include <memory>
30
31namespace apache {
32namespace thrift {
33namespace protocol {
34
35void THeaderProtocol::resetProtocol() {
36 if (proto_ && protoId_ == trans_->getProtocolId()) {
37 return;
38 }
39
40 protoId_ = trans_->getProtocolId();
41
42 switch (protoId_) {
43 case T_BINARY_PROTOCOL:
44 proto_ = std::make_shared<TBinaryProtocolT<THeaderTransport> >(trans_);
45 break;
46
47 case T_COMPACT_PROTOCOL:
48 proto_ = std::make_shared<TCompactProtocolT<THeaderTransport> >(trans_);
49 break;
50
51 default:
52 throw TApplicationException(TApplicationException::INVALID_PROTOCOL,
53 "Unknown protocol requested");
54 }
55}
56
57uint32_t THeaderProtocol::writeMessageBegin(const std::string& name,
58 const TMessageType messageType,
59 const int32_t seqId) {
60 resetProtocol(); // Reset in case we changed protocols
61 trans_->setSequenceNumber(seqId);
62 return proto_->writeMessageBegin(name, messageType, seqId);
63}
64
65uint32_t THeaderProtocol::writeMessageEnd() {
66 return proto_->writeMessageEnd();
67}
68
69uint32_t THeaderProtocol::writeStructBegin(const char* name) {
70 return proto_->writeStructBegin(name);
71}
72
73uint32_t THeaderProtocol::writeStructEnd() {
74 return proto_->writeStructEnd();
75}
76
77uint32_t THeaderProtocol::writeFieldBegin(const char* name,
78 const TType fieldType,
79 const int16_t fieldId) {
80 return proto_->writeFieldBegin(name, fieldType, fieldId);
81}
82
83uint32_t THeaderProtocol::writeFieldEnd() {
84 return proto_->writeFieldEnd();
85}
86
87uint32_t THeaderProtocol::writeFieldStop() {
88 return proto_->writeFieldStop();
89}
90
91uint32_t THeaderProtocol::writeMapBegin(const TType keyType,
92 const TType valType,
93 const uint32_t size) {
94 return proto_->writeMapBegin(keyType, valType, size);
95}
96
97uint32_t THeaderProtocol::writeMapEnd() {
98 return proto_->writeMapEnd();
99}
100
101uint32_t THeaderProtocol::writeListBegin(const TType elemType, const uint32_t size) {
102 return proto_->writeListBegin(elemType, size);
103}
104
105uint32_t THeaderProtocol::writeListEnd() {
106 return proto_->writeListEnd();
107}
108
109uint32_t THeaderProtocol::writeSetBegin(const TType elemType, const uint32_t size) {
110 return proto_->writeSetBegin(elemType, size);
111}
112
113uint32_t THeaderProtocol::writeSetEnd() {
114 return proto_->writeSetEnd();
115}
116
117uint32_t THeaderProtocol::writeBool(const bool value) {
118 return proto_->writeBool(value);
119}
120
121uint32_t THeaderProtocol::writeByte(const int8_t byte) {
122 return proto_->writeByte(byte);
123}
124
125uint32_t THeaderProtocol::writeI16(const int16_t i16) {
126 return proto_->writeI16(i16);
127}
128
129uint32_t THeaderProtocol::writeI32(const int32_t i32) {
130 return proto_->writeI32(i32);
131}
132
133uint32_t THeaderProtocol::writeI64(const int64_t i64) {
134 return proto_->writeI64(i64);
135}
136
137uint32_t THeaderProtocol::writeDouble(const double dub) {
138 return proto_->writeDouble(dub);
139}
140
141uint32_t THeaderProtocol::writeString(const std::string& str) {
142 return proto_->writeString(str);
143}
144
145uint32_t THeaderProtocol::writeBinary(const std::string& str) {
146 return proto_->writeBinary(str);
147}
148
149/**
150 * Reading functions
151 */
152
153uint32_t THeaderProtocol::readMessageBegin(std::string& name,
154 TMessageType& messageType,
155 int32_t& seqId) {
156 // Read the next frame, and change protocols if needed
157 try {
158 trans_->resetProtocol();
159 resetProtocol();
160 } catch (const TApplicationException& ex) {
161 writeMessageBegin("", T_EXCEPTION, 0);
162 ex.write((TProtocol*)this);
163 writeMessageEnd();
164 trans_->flush();
165
166 // The framing is still good, but we don't know about this protocol.
167 // In the future, this could be made a client-side only error if
168 // connection pooling is used.
169 throw ex;
170 }
171 return proto_->readMessageBegin(name, messageType, seqId);
172}
173
174uint32_t THeaderProtocol::readMessageEnd() {
175 return proto_->readMessageEnd();
176}
177
178uint32_t THeaderProtocol::readStructBegin(std::string& name) {
179 return proto_->readStructBegin(name);
180}
181
182uint32_t THeaderProtocol::readStructEnd() {
183 return proto_->readStructEnd();
184}
185
186uint32_t THeaderProtocol::readFieldBegin(std::string& name, TType& fieldType, int16_t& fieldId) {
187 return proto_->readFieldBegin(name, fieldType, fieldId);
188}
189
190uint32_t THeaderProtocol::readFieldEnd() {
191 return proto_->readFieldEnd();
192}
193
194uint32_t THeaderProtocol::readMapBegin(TType& keyType, TType& valType, uint32_t& size) {
195 return proto_->readMapBegin(keyType, valType, size);
196}
197
198uint32_t THeaderProtocol::readMapEnd() {
199 return proto_->readMapEnd();
200}
201
202uint32_t THeaderProtocol::readListBegin(TType& elemType, uint32_t& size) {
203 return proto_->readListBegin(elemType, size);
204}
205
206uint32_t THeaderProtocol::readListEnd() {
207 return proto_->readListEnd();
208}
209
210uint32_t THeaderProtocol::readSetBegin(TType& elemType, uint32_t& size) {
211 return proto_->readSetBegin(elemType, size);
212}
213
214uint32_t THeaderProtocol::readSetEnd() {
215 return proto_->readSetEnd();
216}
217
218uint32_t THeaderProtocol::readBool(bool& value) {
219 return proto_->readBool(value);
220}
221
222uint32_t THeaderProtocol::readByte(int8_t& byte) {
223 return proto_->readByte(byte);
224}
225
226uint32_t THeaderProtocol::readI16(int16_t& i16) {
227 return proto_->readI16(i16);
228}
229
230uint32_t THeaderProtocol::readI32(int32_t& i32) {
231 return proto_->readI32(i32);
232}
233
234uint32_t THeaderProtocol::readI64(int64_t& i64) {
235 return proto_->readI64(i64);
236}
237
238uint32_t THeaderProtocol::readDouble(double& dub) {
239 return proto_->readDouble(dub);
240}
241
242uint32_t THeaderProtocol::readString(std::string& str) {
243 return proto_->readString(str);
244}
245
246uint32_t THeaderProtocol::readBinary(std::string& binary) {
247 return proto_->readBinary(binary);
248}
249}
250}
251} // apache::thrift::protocol
252
253#endif // #ifndef THRIFT_PROTOCOL_THEADERPROTOCOL_CPP_