Skip to content

Commit 7b2717f

Browse files
committed
Add to_json method for Bucket::State
Allows for dropping the to_string() when inserting in json objects Change-Id: I29b304e30be71beb4fd2aa999deb1b659b9bb23b Reviewed-on: https://review.couchbase.org/c/kv_engine/+/223805 Reviewed-by: Mohammad Zaeem <[email protected]> Tested-by: Trond Norbye <[email protected]>
1 parent 08efb95 commit 7b2717f

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

daemon/bucket_manager_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ TEST_F(BucketManagerTest, PauseBucket) {
337337
case Bucket::State::Ready:
338338
case Bucket::State::Destroying:
339339
case Bucket::State::Creating:
340-
FAIL() << "Unexpected callback for state:" << to_string(state);
340+
FAIL() << fmt::format("Unexpected callback for state: {}", state);
341341
break;
342342
case Bucket::State::Pausing:
343343
pausing = true;
@@ -435,7 +435,7 @@ void BucketManagerTest::testPauseBucketCancellable(
435435
case Bucket::State::Initializing:
436436
case Bucket::State::Destroying:
437437
case Bucket::State::Creating:
438-
FAIL() << "Unexpected callback for state:" << to_string(state);
438+
FAIL() << fmt::format("Unexpected callback for state: {}", state);
439439
break;
440440
case Bucket::State::Pausing:
441441
pausing = true;

daemon/buckets.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ nlohmann::json Bucket::to_json() const {
8181
if (state != State::None) {
8282
try {
8383
nlohmann::json json;
84-
json["state"] = to_string(state.load());
84+
json["state"] = state.load();
8585
json["clients"] = clients.load();
8686
json["name"] = name;
8787
json["type"] = type;
@@ -423,7 +423,7 @@ std::string validateBucketName(std::string_view name) {
423423
}
424424
}
425425

426-
std::string to_string(Bucket::State state) {
426+
std::string format_as(Bucket::State state) {
427427
switch (state) {
428428
case Bucket::State::None:
429429
return "none";

daemon/buckets.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,12 @@ class Bucket {
386386
};
387387

388388
void to_json(nlohmann::json& json, const Bucket& bucket);
389-
std::string to_string(Bucket::State state);
389+
std::string format_as(Bucket::State state);
390+
391+
template <typename BasicJsonType>
392+
void to_json(BasicJsonType& j, Bucket::State state) {
393+
j = format_as(state);
394+
}
390395

391396
/**
392397
* All of the buckets are stored in the following array. Index 0 is reserved

daemon/protocol/mcbp/set_cluster_config_command_context.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ cb::engine_errc SetClusterConfigCommandContext::doSetClusterConfig() {
114114
{"bucket", bucketname},
115115
{"global", bucketname.empty()},
116116
{"status", status},
117-
{"state", to_string(state)});
117+
{"state", state});
118118
return status;
119119
}
120120

0 commit comments

Comments
 (0)