diff --git a/td/telegram/ClientJson.cpp b/td/telegram/ClientJson.cpp index 94358660c..71d424252 100644 --- a/td/telegram/ClientJson.cpp +++ b/td/telegram/ClientJson.cpp @@ -67,10 +67,10 @@ static std::string from_response(const td_api::Object &object, const string &ext static TD_THREAD_LOCAL std::string *current_output; -static CSlice store_string(std::string str) { +static const char *store_string(std::string str) { init_thread_local(current_output); *current_output = std::move(str); - return *current_output; + return current_output->c_str(); } void ClientJson::send(Slice request) { @@ -83,10 +83,10 @@ void ClientJson::send(Slice request) { client_.send(Client::Request{extra_id, std::move(parsed_request.first)}); } -CSlice ClientJson::receive(double timeout) { +const char *ClientJson::receive(double timeout) { auto response = client_.receive(timeout); if (!response.object) { - return {}; + return nullptr; } std::string extra; @@ -101,7 +101,7 @@ CSlice ClientJson::receive(double timeout) { return store_string(from_response(*response.object, extra)); } -CSlice ClientJson::execute(Slice request) { +const char *ClientJson::execute(Slice request) { auto parsed_request = to_request(request); return store_string(from_response(*Client::execute(Client::Request{0, std::move(parsed_request.first)}).object, parsed_request.second)); diff --git a/td/telegram/ClientJson.h b/td/telegram/ClientJson.h index 3b08cd28b..62df510b7 100644 --- a/td/telegram/ClientJson.h +++ b/td/telegram/ClientJson.h @@ -22,9 +22,9 @@ class ClientJson final { public: void send(Slice request); - CSlice receive(double timeout); + const char *receive(double timeout); - static CSlice execute(Slice request); + static const char *execute(Slice request); private: Client client_; diff --git a/td/telegram/td_json_client.cpp b/td/telegram/td_json_client.cpp index 8637ee2e6..33d29d4b0 100644 --- a/td/telegram/td_json_client.cpp +++ b/td/telegram/td_json_client.cpp @@ -27,19 +27,9 @@ void td_json_client_send(void *client, const char *request) { } const char *td_json_client_receive(void *client, double timeout) { - auto slice = static_cast(client)->receive(timeout); - if (slice.empty()) { - return nullptr; - } else { - return slice.c_str(); - } + return static_cast(client)->receive(timeout); } const char *td_json_client_execute(void *client, const char *request) { - auto slice = td::ClientJson::execute(td::Slice(request == nullptr ? "" : request)); - if (slice.empty()) { - return nullptr; - } else { - return slice.c_str(); - } + return td::ClientJson::execute(td::Slice(request == nullptr ? "" : request)); } diff --git a/td/telegram/td_json_client.h b/td/telegram/td_json_client.h index 2d030ecdb..d713c532c 100644 --- a/td/telegram/td_json_client.h +++ b/td/telegram/td_json_client.h @@ -84,7 +84,7 @@ TDJSON_EXPORT const char *td_json_client_receive(void *client, double timeout); * in the same thread, so it can't be used after that. * \param[in] client The client. Currently ignored for all requests, so NULL can be passed. * \param[in] request JSON-serialized null-terminated request to TDLib. - * \return JSON-serialized null-terminated request response. May be NULL if the request can't be parsed. + * \return JSON-serialized null-terminated request response. */ TDJSON_EXPORT const char *td_json_client_execute(void *client, const char *request);