Library namespace.
More...
|
namespace | details |
| Contains the implementation details of the JSON RPC library.
|
|
|
static constexpr std::string_view | err_bad_id_type = "ID must be either a number, a string, or null" |
| Error message for when the ID is not a number, a string, or null.
|
|
static constexpr std::string_view | err_bad_params_type = "Parameters must be either an array or an object or omitted" |
| Error message for when the parameters are not an array or an object.
|
|
static constexpr std::string_view | err_empty_batch = "Empty batch request" |
| Error message for when the batch request is empty.
|
|
static constexpr std::string_view | err_empty_method = "Method cannot be empty" |
| Error message for when the method is empty.
|
|
static constexpr std::string_view | err_invalid_params_passed_to_method = "Invalid parameters passed to method" |
| Error message for when the parameters passed to the method are not correct.
|
|
static constexpr std::string_view | err_method_not_found = "Method not found" |
| Error message for when the method is not found.
|
|
static constexpr std::string_view | err_not_jsonrpc_2_0_request = "Not a JSON-RPC 2.0 request" |
| Error message for when the request is not a JSON-RPC 2.0 request.
|
|
◆ from_json()
static void wwa::json_rpc::from_json |
( |
const nlohmann::json & | j, |
|
|
jsonrpc_request & | r ) |
|
static |
Deserializes a JSON object into a jsonrpc_request
structure.
- Parameters
-
j | The JSON object to deserialize. |
r | The jsonrpc_request structure to populate. |
This function deserializes a JSON object into a jsonrpc_request
structure.
- It extracts the
jsonrpc
version, method
name, params
, and id
from the JSON object.
- If the
params
field is not present, it defaults to an empty array.
- If the
params
field is an object, it is wrapped in an array.
- Note
- This function cannot be moved to an anonymous namespace because of Argument-Dependent Lookup (ADL).
- See also
- https://www.jsonrpc.org/specification#request_object
-
https://github.com/nlohmann/json?tab=readme-ov-file#arbitrary-types-conversions
Definition at line 56 of file dispatcher_p.cpp.
57{
58 r.
params = nlohmann::json(nlohmann::json::value_t::discarded);
59 r.
id = nlohmann::json(nlohmann::json::value_t::discarded);
60
61 j.at(
"jsonrpc").get_to(r.
jsonrpc);
62 j.at(
"method").get_to(r.
method);
63
64 if (j.contains("params")) {
65 j.at(
"params").get_to(r.
params);
66 }
67
68 if (j.contains("id")) {
69 j.at(
"id").get_to(r.
id);
70 }
71
72 if (r.
params.is_discarded()) {
73 r.
params = nlohmann::json::array();
74 }
75 else if (r.
params.is_object()) {
77 }
78}
std::string method
The name of the method to be invoked.
std::string jsonrpc
The JSON RPC version.
nlohmann::json id
The ID of the request.
nlohmann::json params
The parameters for the method.