diff options
author | Sadie Powell <sadie@witchery.services> | 2025-02-24 03:21:42 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2025-02-24 03:41:06 +0000 |
commit | a111b40560bf305653b07d8f7289484793a32588 (patch) | |
tree | b90c6a1070120b5115641414ac2c806efde7c8fa /include/modules | |
parent | 2ccd182d2e6689877eba911452eaa8a06e82ac0b (diff) |
Allow use of a non-map type as the root RPC element.
Diffstat (limited to 'include/modules')
-rw-r--r-- | include/modules/rpc.h | 17 |
1 files changed, 15 insertions, 2 deletions
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<Value> replies; @@ -137,10 +137,10 @@ public: }; class RPC::Request final - : public RPC::Map { private: std::optional<std::pair<int64_t, Anope::string>> error; + std::optional<Value> root; public: Anope::string name; @@ -158,7 +158,12 @@ public: this->error.emplace(errcode, errstr); } + template<typename T = Map> + 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<RPC::Map>(it.first->second.Get()); } + +template<typename T> +inline T &RPC::Request::Root() +{ + if (!this->root.has_value()) + this->root = RPC::Value(T()); + return std::get<T>(this->root.value().Get()); +} |