Explicitly specify TLObjectStorer's template parameter.

This commit is contained in:
levlam 2023-09-21 21:31:59 +03:00
parent 4c8ab2bf29
commit df563e781e
7 changed files with 10 additions and 19 deletions

View File

@ -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<mtproto_api::gzip_packed>(packed);
const Storer &data_storer =
query_.gzip_flag ? static_cast<const Storer &>(gzip_storer) : static_cast<const Storer &>(plain_storer);
auto header_storer = create_storer(header_);

View File

@ -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 <class T>
string AuthKeyHandshake::store_object(const T &object) {
auto storer = TLObjectStorer<T>(object);
size_t size = storer.size();
string result(size, '\0');
auto real_size = storer.store(MutableSlice(result).ubegin());

View File

@ -95,7 +95,8 @@ class AuthKeyHandshake {
string last_query_;
static string store_object(const mtproto_api::Object &object);
template <class T>
static string store_object(const T &object);
void send(Callback *connection, const Storer &storer);
static void do_send(Callback *connection, const Storer &storer);

View File

@ -842,7 +842,7 @@ std::pair<MessageId, BufferSlice> 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<mtproto_api::bind_auth_key_inner>(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());

View File

@ -15,9 +15,5 @@ TLStorer<mtproto_api::Function> create_function_storer(const mtproto_api::Functi
return TLStorer<mtproto_api::Function>(function);
}
TLObjectStorer<mtproto_api::Object> create_object_storer(const mtproto_api::Object &object) {
return TLObjectStorer<mtproto_api::Object>(object);
}
} // namespace mtproto
} // namespace td

View File

@ -29,7 +29,7 @@ class TLObjectStorer final : public Storer {
size_t size() const final {
if (size_ == std::numeric_limits<size_t>::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<size_t>(storer.get_buf() - ptr);
}
};
namespace mtproto_api {
class Object;
class Function;
} // namespace mtproto_api
@ -52,7 +51,5 @@ namespace mtproto {
TLStorer<mtproto_api::Function> create_function_storer(const mtproto_api::Function &function);
TLObjectStorer<mtproto_api::Object> create_object_storer(const mtproto_api::Object &object);
} // namespace mtproto
} // namespace td

View File

@ -45,10 +45,6 @@
namespace td {
inline TLObjectStorer<secret_api::Object> create_object_storer(const secret_api::Object &object) {
return TLObjectStorer<secret_api::Object>(object);
}
class SecretImpl {
public:
explicit SecretImpl(const Storer &data) : data(data) {
@ -221,7 +217,7 @@ Result<BufferSlice> SecretChatActor::create_encrypted_message(int32 my_in_seq_no
auto message_with_layer = secret_api::make_object<secret_api::decryptedMessageLayer>(
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<secret_api::decryptedMessageLayer>(*message_with_layer);
auto new_storer = mtproto::PacketStorer<SecretImpl>(storer);
mtproto::PacketInfo packet_info;
packet_info.type = mtproto::PacketInfo::EndToEnd;