mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-08 03:08:53 +00:00
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
This commit is contained in:
parent
2a4bfd6d0c
commit
a80f0fb47a
@ -282,9 +282,15 @@ uint32_t TDebugProtocol::writeDouble(const double dub) {
|
|||||||
uint32_t TDebugProtocol::writeString(const string& str) {
|
uint32_t TDebugProtocol::writeString(const string& str) {
|
||||||
// XXX Raw/UTF-8?
|
// 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 = "\"";
|
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 == '\\') {
|
if (*it == '\\') {
|
||||||
output += "\\";
|
output += "\\";
|
||||||
} else if (*it == '"') {
|
} else if (*it == '"') {
|
||||||
@ -313,6 +319,7 @@ uint32_t TDebugProtocol::writeString(const string& str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t TDebugProtocol::writeBinary(const string& str) {
|
uint32_t TDebugProtocol::writeBinary(const string& str) {
|
||||||
|
// XXX Hex?
|
||||||
return TDebugProtocol::writeString(str);
|
return TDebugProtocol::writeString(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,10 +50,23 @@ class TDebugProtocol : public TWriteOnlyProtocol {
|
|||||||
public:
|
public:
|
||||||
TDebugProtocol(boost::shared_ptr<TTransport> trans)
|
TDebugProtocol(boost::shared_ptr<TTransport> trans)
|
||||||
: TWriteOnlyProtocol(trans, "TDebugProtocol")
|
: TWriteOnlyProtocol(trans, "TDebugProtocol")
|
||||||
|
, string_limit_(DEFAULT_STRING_LIMIT)
|
||||||
|
, string_prefix_size_(DEFAULT_STRING_PREFIX_SIZE)
|
||||||
{
|
{
|
||||||
write_state_.push_back(UNINIT);
|
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,
|
virtual uint32_t writeMessageBegin(const std::string& name,
|
||||||
const TMessageType messageType,
|
const TMessageType messageType,
|
||||||
@ -118,6 +131,9 @@ class TDebugProtocol : public TWriteOnlyProtocol {
|
|||||||
|
|
||||||
static std::string fieldTypeName(TType type);
|
static std::string fieldTypeName(TType type);
|
||||||
|
|
||||||
|
int32_t string_limit_;
|
||||||
|
int32_t string_prefix_size_;
|
||||||
|
|
||||||
std::string indent_str_;
|
std::string indent_str_;
|
||||||
static const int indent_inc = 2;
|
static const int indent_inc = 2;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user