]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/Formatter: add support for dumping null
authorPatrick Donnelly <pdonnell@redhat.com>
Fri, 21 Jul 2023 17:57:33 +0000 (13:57 -0400)
committerPatrick Donnelly <pdonnell@redhat.com>
Mon, 9 Oct 2023 15:37:38 +0000 (11:37 -0400)
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
(cherry picked from commit 5f57c526b22af16e8a079aacefcb26cc14202ad2)

src/common/Formatter.cc
src/common/Formatter.h
src/mgr/PyFormatter.cc
src/mgr/PyFormatter.h
src/rgw/rgw_formats.cc
src/rgw/rgw_formats.h

index 4ced59769b508d6d1fb3406ed6374547b98fd5b2..f121afa07a3e386ccbabde7a7b5d614d8fe695ba 100644 (file)
@@ -311,6 +311,11 @@ void JSONFormatter::add_value(std::string_view name, std::string_view val, bool
   }
 }
 
+void JSONFormatter::dump_null(std::string_view name)
+{
+  add_value(name, "null");
+}
+
 void JSONFormatter::dump_unsigned(std::string_view name, uint64_t u)
 {
   add_value(name, u);
@@ -473,6 +478,14 @@ void XMLFormatter::add_value(std::string_view name, T val)
     m_ss << "\n";
 }
 
+void XMLFormatter::dump_null(std::string_view name)
+{
+  print_spaces();
+  m_ss << "<" << get_xml_name(name) << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:nil=\"true\" />";
+  if (m_pretty)
+    m_ss << "\n";
+}
+
 void XMLFormatter::dump_unsigned(std::string_view name, uint64_t u)
 {
   add_value(name, u);
@@ -845,6 +858,11 @@ void TableFormatter::add_value(std::string_view name, T val) {
   m_ss.str("");
 }
 
+void TableFormatter::dump_null(std::string_view name)
+{
+  add_value(name, "null");
+}
+
 void TableFormatter::dump_unsigned(std::string_view name, uint64_t u)
 {
   add_value(name, u);
index 879e1634d8141bbacaa556f6159d28256228aa91..14f30c84f3de7056b2e4ffb1db0e769eb9b6b90f 100644 (file)
@@ -80,6 +80,7 @@ namespace ceph {
     virtual void open_object_section(std::string_view name) = 0;
     virtual void open_object_section_in_ns(std::string_view name, const char *ns) = 0;
     virtual void close_section() = 0;
+    virtual void dump_null(std::string_view name) = 0;
     virtual void dump_unsigned(std::string_view name, uint64_t u) = 0;
     virtual void dump_int(std::string_view name, int64_t s) = 0;
     virtual void dump_float(std::string_view name, double d) = 0;
@@ -149,6 +150,7 @@ namespace ceph {
     void open_object_section(std::string_view name) override;
     void open_object_section_in_ns(std::string_view name, const char *ns) override;
     void close_section() override;
+    void dump_null(std::string_view name) override;
     void dump_unsigned(std::string_view name, uint64_t u) override;
     void dump_int(std::string_view name, int64_t s) override;
     void dump_float(std::string_view name, double d) override;
@@ -221,6 +223,7 @@ namespace ceph {
     void open_object_section(std::string_view name) override;
     void open_object_section_in_ns(std::string_view name, const char *ns) override;
     void close_section() override;
+    void dump_null(std::string_view name) override;
     void dump_unsigned(std::string_view name, uint64_t u) override;
     void dump_int(std::string_view name, int64_t s) override;
     void dump_float(std::string_view name, double d) override;
@@ -277,6 +280,7 @@ namespace ceph {
     void open_object_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) override;
 
     void close_section() override;
+    void dump_null(std::string_view name) override;
     void dump_unsigned(std::string_view name, uint64_t u) override;
     void dump_int(std::string_view name, int64_t s) override;
     void dump_float(std::string_view name, double d) override;
index 8e58f6e9a84ab99aa55592a7d3fe473af1aa3868..6a7f3e98255521d6e52b9cbcc3f8c7e2814746b7 100644 (file)
@@ -37,6 +37,11 @@ void PyFormatter::open_object_section(std::string_view name)
   cursor = dict;
 }
 
+void PyFormatter::dump_null(std::string_view name)
+{
+  dump_pyobject(name, Py_None);
+}
+
 void PyFormatter::dump_unsigned(std::string_view name, uint64_t u)
 {
   PyObject *p = PyLong_FromUnsignedLong(u);
index 5e4c0a679ac34ce427ffff31319aff7d21d3cc34..b45fbf162e0b02cd5881ddb3905b7857e84703e9 100644 (file)
@@ -87,6 +87,7 @@ public:
     stack.pop();
   }
   void dump_bool(std::string_view name, bool b) override;
+  void dump_null(std::string_view name) override;
   void dump_unsigned(std::string_view name, uint64_t u) override;
   void dump_int(std::string_view name, int64_t u) override;
   void dump_float(std::string_view name, double d) override;
index 3affb5f1414250c66771538eb3febe0396098aa0..7ff3128021da3e52d72556921426fc7d35bfc4b0 100644 (file)
@@ -113,6 +113,11 @@ void RGWFormatter_Plain::close_section()
   stack.pop_back();
 }
 
+void RGWFormatter_Plain::dump_null(std::string_view name)
+{
+  dump_value_int(name, "null"); /* I feel a little bad about this. */
+}
+
 void RGWFormatter_Plain::dump_unsigned(std::string_view name, uint64_t u)
 {
   dump_value_int(name, "%" PRIu64, u);
index d7e47259d5839af018af57afca8f166325814cb6..fd79e29671dac9e6ed39ca46ecca40cac1a1d194 100644 (file)
@@ -38,6 +38,7 @@ public:
   void open_object_section(std::string_view name) override;
   void open_object_section_in_ns(std::string_view name, const char *ns) override;
   void close_section() override;
+  void dump_null(std::string_view name) override;
   void dump_unsigned(std::string_view name, uint64_t u) override;
   void dump_int(std::string_view name, int64_t u) override;
   void dump_float(std::string_view name, double d) override;