nhancdt2602 commented on code in PR #3549:
URL: https://github.com/apache/kvrocks/pull/3549#discussion_r3543130057
##########
src/server/server.cc:
##########
@@ -1548,25 +1548,64 @@ std::string Server::GetInfo(const std::string &ns,
const std::vector<std::string
};
std::string info_str;
+ jsoncons::ojson json_obj;
bool all = sections.empty() || util::FindICase(sections.begin(),
sections.end(), "all") != sections.end();
bool first = true;
for (const auto &[sec, fn] : info_funcs) {
if (all || util::FindICase(sections.begin(), sections.end(), sec) !=
sections.end()) {
- if (first)
- first = false;
- else
- info_str.append("\r\n");
-
- info_str.append("# " + sec + "\r\n");
-
- for (const auto &entry : fn(this)) {
- info_str.append(fmt::format("{}:{}\r\n", entry.name, entry.val));
+ auto entries = fn(this);
+ if (format == InfoFormat::Json) {
+ jsoncons::ojson sec_obj;
+ for (const auto &entry : entries) {
+ std::visit(
+ [&](const auto &v) {
+ using T = std::decay_t<decltype(v)>;
+ if constexpr (std::is_same_v<T, double>) {
+ // Serialize via the same %f text form used above so the
JSON number stays consistent
+ // with the text output (and free of float-to-double
widening noise).
+ sec_obj[entry.name] = std::stod(std::to_string(v));
+ } else {
+ // string -> JSON string, int64/uint64 -> JSON number, bool
-> JSON true/false.
+ sec_obj[entry.name] = v;
+ }
+ },
+ entry.val);
Review Comment:
Thank for clearing it up. I'll keep double value as is in the json format.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]