From d5ac68c067eaa2b5a8203efba4cdbf3e39850296 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 9 May 2024 22:16:52 +0300 Subject: [PATCH] Add NetQuery::add_verification_prefix. --- td/telegram/net/NetQuery.cpp | 11 +++++++++++ td/telegram/net/NetQuery.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/td/telegram/net/NetQuery.cpp b/td/telegram/net/NetQuery.cpp index 71e8814a9..c35ac6de9 100644 --- a/td/telegram/net/NetQuery.cpp +++ b/td/telegram/net/NetQuery.cpp @@ -171,4 +171,15 @@ StringBuilder &operator<<(StringBuilder &stream, const NetQueryPtr &net_query_pt return stream << *net_query_ptr; } +void NetQuery::add_verification_prefix(const string &prefix) { + CHECK(is_ready()); + CHECK(is_error()); + CHECK(!query_.empty()); + BufferSlice query(prefix.size() + query_.size() - verification_prefix_length_); + query.as_mutable_slice().copy_from(prefix); + query.as_mutable_slice().substr(prefix.size()).copy_from(query_.as_slice().substr(verification_prefix_length_)); + verification_prefix_length_ = narrow_cast(prefix.size()); + query_ = std::move(query); +} + } // namespace td diff --git a/td/telegram/net/NetQuery.h b/td/telegram/net/NetQuery.h index 4ea22ff80..8ab74acac 100644 --- a/td/telegram/net/NetQuery.h +++ b/td/telegram/net/NetQuery.h @@ -238,6 +238,8 @@ class NetQuery final : public TsListNode { return in_sequence_dispacher_; } + void add_verification_prefix(const string &prefix); + private: State state_ = State::Empty; Type type_ = Type::Common; @@ -251,6 +253,7 @@ class NetQuery final : public TsListNode { BufferSlice query_; BufferSlice answer_; int32 tl_constructor_ = 0; + int32 verification_prefix_length_ = 0; vector invoke_after_; vector chain_ids_;