diff --git a/td/mtproto/Handshake.cpp b/td/mtproto/Handshake.cpp index feda2e10..eb56e1b7 100644 --- a/td/mtproto/Handshake.cpp +++ b/td/mtproto/Handshake.cpp @@ -27,6 +27,23 @@ namespace td { namespace mtproto { +template +static Result fetch_result(Slice message, bool check_end = true) { + TlParser parser(message); + auto result = T::fetch_result(parser); + + if (check_end) { + parser.fetch_end(); + } + const char *error = parser.get_error(); + if (error != nullptr) { + LOG(ERROR) << "Can't parse: " << format::as_hex_dump<4>(message); + return Status::Error(500, Slice(error)); + } + + return std::move(result); +} + void AuthKeyHandshake::clear() { last_query_ = BufferSlice(); state_ = Start; diff --git a/td/mtproto/utils.h b/td/mtproto/utils.h index 8fb4eba5..2e80e156 100644 --- a/td/mtproto/utils.h +++ b/td/mtproto/utils.h @@ -20,40 +20,6 @@ namespace td { -template -Result fetch_result(Slice message, bool check_end = true) { - TlParser parser(message); - auto result = T::fetch_result(parser); - - if (check_end) { - parser.fetch_end(); - } - const char *error = parser.get_error(); - if (error != nullptr) { - LOG(ERROR) << "Can't parse: " << format::as_hex_dump<4>(message); - return Status::Error(500, Slice(error)); - } - - return std::move(result); -} - -template -Result fetch_result(const BufferSlice &message, bool check_end = true) { - TlBufferParser parser(&message); - auto result = T::fetch_result(parser); - - if (check_end) { - parser.fetch_end(); - } - const char *error = parser.get_error(); - if (error != nullptr) { - LOG(ERROR) << "Can't parse: " << format::as_hex_dump<4>(message.as_slice()); - return Status::Error(500, Slice(error)); - } - - return std::move(result); -} - template using TLStorer = DefaultStorer; diff --git a/td/telegram/net/NetQuery.h b/td/telegram/net/NetQuery.h index ea160a37..4fd61b01 100644 --- a/td/telegram/net/NetQuery.h +++ b/td/telegram/net/NetQuery.h @@ -13,8 +13,6 @@ #include "td/actor/PromiseFuture.h" #include "td/actor/SignalSlot.h" -#include "td/mtproto/utils.h" // for fetch_result TODO - #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/format.h" @@ -24,6 +22,7 @@ #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" #include "td/utils/Time.h" +#include "td/utils/tl_parsers.h" #include #include @@ -379,6 +378,21 @@ inline void cancel_query(NetQueryRef &ref) { ref->cancel(ref.generation()); } +template +Result fetch_result(const BufferSlice &message) { + TlBufferParser parser(&message); + auto result = T::fetch_result(parser); + parser.fetch_end(); + + const char *error = parser.get_error(); + if (error != nullptr) { + LOG(ERROR) << "Can't parse: " << format::as_hex_dump<4>(message.as_slice()); + return Status::Error(500, Slice(error)); + } + + return std::move(result); +} + template Result fetch_result(NetQueryPtr query) { CHECK(!query.empty());