]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_json: add decode / encoder for multimap
authorYehuda Sadeh <yehuda@redhat.com>
Mon, 13 Apr 2015 23:33:17 +0000 (16:33 -0700)
committerKen Dreyer <kdreyer@redhat.com>
Mon, 4 May 2015 18:54:10 +0000 (12:54 -0600)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
(cherry picked from commit 55594623e2a478c3c023336b924bfdef0017d97f)

src/common/ceph_json.h

index f27ee02891053a537d6789b52101ec0dd1e1acb9..604230a59e66a1b912e05478c40cd1d9d319a80a 100644 (file)
@@ -185,6 +185,23 @@ void decode_json_obj(map<K, V>& m, JSONObj *obj)
   }
 }
 
+template<class K, class V>
+void decode_json_obj(multimap<K, V>& m, JSONObj *obj)
+{
+  m.clear();
+
+  JSONObjIter iter = obj->find_first();
+
+  for (; !iter.end(); ++iter) {
+    K key;
+    V val;
+    JSONObj *o = *iter;
+    JSONDecoder::decode_json("key", key, o);
+    JSONDecoder::decode_json("val", val, o);
+    m.insert(make_pair<K, V>(key, val));
+  }
+}
+
 template<class C>
 void decode_json_obj(C& container, void (*cb)(C&, JSONObj *obj), JSONObj *obj)
 {
@@ -302,6 +319,18 @@ static void encode_json(const char *name, const std::map<K, V>& m, ceph::Formatt
   f->close_section();
 }
 
+template<class K, class V>
+static void encode_json(const char *name, const std::multimap<K, V>& m, ceph::Formatter *f)
+{
+  f->open_array_section(name);
+  for (typename std::multimap<K, V>::const_iterator i = m.begin(); i != m.end(); ++i) {
+    f->open_object_section("entry");
+    encode_json("key", i->first, f);
+    encode_json("val", i->second, f);
+    f->close_section();
+  }
+  f->close_section();
+}
 template<class T>
 static void encode_json(const char *name, const std::list<T>& l, ceph::Formatter *f)
 {