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
diff --git a/lib/cpp/src/protocol/TDebugProtocol.cpp b/lib/cpp/src/protocol/TDebugProtocol.cpp
index a24bb5b..e10c6cb 100644
--- a/lib/cpp/src/protocol/TDebugProtocol.cpp
+++ b/lib/cpp/src/protocol/TDebugProtocol.cpp
@@ -282,9 +282,15 @@
 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<string>(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::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 196cff2..310c2b2 100644
--- a/lib/cpp/src/protocol/TDebugProtocol.h
+++ b/lib/cpp/src/protocol/TDebugProtocol.h
@@ -50,10 +50,23 @@
  public:
   TDebugProtocol(boost::shared_ptr<TTransport> 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 @@
 
   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;