Move as_key to FileDb.
GitOrigin-RevId: 4ecd7b79bdf0bc504dc5a3ddd39f971f47d0d1bb
This commit is contained in:
parent
cdefe9b1ee
commit
13c00abf17
@ -306,7 +306,7 @@ Status fix_file_remote_location_key_bug(SqliteDb &db) {
|
||||
auto remote_str = PSTRING() << key.substr(4, 4) << Slice("\0\0\0\0") << key.substr(8);
|
||||
FullRemoteFileLocation remote;
|
||||
if (unserialize(remote, remote_str).is_ok()) {
|
||||
kv.set(as_key(remote), value);
|
||||
kv.set(FileDbInterface::as_key(remote), value);
|
||||
}
|
||||
LOG(DEBUG) << "ERASE " << format::as_hex_dump<4>(Slice(key));
|
||||
kv.erase(key);
|
||||
|
@ -11,8 +11,10 @@
|
||||
|
||||
#include "td/actor/PromiseFuture.h"
|
||||
|
||||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/Status.h"
|
||||
#include "td/utils/tl_storers.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -41,9 +43,25 @@ class FileDbInterface {
|
||||
|
||||
// thread safe
|
||||
virtual void close(Promise<> promise) = 0;
|
||||
|
||||
template <class LocationT>
|
||||
static string as_key(const LocationT &object) {
|
||||
TlStorerCalcLength calc_length;
|
||||
calc_length.store_int(0);
|
||||
object.as_key().store(calc_length);
|
||||
|
||||
BufferSlice key_buffer{calc_length.get_length()};
|
||||
auto key = key_buffer.as_slice();
|
||||
TlStorerUnsafe storer(key.ubegin());
|
||||
storer.store_int(LocationT::KEY_MAGIC);
|
||||
object.as_key().store(storer);
|
||||
CHECK(storer.get_buf() == key.uend());
|
||||
return key.str();
|
||||
}
|
||||
|
||||
template <class LocationT>
|
||||
void get_file_data(const LocationT &location, Promise<FileData> promise) {
|
||||
get_file_data(as_key(location), std::move(promise));
|
||||
get_file_data_impl(as_key(location), std::move(promise));
|
||||
}
|
||||
|
||||
template <class LocationT>
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "td/utils/Slice.h"
|
||||
#include "td/utils/StringBuilder.h"
|
||||
#include "td/utils/tl_helpers.h"
|
||||
#include "td/utils/tl_storers.h"
|
||||
#include "td/utils/Variant.h"
|
||||
|
||||
#include <tuple>
|
||||
@ -1306,19 +1305,4 @@ inline StringBuilder &operator<<(StringBuilder &sb, const FileData &file_data) {
|
||||
return sb << "]";
|
||||
}
|
||||
|
||||
template <class T>
|
||||
string as_key(const T &object) {
|
||||
TlStorerCalcLength calc_length;
|
||||
calc_length.store_int(0);
|
||||
object.as_key().store(calc_length);
|
||||
|
||||
BufferSlice key_buffer{calc_length.get_length()};
|
||||
auto key = key_buffer.as_slice();
|
||||
TlStorerUnsafe storer(key.ubegin());
|
||||
storer.store_int(T::KEY_MAGIC);
|
||||
object.as_key().store(storer);
|
||||
CHECK(storer.get_buf() == key.uend());
|
||||
return key.str();
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
Loading…
Reference in New Issue
Block a user