From df563e781eaeb11b130ae25cb1632371988a0f87 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 21 Sep 2023 21:31:59 +0300 Subject: [PATCH] Explicitly specify TLObjectStorer's template parameter. --- td/mtproto/CryptoStorer.h | 2 +- td/mtproto/Handshake.cpp | 5 +++-- td/mtproto/Handshake.h | 3 ++- td/mtproto/SessionConnection.cpp | 2 +- td/mtproto/utils.cpp | 4 ---- td/mtproto/utils.h | 7 ++----- td/telegram/SecretChatActor.cpp | 6 +----- 7 files changed, 10 insertions(+), 19 deletions(-) diff --git a/td/mtproto/CryptoStorer.h b/td/mtproto/CryptoStorer.h index bbe376770..ab15e2791 100644 --- a/td/mtproto/CryptoStorer.h +++ b/td/mtproto/CryptoStorer.h @@ -149,7 +149,7 @@ class QueryImpl { Slice data = query_.packet.as_slice(); mtproto_api::gzip_packed packed(data); auto plain_storer = create_storer(data); - auto gzip_storer = create_object_storer(packed); + auto gzip_storer = TLObjectStorer(packed); const Storer &data_storer = query_.gzip_flag ? static_cast(gzip_storer) : static_cast(plain_storer); auto header_storer = create_storer(header_); diff --git a/td/mtproto/Handshake.cpp b/td/mtproto/Handshake.cpp index fe22d1a1c..f990ee3f2 100644 --- a/td/mtproto/Handshake.cpp +++ b/td/mtproto/Handshake.cpp @@ -73,8 +73,9 @@ void AuthKeyHandshake::on_finish() { clear(); } -string AuthKeyHandshake::store_object(const mtproto_api::Object &object) { - auto storer = create_object_storer(object); +template +string AuthKeyHandshake::store_object(const T &object) { + auto storer = TLObjectStorer(object); size_t size = storer.size(); string result(size, '\0'); auto real_size = storer.store(MutableSlice(result).ubegin()); diff --git a/td/mtproto/Handshake.h b/td/mtproto/Handshake.h index e0a79ecfd..3eb9ff8a4 100644 --- a/td/mtproto/Handshake.h +++ b/td/mtproto/Handshake.h @@ -95,7 +95,8 @@ class AuthKeyHandshake { string last_query_; - static string store_object(const mtproto_api::Object &object); + template + static string store_object(const T &object); void send(Callback *connection, const Storer &storer); static void do_send(Callback *connection, const Storer &storer); diff --git a/td/mtproto/SessionConnection.cpp b/td/mtproto/SessionConnection.cpp index 92b9e1b7d..f3cef1904 100644 --- a/td/mtproto/SessionConnection.cpp +++ b/td/mtproto/SessionConnection.cpp @@ -842,7 +842,7 @@ std::pair SessionConnection::encrypted_bind(int64 perm_k int64 temp_key = auth_data_->get_tmp_auth_key().id(); mtproto_api::bind_auth_key_inner object(nonce, temp_key, perm_key, auth_data_->get_session_id(), expires_at); - auto object_storer = create_object_storer(object); + auto object_storer = TLObjectStorer(object); auto size = object_storer.size(); auto object_packet = BufferWriter{size, 0, 0}; auto real_size = object_storer.store(object_packet.as_mutable_slice().ubegin()); diff --git a/td/mtproto/utils.cpp b/td/mtproto/utils.cpp index 1d4eee125..b509332ab 100644 --- a/td/mtproto/utils.cpp +++ b/td/mtproto/utils.cpp @@ -15,9 +15,5 @@ TLStorer create_function_storer(const mtproto_api::Functi return TLStorer(function); } -TLObjectStorer create_object_storer(const mtproto_api::Object &object) { - return TLObjectStorer(object); -} - } // namespace mtproto } // namespace td diff --git a/td/mtproto/utils.h b/td/mtproto/utils.h index 353fb5dee..bf9c8dd7e 100644 --- a/td/mtproto/utils.h +++ b/td/mtproto/utils.h @@ -29,7 +29,7 @@ class TLObjectStorer final : public Storer { size_t size() const final { if (size_ == std::numeric_limits::max()) { TlStorerCalcLength storer; - storer.store_binary(object_.get_id()); + storer.store_binary(T::ID); object_.store(storer); size_ = storer.get_length(); } @@ -37,14 +37,13 @@ class TLObjectStorer final : public Storer { } size_t store(uint8 *ptr) const final { TlStorerUnsafe storer(ptr); - storer.store_binary(object_.get_id()); + storer.store_binary(T::ID); object_.store(storer); return static_cast(storer.get_buf() - ptr); } }; namespace mtproto_api { -class Object; class Function; } // namespace mtproto_api @@ -52,7 +51,5 @@ namespace mtproto { TLStorer create_function_storer(const mtproto_api::Function &function); -TLObjectStorer create_object_storer(const mtproto_api::Object &object); - } // namespace mtproto } // namespace td diff --git a/td/telegram/SecretChatActor.cpp b/td/telegram/SecretChatActor.cpp index 0da13dc39..7e28a99ef 100644 --- a/td/telegram/SecretChatActor.cpp +++ b/td/telegram/SecretChatActor.cpp @@ -45,10 +45,6 @@ namespace td { -inline TLObjectStorer create_object_storer(const secret_api::Object &object) { - return TLObjectStorer(object); -} - class SecretImpl { public: explicit SecretImpl(const Storer &data) : data(data) { @@ -221,7 +217,7 @@ Result SecretChatActor::create_encrypted_message(int32 my_in_seq_no auto message_with_layer = secret_api::make_object( std::move(random_bytes), layer, in_seq_no, out_seq_no, std::move(message)); LOG(INFO) << "Create message " << to_string(message_with_layer); - auto storer = create_object_storer(*message_with_layer); + auto storer = TLObjectStorer(*message_with_layer); auto new_storer = mtproto::PacketStorer(storer); mtproto::PacketInfo packet_info; packet_info.type = mtproto::PacketInfo::EndToEnd;