mirror of
https://github.com/matrix-construct/construct
synced 2025-02-27 22:20:15 +01:00
ircd::json: Workaround buffer_sink action.
This commit is contained in:
parent
53b304cb7a
commit
f2f3e9a8a5
1 changed files with 91 additions and 22 deletions
113
ircd/json.cc
113
ircd/json.cc
|
@ -210,6 +210,16 @@ ircd::json::printer
|
||||||
:karma::grammar<char *, unused_type>
|
:karma::grammar<char *, unused_type>
|
||||||
{
|
{
|
||||||
using it = char *;
|
using it = char *;
|
||||||
|
using prop_mask = mpl_::int_
|
||||||
|
<
|
||||||
|
karma::generator_properties::no_properties
|
||||||
|
| karma::generator_properties::buffering
|
||||||
|
| karma::generator_properties::counting
|
||||||
|
| karma::generator_properties::tracking
|
||||||
|
| karma::generator_properties::disabling
|
||||||
|
>;
|
||||||
|
using sink_type = karma::detail::output_iterator<it, prop_mask, unused_type>;
|
||||||
|
static thread_local mutable_buffer *sink_buffer;
|
||||||
|
|
||||||
template<class T = unused_type,
|
template<class T = unused_type,
|
||||||
class... A>
|
class... A>
|
||||||
|
@ -454,6 +464,43 @@ noexcept
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
thread_local
|
||||||
|
decltype(ircd::json::printer::sink_buffer)
|
||||||
|
ircd::json::printer::sink_buffer;
|
||||||
|
|
||||||
|
template<>
|
||||||
|
[[gnu::visibility("internal")]]
|
||||||
|
inline bool
|
||||||
|
boost::spirit::karma::detail::buffer_sink::copy(ircd::json::printer::sink_type &sink,
|
||||||
|
size_t maxwidth)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
assert(ircd::json::printer::sink_buffer);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
[[gnu::visibility("internal")]]
|
||||||
|
inline bool
|
||||||
|
boost::spirit::karma::detail::buffer_sink::copy_rest(ircd::json::printer::sink_type &sink,
|
||||||
|
size_t start_at)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
assert(ircd::json::printer::sink_buffer);
|
||||||
|
assert(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
[[gnu::visibility("internal")]]
|
||||||
|
inline void
|
||||||
|
boost::spirit::karma::detail::buffer_sink::output(const char &value)
|
||||||
|
{
|
||||||
|
assert(ircd::json::printer::sink_buffer);
|
||||||
|
auto &buf(*ircd::json::printer::sink_buffer);
|
||||||
|
ircd::consume(buf, ircd::copy(buf, value));
|
||||||
|
}
|
||||||
|
|
||||||
template<class gen,
|
template<class gen,
|
||||||
class... attr>
|
class... attr>
|
||||||
[[gnu::visibility("internal")]]
|
[[gnu::visibility("internal")]]
|
||||||
|
@ -463,16 +510,6 @@ ircd::json::printer::operator()(mutable_buffer &out,
|
||||||
attr&&... a)
|
attr&&... a)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
const auto maxwidth
|
|
||||||
{
|
|
||||||
karma::maxwidth(size(out))
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto gg
|
|
||||||
{
|
|
||||||
maxwidth[std::forward<gen>(g)]
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto throws{[&out]
|
const auto throws{[&out]
|
||||||
{
|
{
|
||||||
throw print_panic
|
throw print_panic
|
||||||
|
@ -484,9 +521,30 @@ const
|
||||||
};
|
};
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
const auto maxwidth
|
||||||
|
{
|
||||||
|
karma::maxwidth(size(out))
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto gg
|
||||||
|
{
|
||||||
|
maxwidth[std::forward<gen>(g)]
|
||||||
|
};
|
||||||
|
|
||||||
|
assert(!sink_buffer);
|
||||||
|
const scope_restore set_sink_buffer
|
||||||
|
{
|
||||||
|
sink_buffer, &out
|
||||||
|
};
|
||||||
|
|
||||||
|
sink_type sink
|
||||||
|
{
|
||||||
|
begin(out)
|
||||||
|
};
|
||||||
|
|
||||||
const auto ret
|
const auto ret
|
||||||
{
|
{
|
||||||
karma::generate(begin(out), gg | eps[throws], std::forward<attr>(a)...)
|
karma::generate(sink, gg | eps[throws], std::forward<attr>(a)...)
|
||||||
};
|
};
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -499,16 +557,6 @@ ircd::json::printer::operator()(mutable_buffer &out,
|
||||||
gen&& g)
|
gen&& g)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
const auto maxwidth
|
|
||||||
{
|
|
||||||
karma::maxwidth(size(out))
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto gg
|
|
||||||
{
|
|
||||||
maxwidth[std::forward<gen>(g)]
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto throws{[&out]
|
const auto throws{[&out]
|
||||||
{
|
{
|
||||||
throw print_panic
|
throw print_panic
|
||||||
|
@ -519,9 +567,30 @@ const
|
||||||
};
|
};
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
const auto maxwidth
|
||||||
|
{
|
||||||
|
karma::maxwidth(size(out))
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto gg
|
||||||
|
{
|
||||||
|
maxwidth[std::forward<gen>(g)]
|
||||||
|
};
|
||||||
|
|
||||||
|
assert(!sink_buffer);
|
||||||
|
const scope_restore set_sink_buffer
|
||||||
|
{
|
||||||
|
sink_buffer, &out
|
||||||
|
};
|
||||||
|
|
||||||
|
sink_type sink
|
||||||
|
{
|
||||||
|
begin(out)
|
||||||
|
};
|
||||||
|
|
||||||
const auto ret
|
const auto ret
|
||||||
{
|
{
|
||||||
karma::generate(begin(out), gg | eps[throws])
|
karma::generate(sink, gg | eps[throws])
|
||||||
};
|
};
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Add table
Reference in a new issue