diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2018-02-28 17:49:16 +0300 |
---|---|---|
committer | Aleksandr Zatsepin <alexzatsepin@users.noreply.github.com> | 2018-03-05 12:02:52 +0300 |
commit | ae7e6a385de2338401b56f4fa68dc78c36ce4b22 (patch) | |
tree | fcb3479ee806398c954afcee1effe85bc19768f1 /coding/serdes_json.hpp | |
parent | 455527be5fca8895cf755cb6c8d0f16ff524a9a9 (diff) |
Changed cloud interface
Diffstat (limited to 'coding/serdes_json.hpp')
-rw-r--r-- | coding/serdes_json.hpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/coding/serdes_json.hpp b/coding/serdes_json.hpp index 79278eba44..9fa9ca40c5 100644 --- a/coding/serdes_json.hpp +++ b/coding/serdes_json.hpp @@ -26,17 +26,32 @@ public: m_sink.Write(buffer.get(), strlen(buffer.get())); } - void operator()(bool const d, char const * name = nullptr) { ToJSONObject(*m_json, name, d); } - void operator()(uint8_t const d, char const * name = nullptr) { ToJSONObject(*m_json, name, d); } - void operator()(uint32_t const d, char const * name = nullptr) { ToJSONObject(*m_json, name, d); } - void operator()(uint64_t const d, char const * name = nullptr) { ToJSONObject(*m_json, name, d); } - void operator()(int64_t const d, char const * name = nullptr) { ToJSONObject(*m_json, name, d); } - void operator()(double const d, char const * name = nullptr) { ToJSONObject(*m_json, name, d); } - void operator()(std::string const & s, char const * name = nullptr) + template <typename T> + void ToJsonObjectOrValue(T const & value, char const * name) { - ToJSONObject(*m_json, name, s); + if (name != nullptr) + { + ToJSONObject(*m_json, name, value); + } + else if (json_is_array(m_json)) + { + auto json = ToJSON(value); + json_array_append_new(m_json.get(), json.release()); + } + else + { + ASSERT(false, ("Unsupported JSON structure")); + } } + void operator()(bool const d, char const * name = nullptr) { ToJsonObjectOrValue(d, name); } + void operator()(uint8_t const d, char const * name = nullptr) { ToJsonObjectOrValue(d, name); } + void operator()(uint32_t const d, char const * name = nullptr) { ToJsonObjectOrValue(d, name); } + void operator()(uint64_t const d, char const * name = nullptr) { ToJsonObjectOrValue(d, name); } + void operator()(int64_t const d, char const * name = nullptr) { ToJsonObjectOrValue(d, name); } + void operator()(double const d, char const * name = nullptr) { ToJsonObjectOrValue(d, name); } + void operator()(std::string const & s, char const * name = nullptr) { ToJsonObjectOrValue(s, name); } + template <typename T> void operator()(std::vector<T> const & vs, char const * name = nullptr) { |