FastLED 3.10.9
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 327 of file rpc.cpp.hpp.

327 {
328 // If no id, this is a notification - process but don't return response
329 if (!request.contains("id")) {
330 // Still need to execute the method
331 if (request.contains("method")) {
332 auto methodOpt = request["method"].as_string();
333 if (methodOpt.has_value()) {
334 fl::string methodName = methodOpt.value();
335 auto it = mRegistry.find(methodName);
336 if (it != mRegistry.end()) {
337 json params = request.contains("params") ? request["params"] : json::parse("[]");
338 if (params.is_array()) {
339 it->second.mInvoker->invoke(params);
340 }
341 }
342 }
343 }
344 return fl::nullopt;
345 }
346
347 return handle(request);
348}
fl::unordered_map< fl::string, detail::RpcEntry > mRegistry
Definition rpc.h:417
json handle(const json &request) FL_NO_EXCEPT
Process a JSON-RPC request.
Definition rpc.cpp.hpp:134
static json parse(const fl::string &txt) FL_NO_EXCEPT
Definition json.h:849
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: