From 55594623e2a478c3c023336b924bfdef0017d97f Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 13 Apr 2015 16:33:17 -0700 Subject: [PATCH] ceph_json: add decode / encoder for multimap Signed-off-by: Yehuda Sadeh --- src/common/ceph_json.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/common/ceph_json.h b/src/common/ceph_json.h index f27ee0289105..604230a59e66 100644 --- a/src/common/ceph_json.h +++ b/src/common/ceph_json.h @@ -185,6 +185,23 @@ void decode_json_obj(map& m, JSONObj *obj) } } +template +void decode_json_obj(multimap& 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(key, val)); + } +} + template 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& m, ceph::Formatt f->close_section(); } +template +static void encode_json(const char *name, const std::multimap& m, ceph::Formatter *f) +{ + f->open_array_section(name); + for (typename std::multimap::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 static void encode_json(const char *name, const std::list& l, ceph::Formatter *f) { -- 2.47.3