diff --git a/include/ircd/json/array.h b/include/ircd/json/array.h index 7bad6b5b5..99bdf8a57 100644 --- a/include/ircd/json/array.h +++ b/include/ircd/json/array.h @@ -28,6 +28,9 @@ namespace ircd::json string_view stringify(mutable_buffer &buf, const string_view *const &begin, const string_view *const &end); string_view stringify(mutable_buffer &buf, const std::string *const &begin, const std::string *const &end); + + size_t serialized(const string_view *const &begin, const string_view *const &end); + size_t serialized(const std::string *const &begin, const std::string *const &end); } /// Lightweight interface to a JSON array string. diff --git a/ircd/json.cc b/ircd/json.cc index 4cbf50586..831bcfdc5 100644 --- a/ircd/json.cc +++ b/ircd/json.cc @@ -685,12 +685,28 @@ ircd::json::stringify(mutable_buffer &buf, return array::stringify(buf, b, e); } -ircd::string_view -ircd::json::stringify(mutable_buffer &buf, - const string_view *const &b, - const string_view *const &e) +size_t +ircd::json::serialized(const std::string *const &b, + const std::string *const &e) { - return array::stringify(buf, b, e); + const size_t ret(1 + !std::distance(b, e)); + return std::accumulate(b, e, ret, [] + (auto ret, const auto &value) + { + return ret += serialized(string_view{value}) + 1; + }); +} + +size_t +ircd::json::serialized(const string_view *const &b, + const string_view *const &e) +{ + const size_t ret(1 + !std::distance(b, e)); + return std::accumulate(b, e, ret, [] + (auto ret, const auto &value) + { + return ret += serialized(value) + 1; + }); } template