PragmaTwice commented on code in PR #3549:
URL: https://github.com/apache/kvrocks/pull/3549#discussion_r3543751388
##########
src/server/server.h:
##########
@@ -263,15 +264,40 @@ class Server {
int64_t GetLastBgsaveTime();
std::string GetRoleInfo();
+ // An INFO entry holds its value with its original type in a variant, so
each output format can
+ // render it appropriately: the text format (ToString) emits the
Redis-compatible representation
+ // (e.g. a bool as 0/1, numbers via std::to_string) while FORMAT JSON emits
the native JSON type
+ // (a bool as true/false, numbers unquoted). The type is captured here at
construction.
struct InfoEntry {
+ using Value = std::variant<std::string, int64_t, double, bool>;
std::string name;
- std::string val;
+ Value val;
InfoEntry(std::string name, std::string val) : name(std::move(name)),
val(std::move(val)) {}
- InfoEntry(std::string name, std::string_view val) : name(std::move(name)),
val(val.begin(), val.end()) {}
- InfoEntry(std::string name, const char *val) : name(std::move(name)),
val(val) {}
- template <typename T, std::enable_if_t<std::is_integral_v<T> ||
std::is_floating_point_v<T>, int> = 0>
- InfoEntry(std::string name, T v) : name(std::move(name)),
val(std::to_string(v)) {}
+ InfoEntry(std::string name, std::string_view val) : name(std::move(name)),
val(std::string(val)) {}
+ InfoEntry(std::string name, const char *val) : name(std::move(name)),
val(std::string(val)) {}
+ InfoEntry(std::string name, bool v) : name(std::move(name)), val(v) {}
+ // Floating-point values (incl. float, which widens to double) are stored
as double.
+ InfoEntry(std::string name, double v) : name(std::move(name)), val(v) {}
+ // Integers (bool handled above) are stored as int64_t.
+ template <typename T, std::enable_if_t<std::is_integral_v<T> &&
!std::is_same_v<T, bool>, int> = 0>
+ InfoEntry(std::string name, T v) : name(std::move(name)),
val(static_cast<int64_t>(v)) {}
+
+ // Redis-compatible text form: strings verbatim, booleans as 0/1, numbers
via std::to_string.
+ std::string ToString() const {
Review Comment:
```suggestion
std::string ValueToString() const {
```
--
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]