]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/ceph_json: `encode_json()` for `std::array`
authorAdam Emerson <aemerson@redhat.com>
Mon, 7 Aug 2023 19:36:27 +0000 (15:36 -0400)
committerAdam Emerson <aemerson@redhat.com>
Thu, 14 Sep 2023 21:42:55 +0000 (17:42 -0400)
No decode, though, since JSON arrays can vary in length and
`std::array` cannot.

Signed-off-by: Adam Emerson <aemerson@redhat.com>
src/common/ceph_json.h

index 08e8d9e46623302cdda1d9f30d486a487aaa7bac..4a12c037d8adf08e2b5303c5132988874778d8c2 100644 (file)
@@ -582,6 +582,17 @@ static void encode_json(const char *name, const std::vector<T>& l, ceph::Formatt
   f->close_section();
 }
 
+template<class T, std::size_t N>
+static void encode_json(const char *name, const std::array<T, N>& l,
+                        ceph::Formatter *f)
+{
+  f->open_array_section(name);
+  for (auto iter = l.cbegin(); iter != l.cend(); ++iter) {
+    encode_json("obj", *iter, f);
+  }
+  f->close_section();
+}
+
 template<class K, class V, class C = std::less<K>>
 static void encode_json(const char *name, const std::map<K, V, C>& m, ceph::Formatter *f)
 {