This repository has been archived on 2020-05-25. You can view files and clone it, but cannot push or open issues or pull requests.
tdlib-fork/td/telegram/net/NetQueryCreator.cpp
levlam ea8d5dbda7 Add debug for INPUT_METHOD_INVALID and BOT_METHOD_INVALID.
GitOrigin-RevId: dfc4e6c81f80504d2299a59f21cd79633fd98daf
2018-06-08 21:42:04 +03:00

42 lines
1.4 KiB
C++

//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/telegram/net/NetQueryCreator.h"
#include "td/utils/Gzip.h"
namespace td {
NetQueryCreator::Ptr NetQueryCreator::create(uint64 id, const Storer &storer, DcId dc_id, NetQuery::Type type,
NetQuery::AuthFlag auth_flag, NetQuery::GzipFlag gzip_flag,
double total_timeout_limit) {
BufferSlice slice(storer.size());
storer.store(slice.as_slice().ubegin());
// TODO: magic constant
if (slice.size() < (1 << 8)) {
gzip_flag = NetQuery::GzipFlag::Off;
}
int32 tl_constructor = NetQuery::tl_magic(slice);
if (gzip_flag == NetQuery::GzipFlag::On) {
// TODO: try to compress files?
BufferSlice compressed = gzencode(slice.as_slice());
if (compressed.empty()) {
gzip_flag = NetQuery::GzipFlag::Off;
} else {
slice = std::move(compressed);
}
}
auto query = object_pool_.create(NetQuery::State::Query, id, std::move(slice), BufferSlice(), dc_id, type, auth_flag,
gzip_flag, tl_constructor);
query->set_cancellation_token(query.generation());
query->total_timeout_limit = total_timeout_limit;
return query;
}
} // namespace td