mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2025-12-31 09:49:22 +03:00
226 lines
11 KiB
ReStructuredText
226 lines
11 KiB
ReStructuredText
:github_url: hide
|
||
|
||
.. _class_JSONRPC:
|
||
|
||
JSONRPC
|
||
=======
|
||
|
||
**继承:** :ref:`Object<class_Object>`
|
||
|
||
用于处理看起来像 JSONRPC 文档的字典的辅助类。
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
描述
|
||
----
|
||
|
||
`JSON-RPC <https://www.jsonrpc.org/>`__ 是一项标准,它将方法调用包装在一个 :ref:`JSON<class_JSON>` 对象中。该对象有一个特定的结构,并标识出哪个方法被调用,该函数的参数,并携带一个 ID 来跟踪响应。这个类在 :ref:`Dictionary<class_Dictionary>` 之上实现了该标准;你必须用其他函数在 :ref:`Dictionary<class_Dictionary>` 和 :ref:`JSON<class_JSON>` 之间进行转换。
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
方法
|
||
----
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Dictionary<class_Dictionary>` | :ref:`make_notification<class_JSONRPC_method_make_notification>`\ (\ method\: :ref:`String<class_String>`, params\: :ref:`Variant<class_Variant>`\ ) |
|
||
+-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Dictionary<class_Dictionary>` | :ref:`make_request<class_JSONRPC_method_make_request>`\ (\ method\: :ref:`String<class_String>`, params\: :ref:`Variant<class_Variant>`, id\: :ref:`Variant<class_Variant>`\ ) |
|
||
+-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Dictionary<class_Dictionary>` | :ref:`make_response<class_JSONRPC_method_make_response>`\ (\ result\: :ref:`Variant<class_Variant>`, id\: :ref:`Variant<class_Variant>`\ ) |
|
||
+-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Dictionary<class_Dictionary>` | :ref:`make_response_error<class_JSONRPC_method_make_response_error>`\ (\ code\: :ref:`int<class_int>`, message\: :ref:`String<class_String>`, id\: :ref:`Variant<class_Variant>` = null\ ) |const| |
|
||
+-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`process_action<class_JSONRPC_method_process_action>`\ (\ action\: :ref:`Variant<class_Variant>`, recurse\: :ref:`bool<class_bool>` = false\ ) |
|
||
+-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`process_string<class_JSONRPC_method_process_string>`\ (\ action\: :ref:`String<class_String>`\ ) |
|
||
+-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_method<class_JSONRPC_method_set_method>`\ (\ name\: :ref:`String<class_String>`, callback\: :ref:`Callable<class_Callable>`\ ) |
|
||
+-------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
枚举
|
||
----
|
||
|
||
.. _enum_JSONRPC_ErrorCode:
|
||
|
||
.. rst-class:: classref-enumeration
|
||
|
||
enum **ErrorCode**: :ref:`🔗<enum_JSONRPC_ErrorCode>`
|
||
|
||
.. _class_JSONRPC_constant_PARSE_ERROR:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`ErrorCode<enum_JSONRPC_ErrorCode>` **PARSE_ERROR** = ``-32700``
|
||
|
||
无法解析请求,因为不符合 JSON 标准(\ :ref:`JSON.parse()<class_JSON_method_parse>` 失败)。
|
||
|
||
.. _class_JSONRPC_constant_INVALID_REQUEST:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`ErrorCode<enum_JSONRPC_ErrorCode>` **INVALID_REQUEST** = ``-32600``
|
||
|
||
请求进行方法调用,但是请求格式无效。
|
||
|
||
.. _class_JSONRPC_constant_METHOD_NOT_FOUND:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`ErrorCode<enum_JSONRPC_ErrorCode>` **METHOD_NOT_FOUND** = ``-32601``
|
||
|
||
请求进行方法调用,但是 JSONRPC 子类中不存在该名称的函数。
|
||
|
||
.. _class_JSONRPC_constant_INVALID_PARAMS:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`ErrorCode<enum_JSONRPC_ErrorCode>` **INVALID_PARAMS** = ``-32602``
|
||
|
||
请求进行方法调用,但是给定的方法参数无效。内置 JSONRPC 未使用。
|
||
|
||
.. _class_JSONRPC_constant_INTERNAL_ERROR:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`ErrorCode<enum_JSONRPC_ErrorCode>` **INTERNAL_ERROR** = ``-32603``
|
||
|
||
处理请求时发生内部错误。内置 JSONRPC 未使用。
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
方法说明
|
||
--------
|
||
|
||
.. _class_JSONRPC_method_make_notification:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Dictionary<class_Dictionary>` **make_notification**\ (\ method\: :ref:`String<class_String>`, params\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_JSONRPC_method_make_notification>`
|
||
|
||
返回 JSON-RPC 通知形式的字典。通知是一次性的信息,不需要有响应。
|
||
|
||
- ``method``\ :被调用的方法的名称。
|
||
|
||
- ``params``\ :传递给该被调用的方法的参数的数组或字典。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_JSONRPC_method_make_request:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Dictionary<class_Dictionary>` **make_request**\ (\ method\: :ref:`String<class_String>`, params\: :ref:`Variant<class_Variant>`, id\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_JSONRPC_method_make_request>`
|
||
|
||
以 JSON-RPC 请求的形式返回字典。请求被发送到服务器并期望得到响应。ID 字段用于服务器指定它正在响应的确切请求。
|
||
|
||
- ``method``\ :被调用的方法的名称。
|
||
|
||
- ``params``\ :传递给该被调用的方法的参数的数组或字典。
|
||
|
||
- ``id``\ :唯一标识该请求。服务器应发送具有相同 ID 的响应。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_JSONRPC_method_make_response:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Dictionary<class_Dictionary>` **make_response**\ (\ result\: :ref:`Variant<class_Variant>`, id\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_JSONRPC_method_make_response>`
|
||
|
||
当服务器接收并处理了请求时,它应该发送响应。如果不想要响应,则需要发送通知。
|
||
|
||
- ``result``\ :被调用的函数的返回值。
|
||
|
||
- ``id``\ :该响应针对的请求的 ID。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_JSONRPC_method_make_response_error:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Dictionary<class_Dictionary>` **make_response_error**\ (\ code\: :ref:`int<class_int>`, message\: :ref:`String<class_String>`, id\: :ref:`Variant<class_Variant>` = null\ ) |const| :ref:`🔗<class_JSONRPC_method_make_response_error>`
|
||
|
||
创建响应,指示先前的回复以某种方式失败。
|
||
|
||
- ``code``\ :这是哪种错误对应的错误代码。请参阅 :ref:`ErrorCode<enum_JSONRPC_ErrorCode>` 常量。
|
||
|
||
- ``message``\ :关于该错误的自定义消息。
|
||
|
||
- ``id``\ :该错误作为响应对应的请求。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_JSONRPC_method_process_action:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **process_action**\ (\ action\: :ref:`Variant<class_Variant>`, recurse\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_JSONRPC_method_process_action>`
|
||
|
||
给定采用 JSON-RPC 请求形式的字典:解压请求并运行它。通过查看名为“method”的字段,并在 JSONRPC 对象中查找等效命名的函数来解析方法。如果找到,则调用该方法。
|
||
|
||
要添加新的受支持方法,请扩展 JSONRPC 类并在你的子类上调用 :ref:`process_action()<class_JSONRPC_method_process_action>`\ 。
|
||
|
||
\ ``action``\ :要运行的动作,作为 JSON-RPC 请求或通知形式的字典。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_JSONRPC_method_process_string:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **process_string**\ (\ action\: :ref:`String<class_String>`\ ) :ref:`🔗<class_JSONRPC_method_process_string>`
|
||
|
||
.. container:: contribute
|
||
|
||
There is currently no description for this method. Please help us by `contributing one <https://contributing.godotengine.org/en/latest/documentation/class_reference.html>`__!
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_JSONRPC_method_set_method:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_method**\ (\ name\: :ref:`String<class_String>`, callback\: :ref:`Callable<class_Callable>`\ ) :ref:`🔗<class_JSONRPC_method_set_method>`
|
||
|
||
Registers a callback for the given method name.
|
||
|
||
- ``name``: The name that clients can use to access the callback.
|
||
|
||
- ``callback``: The callback which will handle the specified method.
|
||
|
||
.. |virtual| replace:: :abbr:`virtual (本方法通常需要用户覆盖才能生效。)`
|
||
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
|
||
.. |const| replace:: :abbr:`const (本方法无副作用,不会修改该实例的任何成员变量。)`
|
||
.. |vararg| replace:: :abbr:`vararg (本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。)`
|
||
.. |constructor| replace:: :abbr:`constructor (本方法用于构造某个类型。)`
|
||
.. |static| replace:: :abbr:`static (调用本方法无需实例,可直接使用类名进行调用。)`
|
||
.. |operator| replace:: :abbr:`operator (本方法描述的是使用本类型作为左操作数的有效运算符。)`
|
||
.. |bitfield| replace:: :abbr:`BitField (这个值是由下列位标志构成位掩码的整数。)`
|
||
.. |void| replace:: :abbr:`void (无返回值。)`
|