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