]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_json: add json encoder / decoder for std::set
authorYehuda Sadeh <yehuda@redhat.com>
Sat, 5 Sep 2015 00:11:05 +0000 (17:11 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 12 Feb 2016 00:12:45 +0000 (16:12 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/common/ceph_json.h

index 94d690471117d6b2a5583b3ed6ecd4535017d4d9..5a69c77c03a9874b1f0f34a9654a24324377f4c1 100644 (file)
@@ -164,6 +164,21 @@ void decode_json_obj(list<T>& l, JSONObj *obj)
   }
 }
 
+template<class T>
+void decode_json_obj(set<T>& l, JSONObj *obj)
+{
+  l.clear();
+
+  JSONObjIter iter = obj->find_first();
+
+  for (; !iter.end(); ++iter) {
+    T val;
+    JSONObj *o = *iter;
+    decode_json_obj(val, o);
+    l.insert(val);
+  }
+}
+
 template<class T>
 void decode_json_obj(vector<T>& l, JSONObj *obj)
 {
@@ -351,6 +366,15 @@ static void encode_json(const char *name, const std::list<T>& l, ceph::Formatter
   }
   f->close_section();
 }
+template<class T>
+static void encode_json(const char *name, const std::set<T>& l, ceph::Formatter *f)
+{
+  f->open_array_section(name);
+  for (typename std::set<T>::const_iterator iter = l.begin(); iter != l.end(); ++iter) {
+    encode_json("obj", *iter, f);
+  }
+  f->close_section();
+}
 
 template<class T>
 static void encode_json(const char *name, const std::vector<T>& l, ceph::Formatter *f)