From a111b40560bf305653b07d8f7289484793a32588 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 24 Feb 2025 03:21:42 +0000 Subject: Allow use of a non-map type as the root RPC element. --- include/modules/rpc.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'include/modules') diff --git a/include/modules/rpc.h b/include/modules/rpc.h index 3af6e81c5..1f136b1e2 100644 --- a/include/modules/rpc.h +++ b/include/modules/rpc.h @@ -58,7 +58,7 @@ public: inline Map &ReplyMap(); }; -class RPC::Map +class RPC::Map final { private: Anope::map replies; @@ -137,10 +137,10 @@ public: }; class RPC::Request final - : public RPC::Map { private: std::optional> error; + std::optional root; public: Anope::string name; @@ -158,7 +158,12 @@ public: this->error.emplace(errcode, errstr); } + template + inline T &Root(); + inline const auto &GetError() const { return this->error; } + + inline const auto &GetRoot() const { return this->root; } }; class RPC::Event @@ -219,3 +224,11 @@ inline RPC::Map &RPC::Map::ReplyMap(const Anope::string &key) auto it = this->replies.emplace(key, RPC::Map()); return std::get(it.first->second.Get()); } + +template +inline T &RPC::Request::Root() +{ + if (!this->root.has_value()) + this->root = RPC::Value(T()); + return std::get(this->root.value().Get()); +} -- cgit