taras-protsiv commented on a change in pull request #2185:
URL: https://github.com/apache/thrift/pull/2185#discussion_r565037516
##########
File path: lib/cpp/src/thrift/transport/TTransport.h
##########
@@ -238,11 +248,87 @@ class TTransport {
*/
virtual const std::string getOrigin() const { return "Unknown"; }
+ std::shared_ptr<TConfiguration> getConfiguration() { return configuration_; }
+
+ void setConfiguration(std::shared_ptr<TConfiguration> config) {
+ if (config != nullptr) configuration_ = config;
+ }
+
+ /**
+ * Updates RemainingMessageSize to reflect then known real message size
(e.g. framed transport).
+ * Will throw if we already consumed too many bytes or if the new size is
larger than allowed.
+ *
+ * @param size real message size
+ */
+ void updateKnownMessageSize(long int size)
+ {
+ long int consumed = knownMessageSize_ - remainingMessageSize_;
+ resetConsumedMessageSize(size);
+ countConsumedMessageBytes(consumed);
+ }
+
+ /**
+ * Throws if there are not enough bytes in the input stream to satisfy a
read of numBytes bytes of data
+ *
+ * @param numBytes numBytes bytes of data
+ */
+ void checkReadBytesAvailable(long int numBytes)
+ {
+ if (remainingMessageSize_ < numBytes)
+ throw new TTransportException(TTransportException::END_OF_FILE,
"MaxMessageSize reached");
+ }
+
protected:
+ std::shared_ptr<TConfiguration> configuration_;
+ long int remainingMessageSize_;
+ long int knownMessageSize_;
+
+ inline long int getRemainingMessageSize() { return remainingMessageSize_; }
+ inline void setRemainingMessageSize(long int remainingMessageSize) {
remainingMessageSize_ = remainingMessageSize; }
+ inline int getMaxMessageSize() { return configuration_->getMaxMessageSize();
}
+ inline long int getKnownMessageSize() { return knownMessageSize_; }
+ void setKnownMessageSize(long int knownMessageSize) { knownMessageSize_ =
knownMessageSize; }
+
+ /**
+ * Resets RemainingMessageSize to the configured maximum
+ *
+ * @param newSize configured size
+ */
+ void resetConsumedMessageSize(long newSize = -1)
+ {
+ // full reset
+ if (newSize < 0)
+ {
+ knownMessageSize_ = getMaxMessageSize();
+ remainingMessageSize_ = getMaxMessageSize();
+ return;
+ }
+
+ // update only: message size can shrink, but not grow
+ if (newSize > knownMessageSize_)
+ throw new TTransportException(TTransportException::END_OF_FILE,
"MaxMessageSize reached");
Review comment:
throw raw pointer.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]