Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Unified Diff: webrtc/stats/rtcstats.cc

Issue 2983243002: Make RTCStatsReport::ToString() return JSON-parseable string. (Closed)
Patch Set: Add test. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/stats/rtcstats.cc
diff --git a/webrtc/stats/rtcstats.cc b/webrtc/stats/rtcstats.cc
index 5d0a937e6f31c12abadc55fa95be9adfb4fac6da..73fc6a5f5073df4a56237f77e01f3150a52cd366 100644
--- a/webrtc/stats/rtcstats.cc
+++ b/webrtc/stats/rtcstats.cc
@@ -18,33 +18,33 @@ namespace webrtc {
namespace {
-// Produces "{ a, b, c }". Works for non-vector |RTCStatsMemberInterface::Type|
+// Produces "[ a, b, c ]". Works for non-vector |RTCStatsMemberInterface::Type|
// types.
template<typename T>
std::string VectorToString(const std::vector<T>& vector) {
if (vector.empty())
- return "{}";
+ return "[]";
std::ostringstream oss;
- oss << "{ " << rtc::ToString<T>(vector[0]);
+ oss << "[ " << rtc::ToString<T>(vector[0]);
for (size_t i = 1; i < vector.size(); ++i) {
oss << ", " << rtc::ToString<T>(vector[i]);
}
- oss << " }";
+ oss << " ]";
return oss.str();
}
-// Produces "{ \"a\", \"b\", \"c\" }". Works for vectors of both const char* and
+// Produces "[ \"a\", \"b\", \"c\" ]". Works for vectors of both const char* and
// std::string element types.
template<typename T>
std::string VectorOfStringsToString(const std::vector<T>& strings) {
if (strings.empty())
- return "{}";
+ return "[]";
std::ostringstream oss;
- oss << "{ \"" << rtc::ToString<T>(strings[0]) << '\"';
+ oss << "[ \"" << rtc::ToString<T>(strings[0]) << '\"';
for (size_t i = 1; i < strings.size(); ++i) {
oss << ", \"" << rtc::ToString<T>(strings[i]) << '\"';
}
- oss << " }";
+ oss << " ]";
return oss.str();
}
@@ -73,20 +73,18 @@ bool RTCStats::operator!=(const RTCStats& other) const {
std::string RTCStats::ToString() const {
std::ostringstream oss;
- oss << type() << " {\n id: \"" << id_ << "\"\n timestamp: "
- << timestamp_us_ << '\n';
+ oss << "{\n \"type\": \"" << type() << "\",\n \"id\": \"" << id_
+ << "\",\n \"timestamp\": " << timestamp_us_;
for (const RTCStatsMemberInterface* member : Members()) {
- oss << " " << member->name() << ": ";
if (member->is_defined()) {
+ oss << ",\n \"" << member->name() << "\": ";
if (member->is_string())
- oss << '"' << member->ValueToString() << "\"\n";
+ oss << '"' << member->ValueToString() << '"';
else
- oss << member->ValueToString() << '\n';
- } else {
- oss << "undefined\n";
+ oss << member->ValueToString();
}
}
- oss << '}';
+ oss << "\n}";
return oss.str();
}

Powered by Google App Engine
This is Rietveld 408576698