31#include <seastar/core/do_with.hh>
32#include <seastar/core/loop.hh>
33#include <seastar/json/formatter.hh>
34#include <seastar/core/sstring.hh>
35#include <seastar/core/iostream.hh>
36#include <seastar/util/modules.hh>
42SEASTAR_MODULE_EXPORT_BEGIN
58 : _mandatory(false), _set(false) {
71 virtual ~json_base_element() =
default;
79 return !(_mandatory && !_set);
143 return formatter::to_json(_value);
147 return formatter::write(s, _value);
169 _elements.push_back(element);
174 return formatter::to_json(_elements);
184 for (
auto i : list) {
190 return formatter::write(s, _elements);
192 std::vector<T> _elements;
262 bool mandatory =
false);
264 std::vector<json_base_element*> _elements;
306 _res = formatter::to_json(res);
313 _res = std::move(o._res);
314 _body_writer = std::move(o._body_writer);
331template<
typename Container,
typename Func>
332requires requires (Container c, Func aa,
output_stream<char> s) { { formatter::write(s, aa(*c.begin())) } -> std::same_as<future<>>; }
333std::function<future<>(output_stream<char>&&)> stream_range_as_array(Container val, Func fun) {
334 return [val = std::move(val), fun = std::move(fun)](output_stream<char>&& s)
mutable {
335 return do_with(output_stream<char>(std::move(s)), Container(std::move(val)), Func(std::move(fun)),
true, [](output_stream<char>& s,
const Container& val,
const Func& f,
bool& first){
336 return s.write(
"[").then([&val, &s, &first, &f] () {
337 return do_for_each(val, [&s, &first, &f](
const typename Container::value_type& v){
338 auto fut = first ? make_ready_future<>() : s.write(
", ");
340 return fut.then([&s, &f, &v]() {
341 return formatter::write(s, f(v));
360std::function<future<>(output_stream<char>&&)> stream_object(T val) {
361 return [val = std::move(val)](output_stream<char>&& s)
mutable {
362 return do_with(output_stream<char>(std::move(s)), T(std::move(val)), [](output_stream<char>& s,
const T& val){
363 return formatter::write(s, val).finally([&s] {
370SEASTAR_MODULE_EXPORT_END
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
Definition: json_elements.hh:52
json_base_element() noexcept
Definition: json_elements.hh:57
virtual bool is_verify() noexcept
Definition: json_elements.hh:78
virtual std::string to_string()=0
Definition: json_elements.hh:102
json_element & operator=(const C &new_value)
Definition: json_elements.hh:123
const T & operator()() const noexcept
Definition: json_elements.hh:132
json_element & operator=(const T &new_value)
Definition: json_elements.hh:111
virtual std::string to_string() override
Definition: json_elements.hh:141
Definition: json_elements.hh:160
json_list & operator=(const C &list)
Definition: json_elements.hh:182
void push(const T &element)
Definition: json_elements.hh:167
virtual std::string to_string() override
Definition: json_elements.hh:172
Definition: json_elements.hh:195
virtual future write(output_stream< char > &s) const
write an object to the output stream
Definition: json_elements.hh:213
virtual std::string to_json() const =0
future close() noexcept
Definition: iostream-impl.hh:496
future do_for_each(Iterator begin, Sentinel end, AsyncAction action) noexcept
Call a function for each item in a range, sequentially (iterator version).
Definition: loop.hh:465
auto do_with(T1 &&rv1, T2 &&rv2, More &&... more) noexcept
Definition: do_with.hh:135
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
Definition: json_elements.hh:228
virtual bool is_verify() const
virtual future write(output_stream< char > &) const
write to an output stream
virtual std::string to_json() const
virtual void add(json_base_element *element, std::string name, bool mandatory=false)
Definition: json_elements.hh:299
Definition: json_elements.hh:273
virtual future write(output_stream< char > &s) const
write to an output stream
Definition: json_elements.hh:281
virtual std::string to_json() const
Definition: json_elements.hh:274