mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 18:58:51 +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) {
|
||||
// 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::writeString(const string& str) {
|
||||
}
|
||||
|
||||
uint32_t TDebugProtocol::writeBinary(const string& str) {
|
||||
// XXX Hex?
|
||||
return TDebugProtocol::writeString(str);
|
||||
}
|
||||
|
||||
|
@ -50,10 +50,23 @@ class TDebugProtocol : public TWriteOnlyProtocol {
|
||||
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 @@ 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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user