| David Reiss | ea2cba8 | 2009-03-30 21:35:00 +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 | */ |
| Mark Slee | 9f0c651 | 2007-02-28 23:58:26 +0000 | [diff] [blame] | 19 | |
| Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 20 | #ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_ |
| 21 | #define _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_ 1 |
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 22 | |
| Roger Meier | 4285ba2 | 2013-06-10 21:17:23 +0200 | [diff] [blame] | 23 | #include <thrift/protocol/TProtocol.h> |
| 24 | #include <thrift/protocol/TVirtualProtocol.h> |
| Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 25 | |
| cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 26 | #include <memory> |
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 27 | |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 28 | namespace apache { |
| 29 | namespace thrift { |
| 30 | namespace protocol { |
| Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 31 | |
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 32 | /** |
| 33 | * The default binary protocol for thrift. Writes all data in a very basic |
| 34 | * binary format, essentially just spitting out the raw bytes. |
| 35 | * |
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 36 | */ |
| Ben Craig | 384f976 | 2015-07-08 20:33:03 -0500 | [diff] [blame] | 37 | template <class Transport_, class ByteOrder_ = TNetworkBigEndian> |
| 38 | class TBinaryProtocolT : public TVirtualProtocol<TBinaryProtocolT<Transport_, ByteOrder_> > { |
| Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 39 | public: |
| Roger Meier | 406fc74 | 2011-12-08 11:32:21 +0000 | [diff] [blame] | 40 | static const int32_t VERSION_MASK = ((int32_t)0xffff0000); |
| 41 | static const int32_t VERSION_1 = ((int32_t)0x80010000); |
| Randy Abernethy | 8dbe5f6 | 2015-08-01 22:57:02 -0700 | [diff] [blame] | 42 | // VERSION_2 (0x80020000) was taken by TDenseProtocol (which has since been removed) |
| Mark Slee | 808454e | 2007-06-20 21:51:57 +0000 | [diff] [blame] | 43 | |
| cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 44 | TBinaryProtocolT(std::shared_ptr<Transport_> trans) |
| Ben Craig | 384f976 | 2015-07-08 20:33:03 -0500 | [diff] [blame] | 45 | : TVirtualProtocol<TBinaryProtocolT<Transport_, ByteOrder_> >(trans), |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 46 | trans_(trans.get()), |
| 47 | string_limit_(0), |
| 48 | container_limit_(0), |
| 49 | strict_read_(false), |
| Konrad Grochowski | 37b7a0a | 2014-12-04 22:35:39 +0100 | [diff] [blame] | 50 | strict_write_(true) {} |
| Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 51 | |
| cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 52 | TBinaryProtocolT(std::shared_ptr<Transport_> trans, |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 53 | int32_t string_limit, |
| 54 | int32_t container_limit, |
| 55 | bool strict_read, |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 56 | bool strict_write) |
| Ben Craig | 384f976 | 2015-07-08 20:33:03 -0500 | [diff] [blame] | 57 | : TVirtualProtocol<TBinaryProtocolT<Transport_, ByteOrder_> >(trans), |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 58 | trans_(trans.get()), |
| 59 | string_limit_(string_limit), |
| 60 | container_limit_(container_limit), |
| 61 | strict_read_(strict_read), |
| Konrad Grochowski | 37b7a0a | 2014-12-04 22:35:39 +0100 | [diff] [blame] | 62 | strict_write_(strict_write) {} |
| Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 63 | |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 64 | void setStringSizeLimit(int32_t string_limit) { string_limit_ = string_limit; } |
| Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 65 | |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 66 | void setContainerSizeLimit(int32_t container_limit) { container_limit_ = container_limit; } |
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 67 | |
| Mark Slee | 808454e | 2007-06-20 21:51:57 +0000 | [diff] [blame] | 68 | void setStrict(bool strict_read, bool strict_write) { |
| 69 | strict_read_ = strict_read; |
| 70 | strict_write_ = strict_write; |
| 71 | } |
| 72 | |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 73 | /** |
| 74 | * Writing functions. |
| 75 | */ |
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 76 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 77 | /*ol*/ uint32_t writeMessageBegin(const std::string& name, |
| 78 | const TMessageType messageType, |
| 79 | const int32_t seqid); |
| Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 80 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 81 | /*ol*/ uint32_t writeMessageEnd(); |
| Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 82 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 83 | inline uint32_t writeStructBegin(const char* name); |
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 84 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 85 | inline uint32_t writeStructEnd(); |
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 86 | |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 87 | inline uint32_t writeFieldBegin(const char* name, const TType fieldType, const int16_t fieldId); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 88 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 89 | inline uint32_t writeFieldEnd(); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 90 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 91 | inline uint32_t writeFieldStop(); |
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 92 | |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 93 | inline uint32_t writeMapBegin(const TType keyType, const TType valType, const uint32_t size); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 94 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 95 | inline uint32_t writeMapEnd(); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 96 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 97 | inline uint32_t writeListBegin(const TType elemType, const uint32_t size); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 98 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 99 | inline uint32_t writeListEnd(); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 100 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 101 | inline uint32_t writeSetBegin(const TType elemType, const uint32_t size); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 102 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 103 | inline uint32_t writeSetEnd(); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 104 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 105 | inline uint32_t writeBool(const bool value); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 106 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 107 | inline uint32_t writeByte(const int8_t byte); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 108 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 109 | inline uint32_t writeI16(const int16_t i16); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 110 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 111 | inline uint32_t writeI32(const int32_t i32); |
| Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 112 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 113 | inline uint32_t writeI64(const int64_t i64); |
| Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 114 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 115 | inline uint32_t writeDouble(const double dub); |
| Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 116 | |
| Jake Farrell | f42ae01 | 2012-06-22 03:22:53 +0000 | [diff] [blame] | 117 | template <typename StrType> |
| 118 | inline uint32_t writeString(const StrType& str); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 119 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 120 | inline uint32_t writeBinary(const std::string& str); |
| David Reiss | c005b1b | 2008-02-15 01:38:18 +0000 | [diff] [blame] | 121 | |
| CJCombrink | 4b90909 | 2024-04-27 19:51:39 +0200 | [diff] [blame] | 122 | inline uint32_t writeUUID(const TUuid& uuid); |
| CJCombrink | 1d886ca | 2024-03-23 21:32:28 +0100 | [diff] [blame] | 123 | |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 124 | /** |
| 125 | * Reading functions |
| 126 | */ |
| 127 | |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 128 | /*ol*/ uint32_t readMessageBegin(std::string& name, TMessageType& messageType, int32_t& seqid); |
| Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 129 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 130 | /*ol*/ uint32_t readMessageEnd(); |
| Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 131 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 132 | inline uint32_t readStructBegin(std::string& name); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 133 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 134 | inline uint32_t readStructEnd(); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 135 | |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 136 | inline uint32_t readFieldBegin(std::string& name, TType& fieldType, int16_t& fieldId); |
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 137 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 138 | inline uint32_t readFieldEnd(); |
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 139 | |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 140 | inline uint32_t readMapBegin(TType& keyType, TType& valType, uint32_t& size); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 141 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 142 | inline uint32_t readMapEnd(); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 143 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 144 | inline uint32_t readListBegin(TType& elemType, uint32_t& size); |
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 145 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 146 | inline uint32_t readListEnd(); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 147 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 148 | inline uint32_t readSetBegin(TType& elemType, uint32_t& size); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 149 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 150 | inline uint32_t readSetEnd(); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 151 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 152 | inline uint32_t readBool(bool& value); |
| David Reiss | 8dfc732 | 2010-10-06 17:09:58 +0000 | [diff] [blame] | 153 | // Provide the default readBool() implementation for std::vector<bool> |
| Ben Craig | 384f976 | 2015-07-08 20:33:03 -0500 | [diff] [blame] | 154 | using TVirtualProtocol<TBinaryProtocolT<Transport_, ByteOrder_> >::readBool; |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 155 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 156 | inline uint32_t readByte(int8_t& byte); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 157 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 158 | inline uint32_t readI16(int16_t& i16); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 159 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 160 | inline uint32_t readI32(int32_t& i32); |
| Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 161 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 162 | inline uint32_t readI64(int64_t& i64); |
| Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 163 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 164 | inline uint32_t readDouble(double& dub); |
| Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 165 | |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 166 | template <typename StrType> |
| Jake Farrell | f42ae01 | 2012-06-22 03:22:53 +0000 | [diff] [blame] | 167 | inline uint32_t readString(StrType& str); |
| Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 168 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 169 | inline uint32_t readBinary(std::string& str); |
| David Reiss | c005b1b | 2008-02-15 01:38:18 +0000 | [diff] [blame] | 170 | |
| CJCombrink | 4b90909 | 2024-04-27 19:51:39 +0200 | [diff] [blame] | 171 | inline uint32_t readUUID(TUuid& uuid); |
| CJCombrink | 1d886ca | 2024-03-23 21:32:28 +0100 | [diff] [blame] | 172 | |
| Christopher Friedt | cea5559 | 2022-10-01 09:01:45 -0400 | [diff] [blame] | 173 | int getMinSerializedSize(TType type) override; |
| zeshuai007 | 86352b4 | 2020-06-15 17:00:33 +0800 | [diff] [blame] | 174 | |
| Christopher Friedt | cea5559 | 2022-10-01 09:01:45 -0400 | [diff] [blame] | 175 | void checkReadBytesAvailable(TSet& set) override |
| zeshuai007 | 86352b4 | 2020-06-15 17:00:33 +0800 | [diff] [blame] | 176 | { |
| 177 | trans_->checkReadBytesAvailable(set.size_ * getMinSerializedSize(set.elemType_)); |
| 178 | } |
| 179 | |
| Christopher Friedt | cea5559 | 2022-10-01 09:01:45 -0400 | [diff] [blame] | 180 | void checkReadBytesAvailable(TList& list) override |
| zeshuai007 | 86352b4 | 2020-06-15 17:00:33 +0800 | [diff] [blame] | 181 | { |
| 182 | trans_->checkReadBytesAvailable(list.size_ * getMinSerializedSize(list.elemType_)); |
| 183 | } |
| 184 | |
| Christopher Friedt | cea5559 | 2022-10-01 09:01:45 -0400 | [diff] [blame] | 185 | void checkReadBytesAvailable(TMap& map) override |
| zeshuai007 | 86352b4 | 2020-06-15 17:00:33 +0800 | [diff] [blame] | 186 | { |
| 187 | int elmSize = getMinSerializedSize(map.keyType_) + getMinSerializedSize(map.valueType_); |
| 188 | trans_->checkReadBytesAvailable(map.size_ * elmSize); |
| 189 | } |
| 190 | |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 191 | protected: |
| 192 | template <typename StrType> |
| Jake Farrell | f42ae01 | 2012-06-22 03:22:53 +0000 | [diff] [blame] | 193 | uint32_t readStringBody(StrType& str, int32_t sz); |
| Mark Slee | 808454e | 2007-06-20 21:51:57 +0000 | [diff] [blame] | 194 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 195 | Transport_* trans_; |
| 196 | |
| Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 197 | int32_t string_limit_; |
| 198 | int32_t container_limit_; |
| 199 | |
| Mark Slee | 808454e | 2007-06-20 21:51:57 +0000 | [diff] [blame] | 200 | // Enforce presence of version identifier |
| 201 | bool strict_read_; |
| 202 | bool strict_write_; |
| Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 203 | }; |
| 204 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 205 | typedef TBinaryProtocolT<TTransport> TBinaryProtocol; |
| Ben Craig | 384f976 | 2015-07-08 20:33:03 -0500 | [diff] [blame] | 206 | typedef TBinaryProtocolT<TTransport, TNetworkLittleEndian> TLEBinaryProtocol; |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 207 | |
| Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 208 | /** |
| 209 | * Constructs binary protocol handlers |
| 210 | */ |
| Ben Craig | 384f976 | 2015-07-08 20:33:03 -0500 | [diff] [blame] | 211 | template <class Transport_, class ByteOrder_ = TNetworkBigEndian> |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 212 | class TBinaryProtocolFactoryT : public TProtocolFactory { |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 213 | public: |
| 214 | TBinaryProtocolFactoryT() |
| 215 | : string_limit_(0), container_limit_(0), strict_read_(false), strict_write_(true) {} |
| Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 216 | |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 217 | TBinaryProtocolFactoryT(int32_t string_limit, |
| 218 | int32_t container_limit, |
| 219 | bool strict_read, |
| 220 | bool strict_write) |
| 221 | : string_limit_(string_limit), |
| 222 | container_limit_(container_limit), |
| 223 | strict_read_(strict_read), |
| 224 | strict_write_(strict_write) {} |
| Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 225 | |
| Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 226 | ~TBinaryProtocolFactoryT() override = default; |
| Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 227 | |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 228 | void setStringSizeLimit(int32_t string_limit) { string_limit_ = string_limit; } |
| Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 229 | |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 230 | void setContainerSizeLimit(int32_t container_limit) { container_limit_ = container_limit; } |
| Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 231 | |
| Mark Slee | 808454e | 2007-06-20 21:51:57 +0000 | [diff] [blame] | 232 | void setStrict(bool strict_read, bool strict_write) { |
| 233 | strict_read_ = strict_read; |
| 234 | strict_write_ = strict_write; |
| 235 | } |
| 236 | |
| Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 237 | std::shared_ptr<TProtocol> getProtocol(std::shared_ptr<TTransport> trans) override { |
| cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 238 | std::shared_ptr<Transport_> specific_trans = std::dynamic_pointer_cast<Transport_>(trans); |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 239 | TProtocol* prot; |
| 240 | if (specific_trans) { |
| Konrad Grochowski | 7f4be5f | 2015-11-05 20:23:11 +0100 | [diff] [blame] | 241 | prot = new TBinaryProtocolT<Transport_, ByteOrder_>(specific_trans, |
| 242 | string_limit_, |
| 243 | container_limit_, |
| 244 | strict_read_, |
| 245 | strict_write_); |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 246 | } else { |
| Konrad Grochowski | 7f4be5f | 2015-11-05 20:23:11 +0100 | [diff] [blame] | 247 | prot = new TBinaryProtocolT<TTransport, ByteOrder_>(trans, |
| 248 | string_limit_, |
| 249 | container_limit_, |
| 250 | strict_read_, |
| 251 | strict_write_); |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 254 | return std::shared_ptr<TProtocol>(prot); |
| Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 257 | private: |
| Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 258 | int32_t string_limit_; |
| 259 | int32_t container_limit_; |
| Mark Slee | 808454e | 2007-06-20 21:51:57 +0000 | [diff] [blame] | 260 | bool strict_read_; |
| 261 | bool strict_write_; |
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 262 | }; |
| 263 | |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 264 | typedef TBinaryProtocolFactoryT<TTransport> TBinaryProtocolFactory; |
| Ben Craig | 384f976 | 2015-07-08 20:33:03 -0500 | [diff] [blame] | 265 | typedef TBinaryProtocolFactoryT<TTransport, TNetworkLittleEndian> TLEBinaryProtocolFactory; |
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | } // apache::thrift::protocol |
| Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 269 | |
| Roger Meier | 4285ba2 | 2013-06-10 21:17:23 +0200 | [diff] [blame] | 270 | #include <thrift/protocol/TBinaryProtocol.tcc> |
| David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 271 | |
| Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 272 | #endif // #ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_ |