JSON RPC
JSON-RPC 2.0 library for C++
|
Private implementation of the JSON RPC dispatcher class. More...
#include <dispatcher_p.h>
Public Member Functions | |
dispatcher_private (dispatcher *q) | |
Constructs a new dispatcher_private object. | |
void | add_handler (std::string &&method, dispatcher::handler_t &&handler) |
Adds a method handler. | |
nlohmann::json | process_request (const nlohmann::json &request, const nlohmann::json &extra) |
Processes a JSON RPC request. | |
Static Public Member Functions | |
static nlohmann::json | generate_error_response (const exception &e, const nlohmann::json &id) |
Generates an error response. | |
Private Member Functions | |
nlohmann::json | invoke (const std::string &method, const nlohmann::json ¶ms, const nlohmann::json &extra) |
Invokes a method handler. | |
nlohmann::json | process_batch_request (const nlohmann::json &request, const nlohmann::json &extra) |
Processes a batch request. | |
Static Private Member Functions | |
static jsonrpc_request | parse_request (const nlohmann::json &request, nlohmann::json &extra) |
Parses a JSON RPC request. | |
static void | validate_request (const jsonrpc_request &r) |
Validates a JSON RPC request. | |
Private Attributes | |
std::unordered_map< std::string, dispatcher::handler_t, hasher, std::equal_to<> > | m_methods |
Map of method names to handler functions. | |
dispatcher * | q_ptr |
Pointer to the public dispatcher object. | |
Private implementation of the JSON RPC dispatcher class.
This class contains the private members and methods used by the dispatcher
class to manage method handlers and process requests.
Definition at line 63 of file dispatcher_p.h.
|
inlineexplicit |
Constructs a new dispatcher_private
object.
q | Pointer to the public dispatcher object. |
Definition at line 70 of file dispatcher_p.h.
void wwa::json_rpc::dispatcher_private::add_handler | ( | std::string && | method, |
dispatcher::handler_t && | handler ) |
Adds a method handler.
method | The name of the method. |
handler | The handler function. |
This method registers a handler function for a given method name. The handler function will be invoked when a request for the specified method is received.
Definition at line 80 of file dispatcher_p.cpp.
|
static |
Generates an error response.
e | The exception containing the error details. |
id | The ID of the request. |
This method creates a JSON RPC error response based on the provided exception and request ID.
Definition at line 198 of file dispatcher_p.cpp.
|
private |
Invokes a method handler.
method | The name of the method to invoke. |
params | The parameters for the method. |
extra | The extra parameter to pass to the method handlers. |
This method finds the handler for the specified method and invokes it with the provided parameters.
exception | If the method is not found or the invocation fails. |
Definition at line 204 of file dispatcher_p.cpp.
|
staticprivate |
Parses a JSON RPC request.
request | The JSON RPC request as a nlohmann::json object. |
extra | Extra fields extracted from request |
This method extracts the components of a JSON RPC request from the provided JSON object.
Definition at line 85 of file dispatcher_p.cpp.
|
private |
Processes a batch request.
request | The batch request as a nlohmann::json array. |
extra | The extra parameter to pass to the method handlers. |
This method processes a batch request by invoking the method handlers for each request in the batch.
Definition at line 102 of file dispatcher_p.cpp.
nlohmann::json wwa::json_rpc::dispatcher_private::process_request | ( | const nlohmann::json & | request, |
const nlohmann::json & | extra ) |
Processes a JSON RPC request.
request | The JSON RPC request as a nlohmann::json object. |
extra | The extra parameter to pass to the method handlers. |
This method parses the JSON RPC request, validates it, and invokes the appropriate method handler.
Definition at line 132 of file dispatcher_p.cpp.
|
staticprivate |
Validates a JSON RPC request.
r | The JSON RPC request to validate. |
This method checks the validity of the JSON RPC request, ensuring that all required fields are present and correctly formatted.
exception | If the request is invalid. |
Definition at line 179 of file dispatcher_p.cpp.
|
private |
Map of method names to handler functions.
Definition at line 111 of file dispatcher_p.h.
|
private |
Pointer to the public dispatcher
object.
Definition at line 109 of file dispatcher_p.h.