An implementation of the JSON-RPC 2.0 specification. More...
Variables | |
| constexpr std::int64_t | sourcemeta::core::JSONRPC_CODE_PARSE = -32700 |
| constexpr std::int64_t | sourcemeta::core::JSONRPC_CODE_INVALID_REQUEST = -32600 |
| constexpr std::int64_t | sourcemeta::core::JSONRPC_CODE_METHOD_NOT_FOUND = -32601 |
| constexpr std::int64_t | sourcemeta::core::JSONRPC_CODE_INVALID_PARAMS = -32602 |
| constexpr std::int64_t | sourcemeta::core::JSONRPC_CODE_INTERNAL = -32603 |
| constexpr std::int64_t | sourcemeta::core::JSONRPC_CODE_SERVER_ERROR_MIN = -32099 |
| constexpr std::int64_t | sourcemeta::core::JSONRPC_CODE_SERVER_ERROR_MAX = -32000 |
An implementation of the JSON-RPC 2.0 specification.
This functionality is included as follows:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_is_batch | ( | const sourcemeta::core::JSON & | payload | ) | -> bool |
Check whether the given JSON value is a JSON-RPC 2.0 batch envelope. This only verifies that the value is an array, so the caller remains responsible for the empty-batch single-error response and for omitting a response when a batch consists entirely of notifications. For example:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_is_notification | ( | const sourcemeta::core::JSON & | request | ) | -> bool |
Check whether the given JSON value is a well-formed JSON-RPC 2.0 notification (a request without an identifier). For example:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_is_request | ( | const sourcemeta::core::JSON & | request | ) | -> bool |
Check whether the given JSON value is a well-formed JSON-RPC 2.0 request. For example:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_is_server_error | ( | const std::int64_t | code | ) | -> bool |
Check whether the given code lies within the JSON-RPC 2.0 reserved range for implementation-defined server errors. For example:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_is_valid_batch | ( | const sourcemeta::core::JSON & | payload | ) | -> bool |
Check whether the given JSON value is a non-empty JSON-RPC 2.0 batch envelope. For example:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_make_error | ( | const sourcemeta::core::JSON * | identifier, |
| const std::int64_t | code, | ||
| const JSON::StringView | message, | ||
| std::optional< sourcemeta::core::JSON > | data = std::nullopt ) -> sourcemeta::core::JSON |
Construct a JSON-RPC 2.0 error response envelope. Passing nullptr for the identifier writes an "id": null member, as the specification requires when the originating request could not be parsed. The optional data carries implementation-specific extra information. For example:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_make_error_internal | ( | const sourcemeta::core::JSON * | identifier = nullptr | ) | -> sourcemeta::core::JSON |
Construct a JSON-RPC 2.0 internal-error envelope, optionally carrying the offending request identifier. For example:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_make_error_invalid_params | ( | const sourcemeta::core::JSON & | identifier, |
| std::optional< sourcemeta::core::JSON > | data = std::nullopt ) -> sourcemeta::core::JSON |
Construct a JSON-RPC 2.0 invalid-params error envelope for the given request identifier, optionally carrying implementation-specific data. For example:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_make_error_invalid_request | ( | const sourcemeta::core::JSON * | identifier = nullptr | ) | -> sourcemeta::core::JSON |
Construct a JSON-RPC 2.0 invalid-request error envelope, optionally carrying the offending request identifier. For example:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_make_error_method_not_found | ( | const sourcemeta::core::JSON & | identifier | ) | -> sourcemeta::core::JSON |
Construct a JSON-RPC 2.0 method-not-found error envelope for the given request identifier. For example:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_make_error_parse | ( | ) | -> const sourcemeta::core::JSON & |
Get the canonical JSON-RPC 2.0 parse-error envelope. The returned reference is to a static instance that lives for the duration of the program. For example:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_make_success | ( | const sourcemeta::core::JSON & | identifier, |
| sourcemeta::core::JSON | result ) -> sourcemeta::core::JSON |
Construct a successful JSON-RPC 2.0 response envelope with the given identifier and result. For example:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_make_success_empty | ( | const sourcemeta::core::JSON & | identifier | ) | -> sourcemeta::core::JSON |
Construct a successful JSON-RPC 2.0 response envelope with the given identifier and an empty object result. For example:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_method | ( | const sourcemeta::core::JSON & | request | ) | -> JSON::StringView |
Extract the method name from a JSON-RPC 2.0 envelope, or an empty view when the method field is missing or not a string. For example:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_params | ( | const sourcemeta::core::JSON & | request | ) | -> const sourcemeta::core::JSON * |
Extract the params from a JSON-RPC 2.0 envelope, or nullptr when the value is missing or not an object or array. For example:
| SOURCEMETA_CORE_JSONRPC_EXPORT auto sourcemeta::core::jsonrpc_request_id | ( | const sourcemeta::core::JSON & | request | ) | -> const sourcemeta::core::JSON * |
Extract the request identifier from a JSON-RPC 2.0 envelope. Returns a pointer to the identifier (string, number, or null per the specification) or nullptr when the field is missing or not one of those types. For example:
|
constexpr |
The pre-defined JSON-RPC 2.0 error code for internal server errors.
|
constexpr |
The pre-defined JSON-RPC 2.0 error code for invalid method parameters.
|
constexpr |
The pre-defined JSON-RPC 2.0 error code for a malformed request envelope.
|
constexpr |
The pre-defined JSON-RPC 2.0 error code for unknown methods.
|
constexpr |
The pre-defined JSON-RPC 2.0 error code for invalid JSON received by the server.
|
constexpr |
The upper bound of the JSON-RPC 2.0 reserved range for implementation-defined server errors.
|
constexpr |
The lower bound of the JSON-RPC 2.0 reserved range for implementation-defined server errors.