FastLED 3.10.8
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 297 of file rpc.cpp.hpp.

297 {
298 // If no id, this is a notification - process but don't return response
299 if (!request.contains("id")) {
300 // Still need to execute the method
301 if (request.contains("method")) {
302 auto methodOpt = request["method"].as_string();
303 if (methodOpt.has_value()) {
304 fl::string methodName = methodOpt.value();
305 auto it = mRegistry.find(methodName);
306 if (it != mRegistry.end()) {
307 json params = request.contains("params") ? request["params"] : json::parse("[]");
308 if (params.is_array()) {
309 it->second.mInvoker->invoke(params);
310 }
311 }
312 }
313 }
314 return fl::nullopt;
315 }
316
317 return handle(request);
318}
fl::unordered_map< fl::string, detail::RpcEntry > mRegistry
Definition rpc.h:406
json handle(const json &request) FL_NO_EXCEPT
Process a JSON-RPC request.
Definition rpc.cpp.hpp:126
static json parse(const fl::string &txt) FL_NO_EXCEPT
Definition json.h:842
constexpr nullopt_t nullopt
Definition optional.h:13

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

+ Here is the call graph for this function: