summaryrefslogtreecommitdiffstats
path: root/src/common/ceph_json.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/ceph_json.h')
-rw-r--r--src/common/ceph_json.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/common/ceph_json.h b/src/common/ceph_json.h
index 08e8d9e4662..f7a899fd935 100644
--- a/src/common/ceph_json.h
+++ b/src/common/ceph_json.h
@@ -836,6 +836,61 @@ public:
DECODE_FINISH(bl);
}
+ void dump(ceph::Formatter *f) const {
+ switch (type) {
+ case FMT_VALUE:
+ if (value.quoted) {
+ f->dump_string("value", value.str);
+ } else {
+ f->dump_format_unquoted("value", "%s", value.str.c_str());
+ }
+ break;
+ case FMT_ARRAY:
+ f->open_array_section("array");
+ for (auto& i : arr) {
+ i.dump(f);
+ }
+ f->close_section();
+ break;
+ case FMT_OBJ:
+ f->open_object_section("object");
+ for (auto& i : obj) {
+ f->dump_object(i.first.c_str(), i.second);
+ }
+ f->close_section();
+ break;
+ default:
+ break;
+ }
+ }
+ static void generate_test_instances(std::list<JSONFormattable*>& o) {
+ o.push_back(new JSONFormattable);
+ o.push_back(new JSONFormattable);
+ o.back()->set_type(FMT_VALUE);
+ o.back()->value.str = "foo";
+ o.back()->value.quoted = true;
+ o.push_back(new JSONFormattable);
+ o.back()->set_type(FMT_VALUE);
+ o.back()->value.str = "foo";
+ o.back()->value.quoted = false;
+ o.push_back(new JSONFormattable);
+ o.back()->set_type(FMT_ARRAY);
+ o.back()->arr.push_back(JSONFormattable());
+ o.back()->arr.back().set_type(FMT_VALUE);
+ o.back()->arr.back().value.str = "foo";
+ o.back()->arr.back().value.quoted = true;
+ o.back()->arr.push_back(JSONFormattable());
+ o.back()->arr.back().set_type(FMT_VALUE);
+ o.back()->arr.back().value.str = "bar";
+ o.back()->arr.back().value.quoted = true;
+ o.push_back(new JSONFormattable);
+ o.back()->set_type(FMT_OBJ);
+ o.back()->obj["foo"] = JSONFormattable();
+ o.back()->obj["foo"].set_type(FMT_VALUE);
+ o.back()->obj["foo"].value.str = "bar";
+ o.back()->obj["foo"].value.quoted = true;
+ }
+
const std::string& val() const {
return value.str;
}