refactor: folly::dynamic -> nlohmann::json, part 3

This commit is contained in:
Marcus Holland-Moritz 2024-05-13 13:46:16 +02:00
parent 0721b199f5
commit 8903957b63
3 changed files with 18 additions and 15 deletions

View File

@ -212,14 +212,14 @@ class flac_block_compressor final : public block_compressor::impl {
"internal error: flac compression requires metadata"); "internal error: flac compression requires metadata");
} }
auto meta = folly::parseJson(*metadata); auto meta = nlohmann::json::parse(*metadata);
auto endianness = meta["endianness"].asString(); auto endianness = meta["endianness"].get<std::string>();
auto signedness = meta["signedness"].asString(); auto signedness = meta["signedness"].get<std::string>();
auto padding = meta["padding"].asString(); auto padding = meta["padding"].get<std::string>();
auto num_channels = meta["number_of_channels"].asInt(); auto num_channels = meta["number_of_channels"].get<int>();
auto bits_per_sample = meta["bits_per_sample"].asInt(); auto bits_per_sample = meta["bits_per_sample"].get<int>();
auto bytes_per_sample = meta["bytes_per_sample"].asInt(); auto bytes_per_sample = meta["bytes_per_sample"].get<int>();
assert(1 <= bytes_per_sample && bytes_per_sample <= 4); assert(1 <= bytes_per_sample && bytes_per_sample <= 4);
assert(8 <= bits_per_sample && bits_per_sample <= 32); assert(8 <= bits_per_sample && bits_per_sample <= 32);
@ -368,10 +368,10 @@ class flac_block_compressor final : public block_compressor::impl {
compression_constraints compression_constraints
get_compression_constraints(std::string const& metadata) const override { get_compression_constraints(std::string const& metadata) const override {
auto meta = folly::parseJson(metadata); auto meta = nlohmann::json::parse(metadata);
auto num_channels = meta["number_of_channels"].asInt(); auto num_channels = meta["number_of_channels"].get<int>();
auto bytes_per_sample = meta["bytes_per_sample"].asInt(); auto bytes_per_sample = meta["bytes_per_sample"].get<int>();
compression_constraints cc; compression_constraints cc;

View File

@ -27,10 +27,11 @@
#include <folly/String.h> #include <folly/String.h>
#include <folly/container/F14Map.h> #include <folly/container/F14Map.h>
#include <folly/json.h>
#include <fmt/format.h> #include <fmt/format.h>
#include <nlohmann/json.hpp>
#include "dwarfs/checksum.h" #include "dwarfs/checksum.h"
#include "dwarfs/entry.h" #include "dwarfs/entry.h"
#include "dwarfs/file_scanner.h" #include "dwarfs/file_scanner.h"
@ -569,7 +570,8 @@ void file_scanner_<LoggerPolicy>::dump_value(std::ostream& os,
os << "{\n" os << "{\n"
<< " \"ptr\": \"" << " \"ptr\": \""
<< fmt::format("{}", reinterpret_cast<void const*>(p)) << "\",\n" << fmt::format("{}", reinterpret_cast<void const*>(p)) << "\",\n"
<< " \"path\": " << folly::toJson(p->path_as_string()) << ",\n" << " \"path\": " << nlohmann::json{p->path_as_string()}.dump()
<< ",\n"
<< " \"size\": " << fmt::format("{}", p->size()) << ",\n" << " \"size\": " << fmt::format("{}", p->size()) << ",\n"
<< " \"refcnt\": " << fmt::format("{}", p->refcount()) << ",\n" << " \"refcnt\": " << fmt::format("{}", p->refcount()) << ",\n"
<< " \"hash\": \"" << folly::hexlify(p->hash()) << "\",\n" << " \"hash\": \"" << folly::hexlify(p->hash()) << "\",\n"

View File

@ -31,9 +31,10 @@
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <folly/String.h> #include <folly/String.h>
#include <folly/json.h>
#include <folly/lang/Bits.h> #include <folly/lang/Bits.h>
#include <nlohmann/json.hpp>
#include "dwarfs/categorizer.h" #include "dwarfs/categorizer.h"
#include "dwarfs/mmap.h" #include "dwarfs/mmap.h"
@ -171,7 +172,7 @@ TEST_F(fits_categorizer, unused_lsb_count_test) {
EXPECT_EQ(1, unused_lsb_counts.size()); EXPECT_EQ(1, unused_lsb_counts.size());
unsigned unused_lsb_count = *unused_lsb_counts.begin(); unsigned unused_lsb_count = *unused_lsb_counts.begin();
auto json = catmgr->category_metadata(cat); auto json = catmgr->category_metadata(cat);
auto metadata = folly::parseJson(json); auto metadata = nlohmann::json::parse(json);
EXPECT_EQ(unused_lsb_count, metadata["unused_lsb_count"].asInt()); EXPECT_EQ(unused_lsb_count, metadata["unused_lsb_count"].get<int>());
} }
} }