开发文档

TDLib JSON 接口与多客户端实例

依据固定版本头文件理解 td_send、td_receive、@extra、@client_id 与 int64 编码,避免线程和内存生命周期错误。

GetTGAPI 编辑团队更新于
文档解读核对日期

来源版本 a94b83d67ab4 · TDLib contributors · BSL-1.0

依据官方资料整理,由 GetTGAPI 独立维护。 文档目录与术语表 →

本页内容
  1. JSON 中保留协议类型
  2. 收发线程与返回指针
  3. 关闭与旧接口
  4. 接入检查

JSON 中保留协议类型

对象使用 @type 表示类型;请求可带 @extra,响应会保留同样的值。新接口的返回对象还带 @client_id,多账号时必须据此分发。

int64 在 JSON 中使用字符串,int32、int53 和 double 使用数字;bytes 使用 Base64 字符串。不能把所有 ID 都转换成语言里的默认浮点数。

收发线程与返回指针

td_send 可由不同线程调用,但 td_receive 不能被两个线程同时调用,更新和响应须按接收顺序应用。返回指针只在下一次 td_receive 或 td_execute 调用前有效,因此需要及时解析或复制,不能留给任意异步任务稍后使用。

只有明确标为可以同步调用的方法才能通过 td_execute 执行。日志回调中不能再调用 TDLib 方法,避免重入问题。

关闭与旧接口

新实例在关闭后自动销毁;应用退出前仍需关闭全部实例以保持一致性。旧的 td_json_client_* 接口有不同生命周期,固定版本头文件已经标注未来移除计划,不能将两套释放方式混用。

接入检查

给每个请求生成唯一关联值,超时只结束本地等待,不擅自宣告业务失败。接收循环应持续运行,即使暂时没有自己发出的请求。测试两个实例同时产生更新,以及一个实例关闭时另一个仍正常工作。

原文许可与归属 · BSL-1.0

TDLib contributors · 完整许可文件

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.