David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 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_TVIRTUALPROTOCOL_H_ |
| 21 | #define _THRIFT_PROTOCOL_TVIRTUALPROTOCOL_H_ 1 |
| 22 | |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 23 | #include <thrift/protocol/TProtocol.h> |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 24 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 25 | namespace apache { |
| 26 | namespace thrift { |
| 27 | namespace protocol { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 28 | |
| 29 | using apache::thrift::transport::TTransport; |
| 30 | |
| 31 | /** |
| 32 | * Helper class that provides default implementations of TProtocol methods. |
| 33 | * |
| 34 | * This class provides default implementations of the non-virtual TProtocol |
| 35 | * methods. It exists primarily so TVirtualProtocol can derive from it. It |
| 36 | * prevents TVirtualProtocol methods from causing infinite recursion if the |
| 37 | * non-virtual methods are not overridden by the TVirtualProtocol subclass. |
| 38 | * |
| 39 | * You probably don't want to use this class directly. Use TVirtualProtocol |
| 40 | * instead. |
| 41 | */ |
| 42 | class TProtocolDefaults : public TProtocol { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 43 | public: |
| 44 | uint32_t readMessageBegin(std::string& name, TMessageType& messageType, int32_t& seqid) { |
| 45 | (void)name; |
| 46 | (void)messageType; |
| 47 | (void)seqid; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 48 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 49 | "this protocol does not support reading (yet)."); |
| 50 | } |
| 51 | |
| 52 | uint32_t readMessageEnd() { |
| 53 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 54 | "this protocol does not support reading (yet)."); |
| 55 | } |
| 56 | |
| 57 | uint32_t readStructBegin(std::string& name) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 58 | (void)name; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 59 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 60 | "this protocol does not support reading (yet)."); |
| 61 | } |
| 62 | |
| 63 | uint32_t readStructEnd() { |
| 64 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 65 | "this protocol does not support reading (yet)."); |
| 66 | } |
| 67 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 68 | uint32_t readFieldBegin(std::string& name, TType& fieldType, int16_t& fieldId) { |
| 69 | (void)name; |
| 70 | (void)fieldType; |
| 71 | (void)fieldId; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 72 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 73 | "this protocol does not support reading (yet)."); |
| 74 | } |
| 75 | |
| 76 | uint32_t readFieldEnd() { |
| 77 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 78 | "this protocol does not support reading (yet)."); |
| 79 | } |
| 80 | |
| 81 | uint32_t readMapBegin(TType& keyType, TType& valType, uint32_t& size) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 82 | (void)keyType; |
| 83 | (void)valType; |
| 84 | (void)size; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 85 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 86 | "this protocol does not support reading (yet)."); |
| 87 | } |
| 88 | |
| 89 | uint32_t readMapEnd() { |
| 90 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 91 | "this protocol does not support reading (yet)."); |
| 92 | } |
| 93 | |
| 94 | uint32_t readListBegin(TType& elemType, uint32_t& size) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 95 | (void)elemType; |
| 96 | (void)size; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 97 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 98 | "this protocol does not support reading (yet)."); |
| 99 | } |
| 100 | |
| 101 | uint32_t readListEnd() { |
| 102 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 103 | "this protocol does not support reading (yet)."); |
| 104 | } |
| 105 | |
| 106 | uint32_t readSetBegin(TType& elemType, uint32_t& size) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 107 | (void)elemType; |
| 108 | (void)size; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 109 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 110 | "this protocol does not support reading (yet)."); |
| 111 | } |
| 112 | |
| 113 | uint32_t readSetEnd() { |
| 114 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 115 | "this protocol does not support reading (yet)."); |
| 116 | } |
| 117 | |
| 118 | uint32_t readBool(bool& value) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 119 | (void)value; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 120 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 121 | "this protocol does not support reading (yet)."); |
| 122 | } |
| 123 | |
David Reiss | 8dfc732 | 2010-10-06 17:09:58 +0000 | [diff] [blame] | 124 | uint32_t readBool(std::vector<bool>::reference value) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 125 | (void)value; |
David Reiss | 8dfc732 | 2010-10-06 17:09:58 +0000 | [diff] [blame] | 126 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 127 | "this protocol does not support reading (yet)."); |
| 128 | } |
| 129 | |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 130 | uint32_t readByte(int8_t& byte) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 131 | (void)byte; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 132 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 133 | "this protocol does not support reading (yet)."); |
| 134 | } |
| 135 | |
| 136 | uint32_t readI16(int16_t& i16) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 137 | (void)i16; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 138 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 139 | "this protocol does not support reading (yet)."); |
| 140 | } |
| 141 | |
| 142 | uint32_t readI32(int32_t& i32) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 143 | (void)i32; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 144 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 145 | "this protocol does not support reading (yet)."); |
| 146 | } |
| 147 | |
| 148 | uint32_t readI64(int64_t& i64) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 149 | (void)i64; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 150 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 151 | "this protocol does not support reading (yet)."); |
| 152 | } |
| 153 | |
| 154 | uint32_t readDouble(double& dub) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 155 | (void)dub; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 156 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 157 | "this protocol does not support reading (yet)."); |
| 158 | } |
| 159 | |
| 160 | uint32_t readString(std::string& str) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 161 | (void)str; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 162 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 163 | "this protocol does not support reading (yet)."); |
| 164 | } |
| 165 | |
| 166 | uint32_t readBinary(std::string& str) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 167 | (void)str; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 168 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 169 | "this protocol does not support reading (yet)."); |
| 170 | } |
| 171 | |
| 172 | uint32_t writeMessageBegin(const std::string& name, |
| 173 | const TMessageType messageType, |
| 174 | const int32_t seqid) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 175 | (void)name; |
| 176 | (void)messageType; |
| 177 | (void)seqid; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 178 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 179 | "this protocol does not support writing (yet)."); |
| 180 | } |
| 181 | |
| 182 | uint32_t writeMessageEnd() { |
| 183 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 184 | "this protocol does not support writing (yet)."); |
| 185 | } |
| 186 | |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 187 | uint32_t writeStructBegin(const char* name) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 188 | (void)name; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 189 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 190 | "this protocol does not support writing (yet)."); |
| 191 | } |
| 192 | |
| 193 | uint32_t writeStructEnd() { |
| 194 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 195 | "this protocol does not support writing (yet)."); |
| 196 | } |
| 197 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 198 | uint32_t writeFieldBegin(const char* name, const TType fieldType, const int16_t fieldId) { |
| 199 | (void)name; |
| 200 | (void)fieldType; |
| 201 | (void)fieldId; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 202 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 203 | "this protocol does not support writing (yet)."); |
| 204 | } |
| 205 | |
| 206 | uint32_t writeFieldEnd() { |
| 207 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 208 | "this protocol does not support writing (yet)."); |
| 209 | } |
| 210 | |
| 211 | uint32_t writeFieldStop() { |
| 212 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 213 | "this protocol does not support writing (yet)."); |
| 214 | } |
| 215 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 216 | uint32_t writeMapBegin(const TType keyType, const TType valType, const uint32_t size) { |
| 217 | (void)keyType; |
| 218 | (void)valType; |
| 219 | (void)size; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 220 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 221 | "this protocol does not support writing (yet)."); |
| 222 | } |
| 223 | |
| 224 | uint32_t writeMapEnd() { |
| 225 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 226 | "this protocol does not support writing (yet)."); |
| 227 | } |
| 228 | |
| 229 | uint32_t writeListBegin(const TType elemType, const uint32_t size) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 230 | (void)elemType; |
| 231 | (void)size; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 232 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 233 | "this protocol does not support writing (yet)."); |
| 234 | } |
| 235 | |
| 236 | uint32_t writeListEnd() { |
| 237 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 238 | "this protocol does not support writing (yet)."); |
| 239 | } |
| 240 | |
| 241 | uint32_t writeSetBegin(const TType elemType, const uint32_t size) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 242 | (void)elemType; |
| 243 | (void)size; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 244 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 245 | "this protocol does not support writing (yet)."); |
| 246 | } |
| 247 | |
| 248 | uint32_t writeSetEnd() { |
| 249 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 250 | "this protocol does not support writing (yet)."); |
| 251 | } |
| 252 | |
| 253 | uint32_t writeBool(const bool value) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 254 | (void)value; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 255 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 256 | "this protocol does not support writing (yet)."); |
| 257 | } |
| 258 | |
| 259 | uint32_t writeByte(const int8_t byte) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 260 | (void)byte; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 261 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 262 | "this protocol does not support writing (yet)."); |
| 263 | } |
| 264 | |
| 265 | uint32_t writeI16(const int16_t i16) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 266 | (void)i16; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 267 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 268 | "this protocol does not support writing (yet)."); |
| 269 | } |
| 270 | |
| 271 | uint32_t writeI32(const int32_t i32) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 272 | (void)i32; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 273 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 274 | "this protocol does not support writing (yet)."); |
| 275 | } |
| 276 | |
| 277 | uint32_t writeI64(const int64_t i64) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 278 | (void)i64; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 279 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 280 | "this protocol does not support writing (yet)."); |
| 281 | } |
| 282 | |
| 283 | uint32_t writeDouble(const double dub) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 284 | (void)dub; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 285 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 286 | "this protocol does not support writing (yet)."); |
| 287 | } |
| 288 | |
| 289 | uint32_t writeString(const std::string& str) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 290 | (void)str; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 291 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 292 | "this protocol does not support writing (yet)."); |
| 293 | } |
| 294 | |
| 295 | uint32_t writeBinary(const std::string& str) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 296 | (void)str; |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 297 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 298 | "this protocol does not support writing (yet)."); |
| 299 | } |
| 300 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 301 | uint32_t skip(TType type) { return ::apache::thrift::protocol::skip(*this, type); } |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 302 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 303 | protected: |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 304 | TProtocolDefaults(std::shared_ptr<TTransport> ptrans) : TProtocol(ptrans) {} |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 305 | }; |
| 306 | |
| 307 | /** |
| 308 | * Concrete TProtocol classes should inherit from TVirtualProtocol |
| 309 | * so they don't have to manually override virtual methods. |
| 310 | */ |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 311 | template <class Protocol_, class Super_ = TProtocolDefaults> |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 312 | class TVirtualProtocol : public Super_ { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 313 | public: |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 314 | /** |
| 315 | * Writing functions. |
| 316 | */ |
| 317 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 318 | uint32_t writeMessageBegin_virt(const std::string& name, |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 319 | const TMessageType messageType, |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 320 | const int32_t seqid) override { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 321 | return static_cast<Protocol_*>(this)->writeMessageBegin(name, messageType, seqid); |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 324 | uint32_t writeMessageEnd_virt() override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 325 | return static_cast<Protocol_*>(this)->writeMessageEnd(); |
| 326 | } |
| 327 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 328 | uint32_t writeStructBegin_virt(const char* name) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 329 | return static_cast<Protocol_*>(this)->writeStructBegin(name); |
| 330 | } |
| 331 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 332 | uint32_t writeStructEnd_virt() override { return static_cast<Protocol_*>(this)->writeStructEnd(); } |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 333 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 334 | uint32_t writeFieldBegin_virt(const char* name, |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 335 | const TType fieldType, |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 336 | const int16_t fieldId) override { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 337 | return static_cast<Protocol_*>(this)->writeFieldBegin(name, fieldType, fieldId); |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 340 | uint32_t writeFieldEnd_virt() override { return static_cast<Protocol_*>(this)->writeFieldEnd(); } |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 341 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 342 | uint32_t writeFieldStop_virt() override { return static_cast<Protocol_*>(this)->writeFieldStop(); } |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 343 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 344 | uint32_t writeMapBegin_virt(const TType keyType, |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 345 | const TType valType, |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 346 | const uint32_t size) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 347 | return static_cast<Protocol_*>(this)->writeMapBegin(keyType, valType, size); |
| 348 | } |
| 349 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 350 | uint32_t writeMapEnd_virt() override { return static_cast<Protocol_*>(this)->writeMapEnd(); } |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 351 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 352 | uint32_t writeListBegin_virt(const TType elemType, const uint32_t size) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 353 | return static_cast<Protocol_*>(this)->writeListBegin(elemType, size); |
| 354 | } |
| 355 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 356 | uint32_t writeListEnd_virt() override { return static_cast<Protocol_*>(this)->writeListEnd(); } |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 357 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 358 | uint32_t writeSetBegin_virt(const TType elemType, const uint32_t size) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 359 | return static_cast<Protocol_*>(this)->writeSetBegin(elemType, size); |
| 360 | } |
| 361 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 362 | uint32_t writeSetEnd_virt() override { return static_cast<Protocol_*>(this)->writeSetEnd(); } |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 363 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 364 | uint32_t writeBool_virt(const bool value) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 365 | return static_cast<Protocol_*>(this)->writeBool(value); |
| 366 | } |
| 367 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 368 | uint32_t writeByte_virt(const int8_t byte) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 369 | return static_cast<Protocol_*>(this)->writeByte(byte); |
| 370 | } |
| 371 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 372 | uint32_t writeI16_virt(const int16_t i16) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 373 | return static_cast<Protocol_*>(this)->writeI16(i16); |
| 374 | } |
| 375 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 376 | uint32_t writeI32_virt(const int32_t i32) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 377 | return static_cast<Protocol_*>(this)->writeI32(i32); |
| 378 | } |
| 379 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 380 | uint32_t writeI64_virt(const int64_t i64) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 381 | return static_cast<Protocol_*>(this)->writeI64(i64); |
| 382 | } |
| 383 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 384 | uint32_t writeDouble_virt(const double dub) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 385 | return static_cast<Protocol_*>(this)->writeDouble(dub); |
| 386 | } |
| 387 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 388 | uint32_t writeString_virt(const std::string& str) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 389 | return static_cast<Protocol_*>(this)->writeString(str); |
| 390 | } |
| 391 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 392 | uint32_t writeBinary_virt(const std::string& str) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 393 | return static_cast<Protocol_*>(this)->writeBinary(str); |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * Reading functions |
| 398 | */ |
| 399 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 400 | uint32_t readMessageBegin_virt(std::string& name, |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 401 | TMessageType& messageType, |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 402 | int32_t& seqid) override { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 403 | return static_cast<Protocol_*>(this)->readMessageBegin(name, messageType, seqid); |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 406 | uint32_t readMessageEnd_virt() override { return static_cast<Protocol_*>(this)->readMessageEnd(); } |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 407 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 408 | uint32_t readStructBegin_virt(std::string& name) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 409 | return static_cast<Protocol_*>(this)->readStructBegin(name); |
| 410 | } |
| 411 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 412 | uint32_t readStructEnd_virt() override { return static_cast<Protocol_*>(this)->readStructEnd(); } |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 413 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 414 | uint32_t readFieldBegin_virt(std::string& name, TType& fieldType, int16_t& fieldId) override { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 415 | return static_cast<Protocol_*>(this)->readFieldBegin(name, fieldType, fieldId); |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 418 | uint32_t readFieldEnd_virt() override { return static_cast<Protocol_*>(this)->readFieldEnd(); } |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 419 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 420 | uint32_t readMapBegin_virt(TType& keyType, TType& valType, uint32_t& size) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 421 | return static_cast<Protocol_*>(this)->readMapBegin(keyType, valType, size); |
| 422 | } |
| 423 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 424 | uint32_t readMapEnd_virt() override { return static_cast<Protocol_*>(this)->readMapEnd(); } |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 425 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 426 | uint32_t readListBegin_virt(TType& elemType, uint32_t& size) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 427 | return static_cast<Protocol_*>(this)->readListBegin(elemType, size); |
| 428 | } |
| 429 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 430 | uint32_t readListEnd_virt() override { return static_cast<Protocol_*>(this)->readListEnd(); } |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 431 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 432 | uint32_t readSetBegin_virt(TType& elemType, uint32_t& size) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 433 | return static_cast<Protocol_*>(this)->readSetBegin(elemType, size); |
| 434 | } |
| 435 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 436 | uint32_t readSetEnd_virt() override { return static_cast<Protocol_*>(this)->readSetEnd(); } |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 437 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 438 | uint32_t readBool_virt(bool& value) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 439 | return static_cast<Protocol_*>(this)->readBool(value); |
| 440 | } |
| 441 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 442 | uint32_t readBool_virt(std::vector<bool>::reference value) override { |
David Reiss | 8dfc732 | 2010-10-06 17:09:58 +0000 | [diff] [blame] | 443 | return static_cast<Protocol_*>(this)->readBool(value); |
| 444 | } |
| 445 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 446 | uint32_t readByte_virt(int8_t& byte) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 447 | return static_cast<Protocol_*>(this)->readByte(byte); |
| 448 | } |
| 449 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 450 | uint32_t readI16_virt(int16_t& i16) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 451 | return static_cast<Protocol_*>(this)->readI16(i16); |
| 452 | } |
| 453 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 454 | uint32_t readI32_virt(int32_t& i32) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 455 | return static_cast<Protocol_*>(this)->readI32(i32); |
| 456 | } |
| 457 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 458 | uint32_t readI64_virt(int64_t& i64) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 459 | return static_cast<Protocol_*>(this)->readI64(i64); |
| 460 | } |
| 461 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 462 | uint32_t readDouble_virt(double& dub) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 463 | return static_cast<Protocol_*>(this)->readDouble(dub); |
| 464 | } |
| 465 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 466 | uint32_t readString_virt(std::string& str) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 467 | return static_cast<Protocol_*>(this)->readString(str); |
| 468 | } |
| 469 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 470 | uint32_t readBinary_virt(std::string& str) override { |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 471 | return static_cast<Protocol_*>(this)->readBinary(str); |
| 472 | } |
| 473 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 474 | uint32_t skip_virt(TType type) override { return static_cast<Protocol_*>(this)->skip(type); } |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 475 | |
| 476 | /* |
| 477 | * Provide a default skip() implementation that uses non-virtual read |
| 478 | * methods. |
| 479 | * |
| 480 | * Note: subclasses that use TVirtualProtocol to derive from another protocol |
| 481 | * implementation (i.e., not TProtocolDefaults) should beware that this may |
| 482 | * override any non-default skip() implementation provided by the parent |
| 483 | * transport class. They may need to explicitly redefine skip() to call the |
| 484 | * correct parent implementation, if desired. |
| 485 | */ |
| 486 | uint32_t skip(TType type) { |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 487 | auto* const prot = static_cast<Protocol_*>(this); |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 488 | return ::apache::thrift::protocol::skip(*prot, type); |
| 489 | } |
| 490 | |
David Reiss | 8dfc732 | 2010-10-06 17:09:58 +0000 | [diff] [blame] | 491 | /* |
| 492 | * Provide a default readBool() implementation for use with |
| 493 | * std::vector<bool>, that behaves the same as reading into a normal bool. |
| 494 | * |
| 495 | * Subclasses can override this if desired, but there normally shouldn't |
| 496 | * be a need to. |
| 497 | */ |
| 498 | uint32_t readBool(std::vector<bool>::reference value) { |
| 499 | bool b = false; |
| 500 | uint32_t ret = static_cast<Protocol_*>(this)->readBool(b); |
| 501 | value = b; |
| 502 | return ret; |
| 503 | } |
| 504 | using Super_::readBool; // so we don't hide readBool(bool&) |
| 505 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 506 | protected: |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 507 | TVirtualProtocol(std::shared_ptr<TTransport> ptrans) : Super_(ptrans) {} |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 508 | }; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | } // apache::thrift::protocol |
David Reiss | 6806fb8 | 2010-10-06 17:09:52 +0000 | [diff] [blame] | 512 | |
| 513 | #endif // #define _THRIFT_PROTOCOL_TVIRTUALPROTOCOL_H_ 1 |