JSON RPC
JSON-RPC 2.0 library for C++
|
Library namespace. More...
Namespaces | |
namespace | details |
Contains the implementation details of the JSON RPC library. | |
Classes | |
class | dispatcher |
A class that manages JSON RPC method handlers and processes JSON RPC requests. More... | |
class | dispatcher_private |
Private implementation of the JSON RPC dispatcher class. More... | |
class | exception |
JSON RPC Exception class. More... | |
struct | jsonrpc_request |
Represents a JSON RPC request. More... | |
class | method_not_found_exception |
Exception thrown when the method is not found. More... | |
Functions | |
static void | from_json (const nlohmann::json &j, jsonrpc_request &r) |
Deserializes a JSON object into a jsonrpc_request structure. | |
WWA_JSONRPC_EXPORT nlohmann::json | generate_error_response (const exception &e, const nlohmann::json &id=nlohmann::json::value_t::null) |
Generates an error response. | |
WWA_JSONRPC_EXPORT int | get_error_code (const nlohmann::json &response) |
Gets the error code from an error response. | |
WWA_JSONRPC_EXPORT std::string | get_error_message (const nlohmann::json &response) |
Gets the error message from an error response. | |
WWA_JSONRPC_EXPORT nlohmann::json | get_request_id (const nlohmann::json &request) |
Get the request id object. | |
WWA_JSONRPC_EXPORT bool | is_error_response (const nlohmann::json &response) |
Checks whether response is an error response. | |
WWA_JSONRPC_EXPORT bool | is_valid_request_id (const nlohmann::json &id) |
Checks if the provided JSON value is a valid JSON RPC request ID. | |
WWA_JSONRPC_EXPORT std::string | serialize_repsonse (const nlohmann::json &response) |
Serializes the JSON RPC response to a string. | |
Variables | |
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_bad_request = "Bad request" |
Error request for when the request is not valid. | |
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. | |
Library namespace.
|
static |
Deserializes a JSON object into a jsonrpc_request
structure.
j | The JSON object to deserialize. |
r | The jsonrpc_request structure to populate. |
This function deserializes a JSON object into a jsonrpc_request
structure.
jsonrpc
version, method
name, params
, and id
from the JSON object.params
field is not present, it defaults to an empty array.params
field is an object, it is wrapped in an array.Definition at line 38 of file request.cpp.
nlohmann::json wwa::json_rpc::generate_error_response | ( | const exception & | e, |
const nlohmann::json & | id = nlohmann::json::value_t::null ) |
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 43 of file utils.cpp.
int wwa::json_rpc::get_error_code | ( | const nlohmann::json & | response | ) |
std::string wwa::json_rpc::get_error_message | ( | const nlohmann::json & | response | ) |
nlohmann::json wwa::json_rpc::get_request_id | ( | const nlohmann::json & | request | ) |
Get the request id object.
request | JSON RPC request |
This function extracts the ID field from a JSON RPC request object. If the id
field is not present or is not valid (see is_valid_request_id()), it returns a null
JSON value.
Definition at line 17 of file utils.cpp.
bool wwa::json_rpc::is_error_response | ( | const nlohmann::json & | response | ) |
bool wwa::json_rpc::is_valid_request_id | ( | const nlohmann::json & | id | ) |
Checks if the provided JSON value is a valid JSON RPC request ID.
id | The JSON value to check. |
true
if the JSON value is a valid request ID, false
otherwise.This function checks if the provided JSON value is a valid JSON RPC request ID. According to the JSON RPC specification, a valid request ID can be a string, a number, or null. Additionally, this function also considers a discarded JSON value as valid.
Definition at line 12 of file utils.cpp.
std::string wwa::json_rpc::serialize_repsonse | ( | const nlohmann::json & | response | ) |