JSONRPC
繼承: Object
用於處理看起來像 JSONRPC 文件的字典的輔助類。
說明
JSON-RPC 是一項標準,它將方法呼叫包裝在一個 JSON 對象中。該物件有一個特定的結構,並標識出哪個方法被呼叫,該函式的參數,並攜帶一個 ID 來追蹤響應。這個類在 Dictionary 之上實作了該標準;你必須用其他函式在 Dictionary 和 JSON 之間進行轉換。
方法
make_notification(method: String, params: Variant) |
|
make_request(method: String, params: Variant, id: Variant) |
|
make_response(result: Variant, id: Variant) |
|
make_response_error(code: int, message: String, id: Variant = null) const |
|
process_action(action: Variant, recurse: bool = false) |
|
process_string(action: String) |
|
void |
set_method(name: String, callback: Callable) |
列舉
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
請求了方法呼叫,但 JSONRPC 子類別中不存在該名稱的函式。
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) 🔗
返回 JSON-RPC 通知形式的字典。通知是一次性的資訊,不需要有回應。
method:被呼叫的方法的名稱。params:傳遞給該被呼叫的方法的參數的陣列或字典。
Dictionary make_request(method: String, params: Variant, id: Variant) 🔗
以 JSON-RPC 請求的形式返回字典。請求被發送到伺服器並期望得到回應。ID 欄位用於伺服器指定它正在回應的確切請求。
method:被呼叫的方法的名稱。params:傳遞給該被呼叫的方法的參數的陣列或字典。id:唯一標識該請求。伺服器應發送具有相同 ID 的回應。
Dictionary make_response(result: Variant, id: Variant) 🔗
當伺服器接收並處理了請求時,它應該發送回應。如果不想要回應,則需要發送通知。
result:被呼叫的函式的返回值。id:該回應針對的請求的 ID。
Dictionary make_response_error(code: int, message: String, id: Variant = null) const 🔗
建立回應,指示先前的回復以某種方式失敗。
code:這是哪種錯誤對應的錯誤程式碼。請參閱 ErrorCode 常數。message:關於該錯誤的自訂消息。id:該錯誤作為回應對應的請求。
Variant process_action(action: Variant, recurse: bool = false) 🔗
給定採用 JSON-RPC 請求形式的字典:解壓請求並運作它。通過查看名為“method”的字段,並在 JSONRPC 物件中搜尋等效命名的函式來解析方法。如果找到,則呼叫該方法。
要新增新的受支援方法,請擴充 JSONRPC 類並在你的子類別上呼叫 process_action()。
action:要運作的動作,作為 JSON-RPC 請求或通知形式的字典。
String process_string(action: String) 🔗
There is currently no description for this method. Please help us by contributing one!
void set_method(name: String, callback: Callable) 🔗
Registers a callback for the given method name.
nameThe name that clients can use to access the callback.callbackThe callback which will handle the specific method.