From 4090b80d60a73b7c04e6da5df9f1161501962efb Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 27 Sep 2017 20:47:56 -0700 Subject: [PATCH] ircd::json: Add missing serialized() participants. --- include/ircd/json/array.h | 3 +++ ircd/json.cc | 26 +++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) 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