Class JSONRPC
A helper to handle dictionaries which look like JSONRPC documents.
- Inheritance
-
JSONRPC
Remarks
JSON-RPC 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.
Methods
make_notification(String, Variant)
Returns a dictionary in the form of a JSON-RPC notification. Notifications are one-shot messages which do not expect a response.
method
: Name of the method being called.params
: An array or dictionary of parameters being passed to the method.
Dictionary make_notification(String method, Variant params)
Parameters
make_request(String, Variant, Variant)
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.
method
: Name of the method being called.params
: An array or dictionary of parameters being passed to the method.id
: Uniquely identifies this request. The server is expected to send a response with the same ID.
Dictionary make_request(String method, Variant params, Variant id)
Parameters
make_response(Variant, Variant)
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.
result
: The return value of the function which was called.id
: The ID of the request this response is targeted to.
Dictionary make_response(Variant result, Variant id)
Parameters
make_response_error(int, String, Variant)
Qualifiers: const
Creates a response which indicates a previous reply has failed in some way.
code
: The error code corresponding to what kind of error this is. See the ErrorCode constants.message
: A custom message about this error.id
: The request this error is a response to.
Dictionary make_response_error(int code, String message, Variant id)
Parameters
process_action(Variant, bool)
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 JSONRPC.process_action on your subclass.
action
: The action to be run, as a Dictionary in the form of a JSON-RPC request or notification.
Variant process_action(Variant action, bool recurse)
Parameters
process_string(String)
String process_string(String action)
Parameters
action
String
set_scope(String, Object)
void set_scope(String scope, Object target)