JSONRPC
继承: Object
A helper to handle dictionaries which look like JSONRPC documents.
描述
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.
方法
Dictionary | make_notification ( method: String , params: Variant ) |
Dictionary | make_request ( method: String , params: Variant , id: Variant ) |
Dictionary | make_response ( result: Variant , id: Variant ) |
Dictionary | make_response_error ( code: int , message: String , id: Variant = null ) const1 |
Variant | process_action ( action: Variant , recurse: bool = false ) |
String | process_string ( action: String ) |
void | set_scope ( scope: String , target: Object ) |
枚举
enum ErrorCode:
ErrorCode PARSE_ERROR = -32700
The request could not be parsed as it was not valid by JSON standard (JSON.parse
failed).
ErrorCode INVALID_REQUEST = -32600
A method call was requested but the request's format is not valid.
ErrorCode METHOD_NOT_FOUND = -32601
A method call was requested but no function of that name existed in the JSONRPC subclass.
ErrorCode INVALID_PARAMS = -32602
A method call was requested but the given method parameters are not valid. Not used by the built-in JSONRPC.
ErrorCode INTERNAL_ERROR = -32603
An internal error occurred while processing the request. Not used by the built-in JSONRPC.
方法说明
Dictionary
make_notification ( method: String
, params: 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_request ( method: String
, params: Variant
, id: 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_response ( result: Variant
, id: 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_error ( code: int
, message: String
, id: Variant
= null ) const1
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.
Variant
process_action ( action: Variant
, recurse: bool
= false )
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 process_action
on your subclass.
action
: The action to be run, as a Dictionary in the form of a JSON-RPC request or notification.
String
process_string ( action: String
)
该方法目前没有描述,请帮我们\ :ref:贡献一个 <doc_updating_the_class_reference>
\ 吧!
void
set_scope ( scope: String
, target: Object
)
该方法目前没有描述,请帮我们\ :ref:贡献一个 <doc_updating_the_class_reference>
\ 吧!
本方法通常需要用户覆盖才能生效。
本方法无副作用,不会修改该实例的任何成员变量。
本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。
本方法用于构造某个类型。
调用本方法无需实例,可直接使用类名进行调用。
本方法描述的是使用本类型作为左操作数的有效运算符。
这个值是由下列位标志构成位掩码的整数。
无返回值。