7#include <glaze/glaze.hpp>
9#include <unordered_map>
43namespace morph::backend::detail {
46enum class ExecuteReplyKind : std::uint8_t {
76[[nodiscard]]
inline ExecuteReplyKind classifyExecuteReply(const ::morph::wire::Envelope& env) {
77 if (
env.kind ==
"ok") {
78 return ExecuteReplyKind::Value;
80 if (
env.message == ::morph::wire::kExecuteTimeoutMessage) {
81 return ExecuteReplyKind::Timeout;
83 return ExecuteReplyKind::Error;
99[[nodiscard]]
inline bool routeEvent(const ::morph::wire::Envelope& env,
100 const std::function<
void(::morph::wire::EventBody)>& handler) {
101 if (
env.kind != ::morph::wire::kEventKind) {
105 ::morph::wire::EventBody body;
106 constexpr glz::opts lenient{.error_on_unknown_keys =
false};
107 if (!glz::read<lenient>(body,
env.body)) {
108 handler(std::move(body));
127template <
class PendingT>
128class PendingCallTable {
131 using Map = std::unordered_map<std::uint64_t, PendingT>;
138 [[nodiscard]] std::uint64_t nextCallId() noexcept {
return ++_nextCallId; }
143 void insert(std::uint64_t callId, PendingT pending) { _map.insert_or_assign(callId, std::move(pending)); }
149 [[nodiscard]] std::optional<PendingT> take(std::uint64_t callId) {
150 auto node = _map.extract(callId);
154 return std::optional<PendingT>{std::move(node.mapped())};
163 [[nodiscard]] Map drain() {
return std::exchange(_map, {}); }
167 [[nodiscard]] std::size_t size() const noexcept {
return _map.size(); }
170 std::uint64_t _nextCallId{0};
AnyHandle env(std::string const &name)
A client environment value, {"env": name}: widthClass, locale, platform, online, backend.