From 0f65f565db308d9bda7a25d0a2ae9b88cbcf2913 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 4 Sep 2015 17:11:05 -0700 Subject: [PATCH] ceph_json: add json encoder / decoder for std::set Signed-off-by: Yehuda Sadeh --- src/common/ceph_json.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/common/ceph_json.h b/src/common/ceph_json.h index 94d690471117d..5a69c77c03a98 100644 --- a/src/common/ceph_json.h +++ b/src/common/ceph_json.h @@ -164,6 +164,21 @@ void decode_json_obj(list& l, JSONObj *obj) } } +template +void decode_json_obj(set& 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 void decode_json_obj(vector& l, JSONObj *obj) { @@ -351,6 +366,15 @@ static void encode_json(const char *name, const std::list& l, ceph::Formatter } f->close_section(); } +template +static void encode_json(const char *name, const std::set& l, ceph::Formatter *f) +{ + f->open_array_section(name); + for (typename std::set::const_iterator iter = l.begin(); iter != l.end(); ++iter) { + encode_json("obj", *iter, f); + } + f->close_section(); +} template static void encode_json(const char *name, const std::vector& l, ceph::Formatter *f) -- 2.39.5