From 7bba7176194c4d1d9c7066f8eda7a94491d924e6 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Mon, 30 Nov 2026 21:27:55 +0100 Subject: Cleanups and updates --- server/src/http/ext/json.cppm | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'server/src/http/ext/json.cppm') diff --git a/server/src/http/ext/json.cppm b/server/src/http/ext/json.cppm index e69de29..4097253 100644 --- a/server/src/http/ext/json.cppm +++ b/server/src/http/ext/json.cppm @@ -0,0 +1,65 @@ +module; + +#include +#include +#include + +export module routemon:http.ext.json; + +import std; +import :http.core.common; +import :util; + +namespace routemon::http::ext::json { + +namespace { + +namespace json = boost::json; + +} // namespace + +struct body +{ + using value_type = json::value; + + class reader + { + json::stream_parser p_; + util::not_null v_; + + public: + template + explicit reader(bhttp::header&, value_type& v) + : v_{util::not_null{&v}} + { + } + + auto + init(boost::optional /* n */, beast::error_code& ec) noexcept + -> void; + + auto + put(beast::concepts::const_buffer_sequence auto b, + beast::error_code& ec) noexcept -> std::size_t + { + ec = {}; + + auto wrote = 0uz; + for (auto const buf : beast::buffers_range(b)) + { + p_.write(static_cast(buf.data()), buf.size(), ec); + wrote += buf.size(); + if (ec) + break; + } + return wrote; + } + + auto finish(beast::error_code& ec) noexcept -> void; + }; +}; + +static_assert(bhttp::concepts::body); +static_assert(bhttp::concepts::body_reader); + +} // namespace routemon::http::ext::json -- cgit v1.3.1