From a80f0fb47a43c83438150717a8246760642666f5 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Tue, 8 Apr 2008 05:06:15 +0000 Subject: [PATCH] TDebugProtocol: Support a limit on string length. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665641 13f79535-47bb-0310-9956-ffa450edef68 --- lib/cpp/src/protocol/TDebugProtocol.cpp | 9 ++++++++- lib/cpp/src/protocol/TDebugProtocol.h | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/cpp/src/protocol/TDebugProtocol.cpp b/lib/cpp/src/protocol/TDebugProtocol.cpp index a24bb5b1..e10c6cbc 100644 --- a/lib/cpp/src/protocol/TDebugProtocol.cpp +++ b/lib/cpp/src/protocol/TDebugProtocol.cpp @@ -282,9 +282,15 @@ uint32_t TDebugProtocol::writeDouble(const double dub) { uint32_t TDebugProtocol::writeString(const string& str) { // XXX Raw/UTF-8? + string to_show = str; + if (to_show.length() > (string::size_type)string_limit_) { + to_show = str.substr(0, string_prefix_size_); + to_show += "[...](" + boost::lexical_cast(str.length()) + ")"; + } + string output = "\""; - for (string::const_iterator it = str.begin(); it != str.end(); ++it) { + for (string::const_iterator it = to_show.begin(); it != to_show.end(); ++it) { if (*it == '\\') { output += "\\"; } else if (*it == '"') { @@ -313,6 +319,7 @@ uint32_t TDebugProtocol::writeString(const string& str) { } uint32_t TDebugProtocol::writeBinary(const string& str) { + // XXX Hex? return TDebugProtocol::writeString(str); } diff --git a/lib/cpp/src/protocol/TDebugProtocol.h b/lib/cpp/src/protocol/TDebugProtocol.h index 196cff20..310c2b22 100644 --- a/lib/cpp/src/protocol/TDebugProtocol.h +++ b/lib/cpp/src/protocol/TDebugProtocol.h @@ -50,10 +50,23 @@ class TDebugProtocol : public TWriteOnlyProtocol { public: TDebugProtocol(boost::shared_ptr trans) : TWriteOnlyProtocol(trans, "TDebugProtocol") + , string_limit_(DEFAULT_STRING_LIMIT) + , string_prefix_size_(DEFAULT_STRING_PREFIX_SIZE) { write_state_.push_back(UNINIT); } + static const int32_t DEFAULT_STRING_LIMIT = 256; + static const int32_t DEFAULT_STRING_PREFIX_SIZE = 16; + + void setStringSizeLimit(int32_t string_limit) { + string_limit_ = string_limit; + } + + void setStringPrefixSize(int32_t string_prefix_size) { + string_prefix_size_ = string_prefix_size; + } + virtual uint32_t writeMessageBegin(const std::string& name, const TMessageType messageType, @@ -118,6 +131,9 @@ class TDebugProtocol : public TWriteOnlyProtocol { static std::string fieldTypeName(TType type); + int32_t string_limit_; + int32_t string_prefix_size_; + std::string indent_str_; static const int indent_inc = 2; -- 2.17.1