24 #ifndef SEASTAR_MODULE
27 #include <unordered_map>
33 #include <seastar/core/loop.hh>
34 #include <seastar/core/sstring.hh>
35 #include <seastar/core/iostream.hh>
36 #include <seastar/util/modules.hh>
45 typedef struct tm date_time;
57 static sstring begin(state);
58 static sstring end(state);
60 template<
typename K,
typename V>
61 static sstring to_json(state s,
const std::pair<K, V>& p) {
62 return s == state::array ?
63 "{" + to_json(state::none, p) +
"}" :
64 to_json(p.first) +
":" + to_json(p.second);
67 template<
typename Iter>
68 static sstring to_json(state s, Iter i, Iter e) {
69 std::stringstream res;
76 res << to_json(s, *i++);
84 static sstring to_json(state,
const T& t) {
88 template<
typename K,
typename V>
90 if (s == state::array) {
97 return stream.write(to_json(p.first) +
":").then([&p, &
stream] {
98 return write(
stream, p.second);
103 template<
typename Iter>
106 return stream.write(begin(s)).then([&first, &
stream, s, i, e] {
108 auto f = (first) ? make_ready_future<>() :
stream.write(
",");
110 return f.then([&m, &
stream] {
114 return stream.write(end(s));
123 return stream.write(to_json(t));
176 static sstring
to_json(
const char* str,
size_t len);
198 template<
typename... Args>
199 static sstring
to_json(
const std::vector<Args...>& vec) {
200 return to_json(state::array, vec.begin(), vec.end());
203 template<
typename... Args>
204 static sstring to_json(
const std::map<Args...>& map) {
205 return to_json(state::map, map.begin(), map.end());
208 template<
typename... Args>
209 static sstring to_json(
const std::unordered_map<Args...>& map) {
210 return to_json(state::map, map.begin(), map.end());
242 return s.write(to_json(str));
251 return s.write(to_json(n));
260 return s.write(to_json(n));
269 return s.write(to_json(f));
278 return s.write(to_json(d));
287 return s.write(to_json(str));
296 return s.write(to_json(d));
304 template<
typename... Args>
306 return write(s, state::array, vec.begin(), vec.end());
309 template<
typename... Args>
311 return write(s, state::map, map.begin(), map.end());
314 template<
typename... Args>
316 return write(s, state::map, map.begin(), map.end());
325 return s.write(to_json(d));
334 return s.write(to_json(obj));
343 return s.write(to_json(l));
Result then(Func &&func) noexcept
Schedule a block of code to run when the future is ready.
Definition: future.hh:1410
Definition: json_elements.hh:195
auto do_with(T1 &&rv1, T2 &&rv2, More &&... more) noexcept
Definition: do_with.hh:135
future do_for_each(Iterator begin, Iterator end, AsyncAction action) noexcept
Call a function for each item in a range, sequentially (iterator version).
Definition: loop.hh:462
Seastar API namespace.
Definition: abort_on_ebadf.hh:26