From 3ecc2c3e90efc01fafbcacf6bcb0284bfdaaeca6 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Fri, 16 Oct 2015 19:12:01 +0200 Subject: [PATCH] rgw: RGWFormatter_Plain does support key-value style for Bulk Delete API. Signed-off-by: Radoslaw Zarzynski --- src/rgw/rgw_formats.cc | 48 +++++++++++++++++++++++++++++++++--------- src/rgw/rgw_formats.h | 3 ++- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/rgw/rgw_formats.cc b/src/rgw/rgw_formats.cc index d7e47b0bf7a3a..1e730ea823eec 100644 --- a/src/rgw/rgw_formats.cc +++ b/src/rgw/rgw_formats.cc @@ -21,8 +21,12 @@ #define dout_subsys ceph_subsys_rgw -RGWFormatter_Plain::RGWFormatter_Plain() - : buf(NULL), len(0), max_len(0), min_stack_level(0) +RGWFormatter_Plain::RGWFormatter_Plain(const bool ukv) + : buf(NULL), + len(0), + max_len(0), + min_stack_level(0), + use_kv(ukv) { } @@ -64,6 +68,14 @@ void RGWFormatter_Plain::open_array_section(const char *name) struct plain_stack_entry new_entry; new_entry.is_array = true; new_entry.size = 0; + + if (use_kv && min_stack_level > 0 && !stack.empty()) { + struct plain_stack_entry& entry = stack.back(); + + if (!entry.is_array) + dump_format(name, ""); + } + stack.push_back(new_entry); } @@ -79,6 +91,10 @@ void RGWFormatter_Plain::open_object_section(const char *name) struct plain_stack_entry new_entry; new_entry.is_array = false; new_entry.size = 0; + + if (use_kv && min_stack_level > 0) + dump_format(name, ""); + stack.push_back(new_entry); } @@ -131,7 +147,7 @@ void RGWFormatter_Plain::dump_format_va(const char *name, const char *ns, bool q if (!min_stack_level) min_stack_level = stack.size(); - bool should_print = (stack.size() == min_stack_level && !entry.size); + bool should_print = ((stack.size() == min_stack_level && !entry.size) || use_kv); entry.size++; @@ -139,12 +155,20 @@ void RGWFormatter_Plain::dump_format_va(const char *name, const char *ns, bool q return; vsnprintf(buf, LARGE_SIZE, fmt, ap); - if (len) - format = "\n%s"; - else - format = "%s"; - write_data(format, buf); + const char *eol; + if (len) { + if (use_kv && entry.is_array && entry.size > 1) + eol = ", "; + else + eol = "\n"; + } else + eol = ""; + + if (use_kv && !entry.is_array) + write_data("%s%s: %s", eol, name, buf); + else + write_data("%s%s", eol, buf); } int RGWFormatter_Plain::get_len() const @@ -233,7 +257,7 @@ void RGWFormatter_Plain::dump_value_int(const char *name, const char *fmt, ...) min_stack_level = stack.size(); struct plain_stack_entry& entry = stack.back(); - bool should_print = (stack.size() == min_stack_level && !entry.size); + bool should_print = ((stack.size() == min_stack_level && !entry.size) || use_kv); entry.size++; @@ -250,5 +274,9 @@ void RGWFormatter_Plain::dump_value_int(const char *name, const char *fmt, ...) else eol = ""; - write_data("%s%s", eol, buf); + if (use_kv && !entry.is_array) + write_data("%s%s: %s", eol, name, buf); + else + write_data("%s%s", eol, buf); + } diff --git a/src/rgw/rgw_formats.h b/src/rgw/rgw_formats.h index 6f7925e393147..43c087d440ead 100644 --- a/src/rgw/rgw_formats.h +++ b/src/rgw/rgw_formats.h @@ -22,7 +22,7 @@ struct plain_stack_entry { class RGWFormatter_Plain : public Formatter { void reset_buf(); public: - RGWFormatter_Plain(); + RGWFormatter_Plain(bool use_kv = false); virtual ~RGWFormatter_Plain(); virtual void flush(ostream& os); @@ -52,6 +52,7 @@ private: std::list stack; size_t min_stack_level; + bool use_kv; }; class RGWFormatterFlusher { -- 2.39.5