Move fetch_result to corresponding files.

GitOrigin-RevId: e553631e87f81f466ce8ebc353820acd82dd8510
This commit is contained in:
levlam 2020-03-16 01:42:24 +03:00
parent d06a786a16
commit aac59710b4
3 changed files with 33 additions and 36 deletions

View File

@ -27,6 +27,23 @@
namespace td {
namespace mtproto {
template <class T>
static Result<typename T::ReturnType> 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;

View File

@ -20,40 +20,6 @@
namespace td {
template <class T>
Result<typename T::ReturnType> 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 <class T>
Result<typename T::ReturnType> 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 <class T>
using TLStorer = DefaultStorer<T>;

View File

@ -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 <atomic>
#include <utility>
@ -379,6 +378,21 @@ inline void cancel_query(NetQueryRef &ref) {
ref->cancel(ref.generation());
}
template <class T>
Result<typename T::ReturnType> 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 <class T>
Result<typename T::ReturnType> fetch_result(NetQueryPtr query) {
CHECK(!query.empty());