David Reiss | 00dcccf | 2007-07-21 01:18:10 +0000 | [diff] [blame] | 1 | // Copyright (c) 2006- Facebook |
| 2 | // Distributed under the Thrift Software License |
| 3 | // |
| 4 | // See accompanying file LICENSE or visit the Thrift site at: |
| 5 | // http://developers.facebook.com/thrift/ |
| 6 | |
| 7 | #ifndef _THRIFT_PROTOCOL_TONEWAYPROTOCOL_H_ |
| 8 | #define _THRIFT_PROTOCOL_TONEWAYPROTOCOL_H_ 1 |
| 9 | |
| 10 | #include "TProtocol.h" |
| 11 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 12 | namespace apache { namespace thrift { namespace protocol { |
David Reiss | 00dcccf | 2007-07-21 01:18:10 +0000 | [diff] [blame] | 13 | |
| 14 | /** |
| 15 | * Abstract class for implementing a protocol that can only be written, |
| 16 | * not read. |
| 17 | * |
David Reiss | 00dcccf | 2007-07-21 01:18:10 +0000 | [diff] [blame] | 18 | */ |
| 19 | class TWriteOnlyProtocol : public TProtocol { |
| 20 | public: |
| 21 | /** |
| 22 | * @param subclass_name The name of the concrete subclass. |
| 23 | */ |
| 24 | TWriteOnlyProtocol(boost::shared_ptr<TTransport> trans, |
| 25 | const std::string& subclass_name) |
| 26 | : TProtocol(trans) |
| 27 | , subclass_(subclass_name) |
| 28 | {} |
| 29 | |
| 30 | // All writing functions remain abstract. |
| 31 | |
| 32 | /** |
| 33 | * Reading functions all throw an exception. |
| 34 | */ |
| 35 | |
| 36 | uint32_t readMessageBegin(std::string& name, |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 37 | TMessageType& messageType, |
| 38 | int32_t& seqid) { |
David Reiss | 00dcccf | 2007-07-21 01:18:10 +0000 | [diff] [blame] | 39 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 40 | subclass_ + " does not support reading (yet)."); |
| 41 | } |
| 42 | |
| 43 | uint32_t readMessageEnd() { |
| 44 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 45 | subclass_ + " does not support reading (yet)."); |
| 46 | } |
| 47 | |
| 48 | uint32_t readStructBegin(std::string& name) { |
| 49 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 50 | subclass_ + " does not support reading (yet)."); |
| 51 | } |
| 52 | |
| 53 | uint32_t readStructEnd() { |
| 54 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 55 | subclass_ + " does not support reading (yet)."); |
| 56 | } |
| 57 | |
| 58 | uint32_t readFieldBegin(std::string& name, |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 59 | TType& fieldType, |
| 60 | int16_t& fieldId) { |
David Reiss | 00dcccf | 2007-07-21 01:18:10 +0000 | [diff] [blame] | 61 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 62 | subclass_ + " does not support reading (yet)."); |
| 63 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 64 | |
David Reiss | 00dcccf | 2007-07-21 01:18:10 +0000 | [diff] [blame] | 65 | uint32_t readFieldEnd() { |
| 66 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 67 | subclass_ + " does not support reading (yet)."); |
| 68 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 69 | |
David Reiss | 00dcccf | 2007-07-21 01:18:10 +0000 | [diff] [blame] | 70 | uint32_t readMapBegin(TType& keyType, |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 71 | TType& valType, |
| 72 | uint32_t& size) { |
David Reiss | 00dcccf | 2007-07-21 01:18:10 +0000 | [diff] [blame] | 73 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 74 | subclass_ + " does not support reading (yet)."); |
| 75 | } |
| 76 | |
| 77 | uint32_t readMapEnd() { |
| 78 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 79 | subclass_ + " does not support reading (yet)."); |
| 80 | } |
| 81 | |
| 82 | uint32_t readListBegin(TType& elemType, |
| 83 | uint32_t& size) { |
| 84 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 85 | subclass_ + " does not support reading (yet)."); |
| 86 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 87 | |
David Reiss | 00dcccf | 2007-07-21 01:18:10 +0000 | [diff] [blame] | 88 | uint32_t readListEnd() { |
| 89 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 90 | subclass_ + " does not support reading (yet)."); |
| 91 | } |
| 92 | |
| 93 | uint32_t readSetBegin(TType& elemType, |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 94 | uint32_t& size) { |
David Reiss | 00dcccf | 2007-07-21 01:18:10 +0000 | [diff] [blame] | 95 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 96 | subclass_ + " does not support reading (yet)."); |
| 97 | } |
| 98 | |
| 99 | uint32_t readSetEnd() { |
| 100 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 101 | subclass_ + " does not support reading (yet)."); |
| 102 | } |
| 103 | |
| 104 | uint32_t readBool(bool& value) { |
| 105 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 106 | subclass_ + " does not support reading (yet)."); |
| 107 | } |
| 108 | |
| 109 | uint32_t readByte(int8_t& byte) { |
| 110 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 111 | subclass_ + " does not support reading (yet)."); |
| 112 | } |
| 113 | |
| 114 | uint32_t readI16(int16_t& i16) { |
| 115 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 116 | subclass_ + " does not support reading (yet)."); |
| 117 | } |
| 118 | |
| 119 | uint32_t readI32(int32_t& i32) { |
| 120 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 121 | subclass_ + " does not support reading (yet)."); |
| 122 | } |
| 123 | |
| 124 | uint32_t readI64(int64_t& i64) { |
| 125 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 126 | subclass_ + " does not support reading (yet)."); |
| 127 | } |
| 128 | |
| 129 | uint32_t readDouble(double& dub) { |
| 130 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 131 | subclass_ + " does not support reading (yet)."); |
| 132 | } |
| 133 | |
| 134 | uint32_t readString(std::string& str) { |
| 135 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 136 | subclass_ + " does not support reading (yet)."); |
| 137 | } |
| 138 | |
David Reiss | c005b1b | 2008-02-15 01:38:18 +0000 | [diff] [blame] | 139 | uint32_t readBinary(std::string& str) { |
| 140 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 141 | subclass_ + " does not support reading (yet)."); |
| 142 | } |
David Reiss | 00dcccf | 2007-07-21 01:18:10 +0000 | [diff] [blame] | 143 | |
| 144 | private: |
| 145 | std::string subclass_; |
| 146 | }; |
| 147 | |
David Reiss | e0e3d1b | 2008-04-08 05:06:45 +0000 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * Abstract class for implementing a protocol that can only be read, |
| 151 | * not written. |
| 152 | * |
David Reiss | e0e3d1b | 2008-04-08 05:06:45 +0000 | [diff] [blame] | 153 | */ |
| 154 | class TReadOnlyProtocol : public TProtocol { |
| 155 | public: |
| 156 | /** |
| 157 | * @param subclass_name The name of the concrete subclass. |
| 158 | */ |
| 159 | TReadOnlyProtocol(boost::shared_ptr<TTransport> trans, |
| 160 | const std::string& subclass_name) |
| 161 | : TProtocol(trans) |
| 162 | , subclass_(subclass_name) |
| 163 | {} |
| 164 | |
| 165 | // All reading functions remain abstract. |
| 166 | |
| 167 | /** |
| 168 | * Writing functions all throw an exception. |
| 169 | */ |
| 170 | |
| 171 | uint32_t writeMessageBegin(const std::string& name, |
| 172 | const TMessageType messageType, |
| 173 | const int32_t seqid) { |
| 174 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 175 | subclass_ + " does not support writing (yet)."); |
| 176 | } |
| 177 | |
| 178 | uint32_t writeMessageEnd() { |
| 179 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 180 | subclass_ + " does not support writing (yet)."); |
| 181 | } |
| 182 | |
| 183 | |
David Reiss | 6412000 | 2008-04-29 23:12:24 +0000 | [diff] [blame] | 184 | uint32_t writeStructBegin(const char* name) { |
David Reiss | e0e3d1b | 2008-04-08 05:06:45 +0000 | [diff] [blame] | 185 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 186 | subclass_ + " does not support writing (yet)."); |
| 187 | } |
| 188 | |
| 189 | uint32_t writeStructEnd() { |
| 190 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 191 | subclass_ + " does not support writing (yet)."); |
| 192 | } |
| 193 | |
David Reiss | 6412000 | 2008-04-29 23:12:24 +0000 | [diff] [blame] | 194 | uint32_t writeFieldBegin(const char* name, |
David Reiss | e0e3d1b | 2008-04-08 05:06:45 +0000 | [diff] [blame] | 195 | const TType fieldType, |
| 196 | const int16_t fieldId) { |
| 197 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 198 | subclass_ + " does not support writing (yet)."); |
| 199 | } |
| 200 | |
| 201 | uint32_t writeFieldEnd() { |
| 202 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 203 | subclass_ + " does not support writing (yet)."); |
| 204 | } |
| 205 | |
| 206 | uint32_t writeFieldStop() { |
| 207 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 208 | subclass_ + " does not support writing (yet)."); |
| 209 | } |
| 210 | |
| 211 | uint32_t writeMapBegin(const TType keyType, |
| 212 | const TType valType, |
| 213 | const uint32_t size) { |
| 214 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 215 | subclass_ + " does not support writing (yet)."); |
| 216 | } |
| 217 | |
| 218 | uint32_t writeMapEnd() { |
| 219 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 220 | subclass_ + " does not support writing (yet)."); |
| 221 | } |
| 222 | |
| 223 | uint32_t writeListBegin(const TType elemType, |
| 224 | const uint32_t size) { |
| 225 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 226 | subclass_ + " does not support writing (yet)."); |
| 227 | } |
| 228 | |
| 229 | uint32_t writeListEnd() { |
| 230 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 231 | subclass_ + " does not support writing (yet)."); |
| 232 | } |
| 233 | |
| 234 | uint32_t writeSetBegin(const TType elemType, |
| 235 | const uint32_t size) { |
| 236 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 237 | subclass_ + " does not support writing (yet)."); |
| 238 | } |
| 239 | |
| 240 | uint32_t writeSetEnd() { |
| 241 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 242 | subclass_ + " does not support writing (yet)."); |
| 243 | } |
| 244 | |
| 245 | uint32_t writeBool(const bool value) { |
| 246 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 247 | subclass_ + " does not support writing (yet)."); |
| 248 | } |
| 249 | |
| 250 | uint32_t writeByte(const int8_t byte) { |
| 251 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 252 | subclass_ + " does not support writing (yet)."); |
| 253 | } |
| 254 | |
| 255 | uint32_t writeI16(const int16_t i16) { |
| 256 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 257 | subclass_ + " does not support writing (yet)."); |
| 258 | } |
| 259 | |
| 260 | uint32_t writeI32(const int32_t i32) { |
| 261 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 262 | subclass_ + " does not support writing (yet)."); |
| 263 | } |
| 264 | |
| 265 | uint32_t writeI64(const int64_t i64) { |
| 266 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 267 | subclass_ + " does not support writing (yet)."); |
| 268 | } |
| 269 | |
| 270 | uint32_t writeDouble(const double dub) { |
| 271 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 272 | subclass_ + " does not support writing (yet)."); |
| 273 | } |
| 274 | |
| 275 | uint32_t writeString(const std::string& str) { |
| 276 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 277 | subclass_ + " does not support writing (yet)."); |
| 278 | } |
| 279 | |
| 280 | uint32_t writeBinary(const std::string& str) { |
| 281 | throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, |
| 282 | subclass_ + " does not support writing (yet)."); |
| 283 | } |
| 284 | |
| 285 | private: |
| 286 | std::string subclass_; |
| 287 | }; |
| 288 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 289 | }}} // apache::thrift::protocol |
David Reiss | 00dcccf | 2007-07-21 01:18:10 +0000 | [diff] [blame] | 290 | |
| 291 | #endif // #ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_ |