]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/cpp/src/thrift/protocol/THeaderProtocol.cpp
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
19 #ifndef THRIFT_PROTOCOL_THEADERPROTOCOL_CPP_
20 #define THRIFT_PROTOCOL_THEADERPROTOCOL_CPP_ 1
22 #include <thrift/protocol/THeaderProtocol.h>
23 #include <thrift/protocol/TCompactProtocol.h>
24 #include <thrift/protocol/TBinaryProtocol.h>
25 #include <thrift/TApplicationException.h>
35 void THeaderProtocol::resetProtocol() {
36 if (proto_
&& protoId_
== trans_
->getProtocolId()) {
40 protoId_
= trans_
->getProtocolId();
43 case T_BINARY_PROTOCOL
:
44 proto_
= std::make_shared
<TBinaryProtocolT
<THeaderTransport
> >(trans_
);
47 case T_COMPACT_PROTOCOL
:
48 proto_
= std::make_shared
<TCompactProtocolT
<THeaderTransport
> >(trans_
);
52 throw TApplicationException(TApplicationException::INVALID_PROTOCOL
,
53 "Unknown protocol requested");
57 uint32_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
);
65 uint32_t THeaderProtocol::writeMessageEnd() {
66 return proto_
->writeMessageEnd();
69 uint32_t THeaderProtocol::writeStructBegin(const char* name
) {
70 return proto_
->writeStructBegin(name
);
73 uint32_t THeaderProtocol::writeStructEnd() {
74 return proto_
->writeStructEnd();
77 uint32_t THeaderProtocol::writeFieldBegin(const char* name
,
78 const TType fieldType
,
79 const int16_t fieldId
) {
80 return proto_
->writeFieldBegin(name
, fieldType
, fieldId
);
83 uint32_t THeaderProtocol::writeFieldEnd() {
84 return proto_
->writeFieldEnd();
87 uint32_t THeaderProtocol::writeFieldStop() {
88 return proto_
->writeFieldStop();
91 uint32_t THeaderProtocol::writeMapBegin(const TType keyType
,
93 const uint32_t size
) {
94 return proto_
->writeMapBegin(keyType
, valType
, size
);
97 uint32_t THeaderProtocol::writeMapEnd() {
98 return proto_
->writeMapEnd();
101 uint32_t THeaderProtocol::writeListBegin(const TType elemType
, const uint32_t size
) {
102 return proto_
->writeListBegin(elemType
, size
);
105 uint32_t THeaderProtocol::writeListEnd() {
106 return proto_
->writeListEnd();
109 uint32_t THeaderProtocol::writeSetBegin(const TType elemType
, const uint32_t size
) {
110 return proto_
->writeSetBegin(elemType
, size
);
113 uint32_t THeaderProtocol::writeSetEnd() {
114 return proto_
->writeSetEnd();
117 uint32_t THeaderProtocol::writeBool(const bool value
) {
118 return proto_
->writeBool(value
);
121 uint32_t THeaderProtocol::writeByte(const int8_t byte
) {
122 return proto_
->writeByte(byte
);
125 uint32_t THeaderProtocol::writeI16(const int16_t i16
) {
126 return proto_
->writeI16(i16
);
129 uint32_t THeaderProtocol::writeI32(const int32_t i32
) {
130 return proto_
->writeI32(i32
);
133 uint32_t THeaderProtocol::writeI64(const int64_t i64
) {
134 return proto_
->writeI64(i64
);
137 uint32_t THeaderProtocol::writeDouble(const double dub
) {
138 return proto_
->writeDouble(dub
);
141 uint32_t THeaderProtocol::writeString(const std::string
& str
) {
142 return proto_
->writeString(str
);
145 uint32_t THeaderProtocol::writeBinary(const std::string
& str
) {
146 return proto_
->writeBinary(str
);
153 uint32_t THeaderProtocol::readMessageBegin(std::string
& name
,
154 TMessageType
& messageType
,
156 // Read the next frame, and change protocols if needed
158 trans_
->resetProtocol();
160 } catch (const TApplicationException
& ex
) {
161 writeMessageBegin("", T_EXCEPTION
, 0);
162 ex
.write((TProtocol
*)this);
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.
171 return proto_
->readMessageBegin(name
, messageType
, seqId
);
174 uint32_t THeaderProtocol::readMessageEnd() {
175 return proto_
->readMessageEnd();
178 uint32_t THeaderProtocol::readStructBegin(std::string
& name
) {
179 return proto_
->readStructBegin(name
);
182 uint32_t THeaderProtocol::readStructEnd() {
183 return proto_
->readStructEnd();
186 uint32_t THeaderProtocol::readFieldBegin(std::string
& name
, TType
& fieldType
, int16_t& fieldId
) {
187 return proto_
->readFieldBegin(name
, fieldType
, fieldId
);
190 uint32_t THeaderProtocol::readFieldEnd() {
191 return proto_
->readFieldEnd();
194 uint32_t THeaderProtocol::readMapBegin(TType
& keyType
, TType
& valType
, uint32_t& size
) {
195 return proto_
->readMapBegin(keyType
, valType
, size
);
198 uint32_t THeaderProtocol::readMapEnd() {
199 return proto_
->readMapEnd();
202 uint32_t THeaderProtocol::readListBegin(TType
& elemType
, uint32_t& size
) {
203 return proto_
->readListBegin(elemType
, size
);
206 uint32_t THeaderProtocol::readListEnd() {
207 return proto_
->readListEnd();
210 uint32_t THeaderProtocol::readSetBegin(TType
& elemType
, uint32_t& size
) {
211 return proto_
->readSetBegin(elemType
, size
);
214 uint32_t THeaderProtocol::readSetEnd() {
215 return proto_
->readSetEnd();
218 uint32_t THeaderProtocol::readBool(bool& value
) {
219 return proto_
->readBool(value
);
222 uint32_t THeaderProtocol::readByte(int8_t& byte
) {
223 return proto_
->readByte(byte
);
226 uint32_t THeaderProtocol::readI16(int16_t& i16
) {
227 return proto_
->readI16(i16
);
230 uint32_t THeaderProtocol::readI32(int32_t& i32
) {
231 return proto_
->readI32(i32
);
234 uint32_t THeaderProtocol::readI64(int64_t& i64
) {
235 return proto_
->readI64(i64
);
238 uint32_t THeaderProtocol::readDouble(double& dub
) {
239 return proto_
->readDouble(dub
);
242 uint32_t THeaderProtocol::readString(std::string
& str
) {
243 return proto_
->readString(str
);
246 uint32_t THeaderProtocol::readBinary(std::string
& binary
) {
247 return proto_
->readBinary(binary
);
251 } // apache::thrift::protocol
253 #endif // #ifndef THRIFT_PROTOCOL_THEADERPROTOCOL_CPP_