Skip to content

Commit 9c2af53

Browse files
committed
bazel: remove baselibs dependency
replace with direct nlohamann json usage
1 parent e40c188 commit 9c2af53

File tree

5 files changed

+15
-23
lines changed

5 files changed

+15
-23
lines changed

.bazelrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ build --java_language_version=17
22
build --tool_java_language_version=17
33
build --java_runtime_version=remotejdk_17
44
build --tool_java_runtime_version=remotejdk_17
5-
build --@score_baselibs//score/json:base_library=nlohmann
65

76
test --test_output=errors
87

MODULE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ rust.toolchain(
5151
versions = ["1.85.0"],
5252
)
5353

54-
# C++ base libs.
55-
bazel_dep(name = "score_baselibs", version = "0.1.2", dev_dependency = True)
54+
# Json for C++.
55+
bazel_dep(name = "nlohmann_json", version = "3.12.0")
5656

5757
# Score Rust crates.
5858
bazel_dep(name = "score_crates", version = "0.0.6")

test_scenarios_cpp/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ cc_library(
3535
],
3636
includes = ["include/"],
3737
visibility = ["//visibility:public"],
38-
deps = ["@score_baselibs//score/json:json_parser"],
38+
deps = ["@nlohmann_json//:json"],
3939
)
4040

4141
cc_test(

test_scenarios_cpp/include/tracing.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <string>
2121

2222
#include "monotonic_clock.hpp"
23-
#include "score/json/json_writer.h"
23+
#include <nlohmann/json.hpp>
2424

2525
#define _TRACING(target, level, fields...) \
2626
do { \
@@ -58,8 +58,7 @@ class Subscriber {
5858
template <typename... T>
5959
void event(const std::optional<std::string>& target, const Level& level,
6060
std::pair<std::string, T>... fields) const {
61-
using namespace score::json;
62-
Object fields_object{object_create(fields...)};
61+
nlohmann::json fields_object = object_create(fields...);
6362
handle_event(target, level, std::move(fields_object));
6463
}
6564

@@ -69,15 +68,15 @@ class Subscriber {
6968
MonotonicClock timer_;
7069

7170
void handle_event(const std::optional<std::string>& target, const Level& level,
72-
score::json::Object&& fields) const;
71+
nlohmann::json&& fields) const;
7372

74-
score::json::Object object_create() const { return score::json::Object{}; }
73+
nlohmann::json object_create() const { return nlohmann::json::object(); }
7574

7675
template <typename HeadT, typename... TailT>
77-
score::json::Object object_create(std::pair<std::string, HeadT> field,
78-
std::pair<std::string, TailT>... fields) const {
79-
auto object{object_create(fields...)};
80-
object.insert(field);
76+
nlohmann::json object_create(std::pair<std::string, HeadT> field,
77+
std::pair<std::string, TailT>... fields) const {
78+
auto object = object_create(fields...);
79+
object[field.first] = field.second;
8180
return object;
8281
}
8382
};

test_scenarios_cpp/src/tracing.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,13 @@ Subscriber::Subscriber(Level max_level, bool thread_ids)
6565
: max_level_{max_level}, thread_ids_{thread_ids} {}
6666

6767
void Subscriber::handle_event(const std::optional<std::string>& target, const Level& level,
68-
score::json::Object&& fields) const {
69-
using namespace score::json;
70-
68+
nlohmann::json&& fields) const {
7169
// Drop handling if below max level.
7270
if (level < max_level_) {
7371
return;
7472
}
7573

76-
Object event;
74+
nlohmann::json event;
7775

7876
// Add timestamp.
7977
event.emplace("timestamp", timer_.format_time());
@@ -98,17 +96,13 @@ void Subscriber::handle_event(const std::optional<std::string>& target, const Le
9896
}
9997

10098
// Make JSON string.
101-
JsonWriter writer;
102-
auto buffer_result{writer.ToBuffer(event)};
103-
if (!buffer_result) {
104-
throw std::runtime_error{"Failed to stringify JSON"};
105-
}
99+
std::string json_str = event.dump();
106100

107101
// Minify JSON and add "\n".
108102
// "\n" + 'std::flush' is used instead of 'std::endl'.
109103
// This is to avoid message mangling in multithreaded scenarios.
110104
std::stringstream ss;
111-
ss << minify_json(*buffer_result) << "\n";
105+
ss << minify_json(json_str) << "\n";
112106

113107
// Print output.
114108
std::cout << ss.str() << std::flush;

0 commit comments

Comments
 (0)