Class JsonRpc
- Namespace
- Godot
- Assembly
- GodotSharp.dll
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.
[GodotClassName("JSONRPC")]
public class JsonRpc : GodotObject, IDisposable
- Inheritance
-
JsonRpc
- Implements
- Inherited Members
Constructors
JsonRpc()
public JsonRpc()
Methods
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
MakeNotification(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.
public Dictionary MakeNotification(string method, Variant @params)
Parameters
Returns
MakeRequest(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.
public Dictionary MakeRequest(string method, Variant @params, Variant id)
Parameters
Returns
MakeResponse(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.
public Dictionary MakeResponse(Variant result, Variant id)
Parameters
Returns
MakeResponseError(int, string, Variant)
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 JsonRpc.ErrorCode constants.
- message
: A custom message about this error.
- id
: The request this error is a response to.
public Dictionary MakeResponseError(int code, string message, Variant id = default)
Parameters
Returns
ProcessAction(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 ProcessAction(Variant, bool) on your subclass.
action
: The action to be run, as a Dictionary in the form of a JSON-RPC request or notification.
public Variant ProcessAction(Variant action, bool recurse = false)
Parameters
Returns
ProcessString(string)
public string ProcessString(string action)
Parameters
action
string
Returns
SetScope(string, GodotObject)
public void SetScope(string scope, GodotObject target)
Parameters
scope
stringtarget
GodotObject