From 2cd304097ab2d69ee3acbed064b3d938015e0907 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 12 Oct 2023 01:58:43 +0200 Subject: [PATCH] Fix JSONRPC's class docs. --- modules/jsonrpc/config.py | 8 +++ modules/jsonrpc/doc_classes/JSONRPC.xml | 93 +++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 modules/jsonrpc/doc_classes/JSONRPC.xml diff --git a/modules/jsonrpc/config.py b/modules/jsonrpc/config.py index d22f9454e..b9cdfd31e 100644 --- a/modules/jsonrpc/config.py +++ b/modules/jsonrpc/config.py @@ -4,3 +4,11 @@ def can_build(env, platform): def configure(env): pass + +def get_doc_classes(): + return [ + "JSONRPC", + ] + +def get_doc_path(): + return "doc_classes" diff --git a/modules/jsonrpc/doc_classes/JSONRPC.xml b/modules/jsonrpc/doc_classes/JSONRPC.xml new file mode 100644 index 000000000..bcf92b9d2 --- /dev/null +++ b/modules/jsonrpc/doc_classes/JSONRPC.xml @@ -0,0 +1,93 @@ + + + + A helper to handle dictionaries which look like JSONRPC documents. + + + [url=https://www.jsonrpc.org/]JSON-RPC[/url] is a standard which wraps a method call in a [JSON] object. The object has a particular structure and identifies which method is called, the parameters to that function, and carries an ID to keep track of responses. This class implements that standard on top of [Dictionary]; you will have to convert between a [Dictionary] and [JSON] with other functions. + + + + + + + + + + Returns a dictionary in the form of a JSON-RPC notification. Notifications are one-shot messages which do not expect a response. + - [code]method[/code]: Name of the method being called. + - [code]params[/code]: An array or dictionary of parameters being passed to the method. + + + + + + + + + Returns a dictionary in the form of a JSON-RPC request. Requests are sent to a server with the expectation of a response. The ID field is used for the server to specify which exact request it is responding to. + - [code]method[/code]: Name of the method being called. + - [code]params[/code]: An array or dictionary of parameters being passed to the method. + - [code]id[/code]: Uniquely identifies this request. The server is expected to send a response with the same ID. + + + + + + + + When a server has received and processed a request, it is expected to send a response. If you did not want a response then you need to have sent a Notification instead. + - [code]result[/code]: The return value of the function which was called. + - [code]id[/code]: The ID of the request this response is targeted to. + + + + + + + + + Creates a response which indicates a previous reply has failed in some way. + - [code]code[/code]: The error code corresponding to what kind of error this is. See the [enum ErrorCode] constants. + - [code]message[/code]: A custom message about this error. + - [code]id[/code]: The request this error is a response to. + + + + + + + + Given a Dictionary which takes the form of a JSON-RPC request: unpack the request and run it. Methods are resolved by looking at the field called "method" and looking for an equivalently named function in the JSONRPC object. If one is found that method is called. + To add new supported methods extend the JSONRPC class and call [method process_action] on your subclass. + [code]action[/code]: The action to be run, as a Dictionary in the form of a JSON-RPC request or notification. + + + + + + + + + + + + + + + + + + + + + + + A method call was requested but no function of that name existed in the JSONRPC subclass. + + + + + + +