FastLED 3.9.15
Loading...
Searching...
No Matches

◆ handle_maybe()

fl::optional< json > fl::Rpc::handle_maybe ( const json & request)

For notifications (no id), returns nullopt.

Definition at line 192 of file rpc.cpp.hpp.

192 {
193 // If no id, this is a notification - process but don't return response
194 if (!request.contains("id")) {
195 // Still need to execute the method
196 if (request.contains("method")) {
197 auto methodOpt = request["method"].as_string();
198 if (methodOpt.has_value()) {
199 fl::string methodName = methodOpt.value();
200 auto it = mRegistry.find(methodName);
201 if (it != mRegistry.end()) {
202 json params = request.contains("params") ? request["params"] : json::parse("[]");
203 if (params.is_array()) {
204 it->second.mInvoker->invoke(params);
205 }
206 }
207 }
208 }
209 return fl::nullopt;
210 }
211
212 return handle(request);
213}
fl::unordered_map< fl::string, detail::RpcEntry > mRegistry
Definition rpc.h:387
json handle(const json &request)
Process a JSON-RPC request.
Definition rpc.cpp.hpp:67
static json parse(const fl::string &txt) FL_NOEXCEPT
Definition json.h:677
constexpr nullopt_t nullopt
Definition optional.h:13

References fl::json::as_string(), fl::json::contains(), handle(), fl::json::is_array(), mRegistry, fl::nullopt, and fl::json::parse().

+ Here is the call graph for this function: