Using std::ostringstream in key DebugString.
Switching from snprintf to std::ostringstream eliminates cast warning for (unsigned long long). PiperOrigin-RevId: 247326681
This commit is contained in:
parent
3e6c000e18
commit
b7b86baec9
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "port/port.h"
|
#include "port/port.h"
|
||||||
#include "util/coding.h"
|
#include "util/coding.h"
|
||||||
|
|
||||||
@ -23,25 +25,20 @@ void AppendInternalKey(std::string* result, const ParsedInternalKey& key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string ParsedInternalKey::DebugString() const {
|
std::string ParsedInternalKey::DebugString() const {
|
||||||
char buf[50];
|
std::ostringstream ss;
|
||||||
snprintf(buf, sizeof(buf), "' @ %llu : %d", (unsigned long long)sequence,
|
ss << '\'' << EscapeString(user_key.ToString()) << "' @ " << sequence << " : "
|
||||||
int(type));
|
<< static_cast<int>(type);
|
||||||
std::string result = "'";
|
return ss.str();
|
||||||
result += EscapeString(user_key.ToString());
|
|
||||||
result += buf;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string InternalKey::DebugString() const {
|
std::string InternalKey::DebugString() const {
|
||||||
std::string result;
|
|
||||||
ParsedInternalKey parsed;
|
ParsedInternalKey parsed;
|
||||||
if (ParseInternalKey(rep_, &parsed)) {
|
if (ParseInternalKey(rep_, &parsed)) {
|
||||||
result = parsed.DebugString();
|
return parsed.DebugString();
|
||||||
} else {
|
|
||||||
result = "(bad)";
|
|
||||||
result.append(EscapeString(rep_));
|
|
||||||
}
|
}
|
||||||
return result;
|
std::ostringstream ss;
|
||||||
|
ss << "(bad)" << EscapeString(rep_);
|
||||||
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* InternalKeyComparator::Name() const {
|
const char* InternalKeyComparator::Name() const {
|
||||||
|
@ -106,6 +106,20 @@ TEST(FormatTest, InternalKeyShortestSuccessor) {
|
|||||||
ShortSuccessor(IKey("\xff\xff", 100, kTypeValue)));
|
ShortSuccessor(IKey("\xff\xff", 100, kTypeValue)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(FormatTest, ParsedInternalKeyDebugString) {
|
||||||
|
ParsedInternalKey key("The \"key\" in 'single quotes'", 42, kTypeValue);
|
||||||
|
|
||||||
|
ASSERT_EQ("'The \"key\" in 'single quotes'' @ 42 : 1", key.DebugString());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(FormatTest, InternalKeyDebugString) {
|
||||||
|
InternalKey key("The \"key\" in 'single quotes'", 42, kTypeValue);
|
||||||
|
ASSERT_EQ("'The \"key\" in 'single quotes'' @ 42 : 1", key.DebugString());
|
||||||
|
|
||||||
|
InternalKey invalid_key;
|
||||||
|
ASSERT_EQ("(bad)", invalid_key.DebugString());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace leveldb
|
} // namespace leveldb
|
||||||
|
|
||||||
int main(int argc, char** argv) { return leveldb::test::RunAllTests(); }
|
int main(int argc, char** argv) { return leveldb::test::RunAllTests(); }
|
||||||
|
Loading…
Reference in New Issue
Block a user