PartsManager: truncate unchecked part of a bitmask

GitOrigin-RevId: 733c1f7a2a63a25103e10392780123e1e2289425
This commit is contained in:
Arseny Smirnov 2018-12-27 12:12:24 +03:00
parent e60c9ab24d
commit 4cee00d938
3 changed files with 10 additions and 3 deletions

View File

@ -20,9 +20,12 @@ Bitmask::Bitmask(Ones, int64 count) : data_(narrow_cast<size_t>((count + 7) / 8)
}
}
std::string Bitmask::encode() const {
std::string Bitmask::encode(int32 prefix_count) const {
// remove zeroes in the end to make encoding deterministic
td::Slice data(data_);
if (prefix_count != -1) {
data.truncate(prefix_count);
}
while (!data.empty() && data.back() == '\0') {
data.remove_suffix(1);
}

View File

@ -19,7 +19,7 @@ class Bitmask {
Bitmask() = default;
Bitmask(Decode, Slice data);
Bitmask(Ones, int64 count);
std::string encode() const;
std::string encode(int32 prefix_count = -1) const;
int64 get_ready_prefix_size(int64 offset, int64 part_size, int64 file_size) const;
int64 get_total_size(int64 part_size, int64 file_size) const;
bool get(int64 offset_part) const;

View File

@ -170,7 +170,11 @@ int32 PartsManager::get_ready_prefix_count() {
return res;
}
string PartsManager::get_bitmask() const {
return bitmask_.encode();
int32 prefix_count = -1;
if (need_check_) {
prefix_count = narrow_cast<int32>(checked_prefix_size_ / part_size_);
}
return bitmask_.encode(prefix_count);
}
Result<Part> PartsManager::start_part() {