mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-10 04:50:31 -04:00
Unpack fields for metadata export
This commit is contained in:
parent
423c7ea3e8
commit
e67d3df41a
@ -57,6 +57,10 @@ class global_metadata {
|
||||
|
||||
string_table const& names() const { return names_; }
|
||||
|
||||
std::vector<thrift::metadata::directory> const& directories() const {
|
||||
return directories_storage_;
|
||||
}
|
||||
|
||||
private:
|
||||
Meta const* const meta_;
|
||||
std::vector<thrift::metadata::directory> const directories_storage_;
|
||||
|
@ -56,6 +56,10 @@ class string_table {
|
||||
|
||||
std::string operator[](size_t index) const { return impl_->lookup(index); }
|
||||
|
||||
std::vector<std::string> unpack() const { return impl_->unpack(); }
|
||||
|
||||
bool is_packed() const { return impl_->is_packed(); }
|
||||
|
||||
static thrift::metadata::string_table
|
||||
pack(std::vector<std::string> const& input,
|
||||
pack_options const& options = pack_options());
|
||||
@ -65,6 +69,8 @@ class string_table {
|
||||
virtual ~impl() = default;
|
||||
|
||||
virtual std::string lookup(size_t index) const = 0;
|
||||
virtual std::vector<std::string> unpack() const = 0;
|
||||
virtual bool is_packed() const = 0;
|
||||
};
|
||||
|
||||
private:
|
||||
|
@ -371,6 +371,8 @@ class metadata_ final : public metadata_v2::impl {
|
||||
template <typename K>
|
||||
using set_type = folly::F14ValueSet<K>;
|
||||
|
||||
thrift::metadata::metadata unpack_metadata() const;
|
||||
|
||||
inode_view make_inode_view(uint32_t inode) const {
|
||||
// TODO: move compatibility details to metadata_types
|
||||
uint32_t index =
|
||||
@ -899,15 +901,45 @@ folly::dynamic metadata_<LoggerPolicy>::as_dynamic() const {
|
||||
return obj;
|
||||
}
|
||||
|
||||
template <typename LoggerPolicy>
|
||||
thrift::metadata::metadata metadata_<LoggerPolicy>::unpack_metadata() const {
|
||||
auto meta = meta_.thaw();
|
||||
|
||||
if (auto opts = meta.options_ref()) {
|
||||
if (opts->packed_chunk_table) {
|
||||
meta.chunk_table = chunk_table_;
|
||||
}
|
||||
if (opts->packed_directories) {
|
||||
meta.directories = global_.directories();
|
||||
}
|
||||
if (opts->packed_shared_files_table) {
|
||||
meta.shared_files_table_ref() = shared_files_;
|
||||
}
|
||||
if (auto const& names = global_.names(); names.is_packed()) {
|
||||
meta.names = names.unpack();
|
||||
meta.compact_names_ref().reset();
|
||||
}
|
||||
if (symlinks_.is_packed()) {
|
||||
meta.symlinks = symlinks_.unpack();
|
||||
meta.compact_symlinks_ref().reset();
|
||||
}
|
||||
opts->packed_chunk_table = false;
|
||||
opts->packed_directories = false;
|
||||
opts->packed_shared_files_table = false;
|
||||
}
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
template <typename LoggerPolicy>
|
||||
std::string metadata_<LoggerPolicy>::serialize_as_json(bool simple) const {
|
||||
std::string json;
|
||||
if (simple) {
|
||||
apache::thrift::SimpleJSONSerializer serializer;
|
||||
serializer.serialize(meta_.thaw(), &json);
|
||||
serializer.serialize(unpack_metadata(), &json);
|
||||
} else {
|
||||
apache::thrift::JSONSerializer serializer;
|
||||
serializer.serialize(meta_.thaw(), &json);
|
||||
serializer.serialize(unpack_metadata(), &json);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
@ -41,6 +41,12 @@ class legacy_string_table : public string_table::impl {
|
||||
return std::string(v_[index]);
|
||||
}
|
||||
|
||||
std::vector<std::string> unpack() const override {
|
||||
throw std::runtime_error("cannot unpack legacy string table");
|
||||
}
|
||||
|
||||
bool is_packed() const override { return false; }
|
||||
|
||||
private:
|
||||
string_table::LegacyTableView v_;
|
||||
};
|
||||
@ -113,6 +119,20 @@ class packed_string_table : public string_table::impl {
|
||||
return std::string(beg, end);
|
||||
}
|
||||
|
||||
std::vector<std::string> unpack() const override {
|
||||
std::vector<std::string> v;
|
||||
auto size = PackedIndex ? index_.size() : v_.index().size();
|
||||
if (size > 0) {
|
||||
v.reserve(size - 1);
|
||||
for (size_t i = 0; i < size - 1; ++i) {
|
||||
v.emplace_back(lookup(i));
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
bool is_packed() const override { return true; }
|
||||
|
||||
private:
|
||||
string_table::PackedTableView v_;
|
||||
char const* const buffer_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user