Move FileDAta to FileData.h.
GitOrigin-RevId: d0724db9881d39ca22fe491dc4809a3f03bf6b2b
This commit is contained in:
parent
13c00abf17
commit
3c46828749
@ -484,6 +484,7 @@ set(TDLIB_SOURCE
|
||||
td/telegram/DraftMessage.h
|
||||
td/telegram/FileReferenceManager.h
|
||||
td/telegram/files/FileBitmask.h
|
||||
td/telegram/files/FileData.h
|
||||
td/telegram/files/FileDb.h
|
||||
td/telegram/files/FileDbId.h
|
||||
td/telegram/files/FileDownloader.h
|
||||
|
118
td/telegram/files/FileData.h
Normal file
118
td/telegram/files/FileData.h
Normal file
@ -0,0 +1,118 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/files/FileLocation.h"
|
||||
#include "td/telegram/files/FileEncryptionKey.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/format.h"
|
||||
#include "td/utils/StringBuilder.h"
|
||||
#include "td/utils/tl_helpers.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
class FileData {
|
||||
public:
|
||||
DialogId owner_dialog_id_;
|
||||
uint64 pmc_id_ = 0;
|
||||
RemoteFileLocation remote_;
|
||||
LocalFileLocation local_;
|
||||
unique_ptr<FullGenerateFileLocation> generate_;
|
||||
int64 size_ = 0;
|
||||
int64 expected_size_ = 0;
|
||||
string remote_name_;
|
||||
string url_;
|
||||
FileEncryptionKey encryption_key_;
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const {
|
||||
using ::td::store;
|
||||
bool has_owner_dialog_id = owner_dialog_id_.is_valid();
|
||||
bool has_expected_size = size_ == 0 && expected_size_ != 0;
|
||||
bool encryption_key_is_secure = encryption_key_.is_secure();
|
||||
BEGIN_STORE_FLAGS();
|
||||
STORE_FLAG(has_owner_dialog_id);
|
||||
STORE_FLAG(has_expected_size);
|
||||
STORE_FLAG(encryption_key_is_secure);
|
||||
END_STORE_FLAGS();
|
||||
|
||||
if (has_owner_dialog_id) {
|
||||
store(owner_dialog_id_, storer);
|
||||
}
|
||||
store(pmc_id_, storer);
|
||||
store(remote_, storer);
|
||||
store(local_, storer);
|
||||
auto generate = generate_ == nullptr ? GenerateFileLocation() : GenerateFileLocation(*generate_);
|
||||
store(generate, storer);
|
||||
if (has_expected_size) {
|
||||
store(expected_size_, storer);
|
||||
} else {
|
||||
store(size_, storer);
|
||||
}
|
||||
store(remote_name_, storer);
|
||||
store(url_, storer);
|
||||
store(encryption_key_, storer);
|
||||
}
|
||||
template <class ParserT>
|
||||
void parse(ParserT &parser) {
|
||||
using ::td::parse;
|
||||
bool has_owner_dialog_id;
|
||||
bool has_expected_size;
|
||||
bool encryption_key_is_secure;
|
||||
BEGIN_PARSE_FLAGS();
|
||||
PARSE_FLAG(has_owner_dialog_id);
|
||||
PARSE_FLAG(has_expected_size);
|
||||
PARSE_FLAG(encryption_key_is_secure);
|
||||
END_PARSE_FLAGS_GENERIC();
|
||||
|
||||
if (has_owner_dialog_id) {
|
||||
parse(owner_dialog_id_, parser);
|
||||
}
|
||||
parse(pmc_id_, parser);
|
||||
parse(remote_, parser);
|
||||
parse(local_, parser);
|
||||
GenerateFileLocation generate;
|
||||
parse(generate, parser);
|
||||
if (generate.type() == GenerateFileLocation::Type::Full) {
|
||||
generate_ = make_unique<FullGenerateFileLocation>(generate.full());
|
||||
} else {
|
||||
generate_ = nullptr;
|
||||
}
|
||||
if (has_expected_size) {
|
||||
parse(expected_size_, parser);
|
||||
} else {
|
||||
parse(size_, parser);
|
||||
}
|
||||
parse(remote_name_, parser);
|
||||
parse(url_, parser);
|
||||
encryption_key_.parse(encryption_key_is_secure ? FileEncryptionKey::Type::Secure : FileEncryptionKey::Type::Secret,
|
||||
parser);
|
||||
}
|
||||
};
|
||||
|
||||
inline StringBuilder &operator<<(StringBuilder &sb, const FileData &file_data) {
|
||||
sb << "[" << tag("remote_name", file_data.remote_name_) << " " << file_data.owner_dialog_id_ << " "
|
||||
<< tag("size", file_data.size_) << tag("expected_size", file_data.expected_size_) << " "
|
||||
<< file_data.encryption_key_;
|
||||
if (!file_data.url_.empty()) {
|
||||
sb << tag("url", file_data.url_);
|
||||
}
|
||||
if (file_data.local_.type() == LocalFileLocation::Type::Full) {
|
||||
sb << " local " << file_data.local_.full();
|
||||
}
|
||||
if (file_data.generate_ != nullptr) {
|
||||
sb << " generate " << *file_data.generate_;
|
||||
}
|
||||
if (file_data.remote_.type() == RemoteFileLocation::Type::Full) {
|
||||
sb << " remote " << file_data.remote_.full();
|
||||
}
|
||||
return sb << "]";
|
||||
}
|
||||
|
||||
} // namespace td
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/files/FileData.h"
|
||||
#include "td/telegram/files/FileDbId.h"
|
||||
#include "td/telegram/files/FileLocation.h"
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "td/telegram/td_api.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/files/FileBitmask.h"
|
||||
#include "td/telegram/files/FileEncryptionKey.h"
|
||||
#include "td/telegram/net/DcId.h"
|
||||
@ -1207,102 +1206,4 @@ inline bool operator!=(const GenerateFileLocation &lhs, const GenerateFileLocati
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
class FileData {
|
||||
public:
|
||||
DialogId owner_dialog_id_;
|
||||
uint64 pmc_id_ = 0;
|
||||
RemoteFileLocation remote_;
|
||||
LocalFileLocation local_;
|
||||
unique_ptr<FullGenerateFileLocation> generate_;
|
||||
int64 size_ = 0;
|
||||
int64 expected_size_ = 0;
|
||||
string remote_name_;
|
||||
string url_;
|
||||
FileEncryptionKey encryption_key_;
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const {
|
||||
using ::td::store;
|
||||
bool has_owner_dialog_id = owner_dialog_id_.is_valid();
|
||||
bool has_expected_size = size_ == 0 && expected_size_ != 0;
|
||||
bool encryption_key_is_secure = encryption_key_.is_secure();
|
||||
BEGIN_STORE_FLAGS();
|
||||
STORE_FLAG(has_owner_dialog_id);
|
||||
STORE_FLAG(has_expected_size);
|
||||
STORE_FLAG(encryption_key_is_secure);
|
||||
END_STORE_FLAGS();
|
||||
|
||||
if (has_owner_dialog_id) {
|
||||
store(owner_dialog_id_, storer);
|
||||
}
|
||||
store(pmc_id_, storer);
|
||||
store(remote_, storer);
|
||||
store(local_, storer);
|
||||
auto generate = generate_ == nullptr ? GenerateFileLocation() : GenerateFileLocation(*generate_);
|
||||
store(generate, storer);
|
||||
if (has_expected_size) {
|
||||
store(expected_size_, storer);
|
||||
} else {
|
||||
store(size_, storer);
|
||||
}
|
||||
store(remote_name_, storer);
|
||||
store(url_, storer);
|
||||
store(encryption_key_, storer);
|
||||
}
|
||||
template <class ParserT>
|
||||
void parse(ParserT &parser) {
|
||||
using ::td::parse;
|
||||
bool has_owner_dialog_id;
|
||||
bool has_expected_size;
|
||||
bool encryption_key_is_secure;
|
||||
BEGIN_PARSE_FLAGS();
|
||||
PARSE_FLAG(has_owner_dialog_id);
|
||||
PARSE_FLAG(has_expected_size);
|
||||
PARSE_FLAG(encryption_key_is_secure);
|
||||
END_PARSE_FLAGS_GENERIC();
|
||||
|
||||
if (has_owner_dialog_id) {
|
||||
parse(owner_dialog_id_, parser);
|
||||
}
|
||||
parse(pmc_id_, parser);
|
||||
parse(remote_, parser);
|
||||
parse(local_, parser);
|
||||
GenerateFileLocation generate;
|
||||
parse(generate, parser);
|
||||
if (generate.type() == GenerateFileLocation::Type::Full) {
|
||||
generate_ = make_unique<FullGenerateFileLocation>(generate.full());
|
||||
} else {
|
||||
generate_ = nullptr;
|
||||
}
|
||||
if (has_expected_size) {
|
||||
parse(expected_size_, parser);
|
||||
} else {
|
||||
parse(size_, parser);
|
||||
}
|
||||
parse(remote_name_, parser);
|
||||
parse(url_, parser);
|
||||
encryption_key_.parse(encryption_key_is_secure ? FileEncryptionKey::Type::Secure : FileEncryptionKey::Type::Secret,
|
||||
parser);
|
||||
}
|
||||
};
|
||||
|
||||
inline StringBuilder &operator<<(StringBuilder &sb, const FileData &file_data) {
|
||||
sb << "[" << tag("remote_name", file_data.remote_name_) << " " << file_data.owner_dialog_id_ << " "
|
||||
<< tag("size", file_data.size_) << tag("expected_size", file_data.expected_size_) << " "
|
||||
<< file_data.encryption_key_;
|
||||
if (!file_data.url_.empty()) {
|
||||
sb << tag("url", file_data.url_);
|
||||
}
|
||||
if (file_data.local_.type() == LocalFileLocation::Type::Full) {
|
||||
sb << " local " << file_data.local_.full();
|
||||
}
|
||||
if (file_data.generate_ != nullptr) {
|
||||
sb << " generate " << *file_data.generate_;
|
||||
}
|
||||
if (file_data.remote_.type() == RemoteFileLocation::Type::Full) {
|
||||
sb << " remote " << file_data.remote_.full();
|
||||
}
|
||||
return sb << "]";
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "td/telegram/ConfigShared.h"
|
||||
#include "td/telegram/FileReferenceManager.h"
|
||||
#include "td/telegram/files/FileData.h"
|
||||
#include "td/telegram/files/FileDb.h"
|
||||
#include "td/telegram/files/FileLoaderUtils.h"
|
||||
#include "td/telegram/files/FileLocation.h"
|
||||
@ -849,7 +850,7 @@ Result<FileId> FileManager::register_generate(FileType file_type, FileLocationSo
|
||||
return register_file(std::move(data), file_location_source, "register_generate", false);
|
||||
}
|
||||
|
||||
Result<FileId> FileManager::register_file(FileData data, FileLocationSource file_location_source, const char *source,
|
||||
Result<FileId> FileManager::register_file(FileData &&data, FileLocationSource file_location_source, const char *source,
|
||||
bool force) {
|
||||
bool has_remote = data.remote_.type() == RemoteFileLocation::Type::Full;
|
||||
bool has_generate = data.generate_ != nullptr;
|
||||
|
@ -41,6 +41,7 @@ namespace td {
|
||||
|
||||
extern int VERBOSITY_NAME(update_file);
|
||||
|
||||
class FileData;
|
||||
class FileDbInterface;
|
||||
|
||||
enum class FileLocationSource : int8 { None, FromUser, FromDb, FromServer };
|
||||
@ -346,7 +347,6 @@ class FileManager : public FileLoadManager::Callback {
|
||||
Result<FileId> register_generate(FileType file_type, FileLocationSource file_location_source, string original_path,
|
||||
string conversion, DialogId owner_dialog_id,
|
||||
int64 expected_size) TD_WARN_UNUSED_RESULT;
|
||||
Result<FileId> register_file(FileData data, FileLocationSource file_location_source, const char *source, bool force);
|
||||
|
||||
Result<FileId> merge(FileId x_file_id, FileId y_file_id, bool no_sync = false) TD_WARN_UNUSED_RESULT;
|
||||
|
||||
@ -404,6 +404,8 @@ class FileManager : public FileLoadManager::Callback {
|
||||
|
||||
FileId register_url(string url, FileType file_type, FileLocationSource file_location_source,
|
||||
DialogId owner_dialog_id);
|
||||
Result<FileId> register_file(FileData &&data, FileLocationSource file_location_source, const char *source,
|
||||
bool force);
|
||||
|
||||
static constexpr int8 FROM_BYTES_PRIORITY = 10;
|
||||
using FileNodeId = int32;
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "td/telegram/files/FileStatsWorker.h"
|
||||
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/files/FileData.h"
|
||||
#include "td/telegram/files/FileDb.h"
|
||||
#include "td/telegram/files/FileLoaderUtils.h"
|
||||
#include "td/telegram/Global.h"
|
||||
|
Loading…
Reference in New Issue
Block a user