Technical Sub-Spec: TDLib Client Architecture & RAII
Module Specification
[TECH-001]: C++23 TDLib Client Wrapper (
grm::TdClient)[TECH-002]: C++23 RAII JSON Wrapper (
grm::JsonValue)[TECH-003]: Application Controller (
grm::App)
[TECH-001] TDLib Client Wrapper (grm::TdClient)
Fulfills Requirements:
[FUNC-001],[FUNC-002]Header:
include/grm/td_client.hppImplementation:
src/td_client.cpp
The TdClient class wraps TDLib’s C JSON API (td_create_client_id, td_send, td_receive):
Lifecycle: Manages background worker thread
receiver_thread_executingreceiver_loop().Request Routing: Generates atomic request identifiers (
req_1,req_2, …) attached to the@extrafield of sent JSON objects. Incoming responses matching@extraset correspondingstd::promise<JsonValue>objects.Synchronous Wait:
send_request(type, payload, timeout)waits on the resultingstd::future<JsonValue>and returnsstd::expected<JsonValue, std::string>.
[TECH-002] RAII JSON Wrapper (grm::JsonValue)
Fulfills Requirements:
[FUNC-003]Header:
include/grm/json_utils.hppImplementation:
src/json_utils.cpp
Wraps C library json-c pointers with modern C++ memory management:
RAII Ownership: Calls
json_object_geton copy/increment andjson_object_puton destruction, preventing memory leaks.Type-Safe Getters: Provides
get_string(),get_int(),get_bool(),get_object(), andget_array()returningstd::optional.
[TECH-003] Application Controller (grm::App)
Fulfills Requirements:
[FUNC-005]Header:
include/grm/app.hppImplementation:
src/app.cpp
Executes CLI subcommand routing:
cmd_login(): Drives interactive phone and password authentication state transitions.cmd_chat_ls(): Fetches chat IDs viagetChatsand inspects details viagetChat.cmd_msg_ls(): Retrieves history viagetChatHistory.cmd_send(): Dispatches formatted text viasendMessage.