Move WebRTC to non deprecated jsoncpp APIs.

This will allow the removal of -Wno-deprecated-declarations from
WebRTC's BUILD.gn files even if [1] will still propagate in the
build graph, causing some ABSL_DEPRECATED to be ignored.

[1] - https://source.chromium.org/chromium/chromium/src/+/main:third_party/jsoncpp/BUILD.gn;l=15;drc=592d07510836410a1ec4833de342544d1b39ef08

Bug: webrtc:10770
Change-Id: I90193ac5cc3e41f00f1b5dd5dac3c462e4b5f9ef
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/223666
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34375}
This commit is contained in:
Mirko Bonadei
2021-06-24 15:24:59 +02:00
committed by WebRTC LUCI CQ
parent 06b8f7ea32
commit e99f6879f6
7 changed files with 38 additions and 18 deletions

View File

@ -11,6 +11,7 @@
#include <stddef.h>
#include <memory>
#include <string>
#include <vector>
@ -156,9 +157,14 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
*parsing_successful = true;
Json::Value root;
bool success = Json::Reader().parse(std::string(json_string), root);
Json::CharReaderBuilder builder;
std::string error_message;
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
bool success =
reader->parse(json_string.data(), json_string.data() + json_string.size(),
&root, &error_message);
if (!success) {
RTC_LOG(LS_ERROR) << "Incorrect JSON format: " << json_string;
RTC_LOG(LS_ERROR) << "Incorrect JSON format: " << error_message;
*parsing_successful = false;
return;
}

View File

@ -951,9 +951,14 @@ TEST_F(RTCStatsCollectorTest, ToJsonProducesParseableJson) {
ExampleStatsGraph graph = SetupExampleStatsGraphForSelectorTests();
rtc::scoped_refptr<const RTCStatsReport> report = stats_->GetStatsReport();
std::string json_format = report->ToJson();
Json::Reader reader;
Json::CharReaderBuilder builder;
Json::Value json_value;
ASSERT_TRUE(reader.parse(json_format, json_value));
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
ASSERT_TRUE(reader->parse(json_format.c_str(),
json_format.c_str() + json_format.size(),
&json_value, nullptr));
// A very brief sanity check on the result.
EXPECT_EQ(report->size(), json_value.size());
}

View File

@ -637,10 +637,6 @@ rtc_library("rtc_stats_counters") {
config("rtc_json_suppressions") {
if (!is_win || is_clang) {
cflags_cc = [
# TODO(bugs.webrtc.org/10770): Update jsoncpp API usage and remove
# -Wno-deprecated-declarations.
"-Wno-deprecated-declarations",
# TODO(bugs.webrtc.org/10814): Remove -Wno-undef as soon as it get
# removed upstream.
"-Wno-undef",

View File

@ -286,9 +286,9 @@ bool GetDoubleFromJsonObject(const Json::Value& in,
}
std::string JsonValueToString(const Json::Value& json) {
Json::FastWriter w;
std::string value = w.write(json);
return value.substr(0, value.size() - 1); // trim trailing newline
Json::StreamWriterBuilder builder;
std::string output = Json::writeString(builder, json);
return output.substr(0, output.size() - 1); // trim trailing newline
}
} // namespace rtc

View File

@ -136,10 +136,15 @@ absl::optional<RtpGeneratorOptions> ParseRtpGeneratorOptionsFromFile(
}
// Parse the file as JSON
Json::Reader json_reader;
Json::CharReaderBuilder builder;
Json::Value json;
if (!json_reader.parse(raw_json_buffer.data(), json)) {
RTC_LOG(LS_ERROR) << "Unable to parse the corpus config json file";
std::string error_message;
std::unique_ptr<Json::CharReader> json_reader(builder.newCharReader());
if (!json_reader->parse(raw_json_buffer.data(),
raw_json_buffer.data() + raw_json_buffer.size(),
&json, &error_message)) {
RTC_LOG(LS_ERROR) << "Unable to parse the corpus config json file. Error:"
<< error_message;
return absl::nullopt;
}

View File

@ -399,11 +399,14 @@ class RtpReplayer final {
std::stringstream raw_json_buffer;
raw_json_buffer << config_file.rdbuf();
std::string raw_json = raw_json_buffer.str();
Json::Reader json_reader;
Json::CharReaderBuilder builder;
Json::Value json_configs;
if (!json_reader.parse(raw_json, json_configs)) {
std::string error_message;
std::unique_ptr<Json::CharReader> json_reader(builder.newCharReader());
if (!json_reader->parse(raw_json.data(), raw_json.data() + raw_json.size(),
&json_configs, &error_message)) {
fprintf(stderr, "Error parsing JSON config\n");
fprintf(stderr, "%s\n", json_reader.getFormatedErrorMessages().c_str());
fprintf(stderr, "%s\n", error_message.c_str());
return nullptr;
}

View File

@ -267,9 +267,14 @@ TEST(RTCStatsTest, RTCStatsPrintsValidJson) {
stats.m_sequence_string = sequence_string;
stats.m_map_string_uint64 = map_string_uint64;
stats.m_map_string_double = map_string_double;
std::string json_stats = stats.ToJson();
Json::CharReaderBuilder builder;
Json::Value json_output;
EXPECT_TRUE(Json::Reader().parse(stats.ToJson(), json_output));
std::unique_ptr<Json::CharReader> json_reader(builder.newCharReader());
EXPECT_TRUE(json_reader->parse(json_stats.c_str(),
json_stats.c_str() + json_stats.size(),
&json_output, nullptr));
EXPECT_TRUE(rtc::GetStringFromJsonObject(json_output, "id", &id));
EXPECT_TRUE(rtc::GetIntFromJsonObject(json_output, "timestamp", &timestamp));