70 const std::string type_name =
"simple_list";
72 ritsuko::Version version;
74 std::optional<std::size_t> expected_length;
76 const auto& metamap = extract_json_object(metadata.
other, type_name);
78 const std::string& vstring = extract_json_version_string(metamap);
79 version = ritsuko::parse_version_string(vstring.c_str(), vstring.size(),
true);
80 if (version.major != 1) {
81 throw std::runtime_error(
"unsupported version string '" + vstring +
"'");
84 std::throw_with_nested(std::runtime_error(
"failed to validate 'version'"));
88 format = extract_simple_list_format(metamap);
89 if (format !=
"json.gz" && format !=
"hdf5") {
90 throw std::runtime_error(
"unknown format '" + format +
"'");
93 std::throw_with_nested(std::runtime_error(
"failed to validate 'format'"));
97 expected_length = extract_simple_list_length(metamap);
99 std::throw_with_nested(std::runtime_error(
"failed to validate 'length'"));
102 std::throw_with_nested(std::runtime_error(
"failed to validate '" + type_name +
"' in the object metadata"));
105 auto other_dir = path /
"other_contents";
106 std::size_t num_external = 0;
107 if (std::filesystem::exists(other_dir)) {
108 auto status = std::filesystem::status(other_dir);
109 if (status.type() != std::filesystem::file_type::directory) {
110 throw std::runtime_error(
"expected 'other_contents' to be a directory");
113 num_external = count_directory_entries(other_dir);
114 for (I<
decltype(num_external)> e = 0; e < num_external; ++e) {
115 auto epath = other_dir / ritsuko::itoa(e);
116 if (!std::filesystem::exists(epath)) {
117 throw std::runtime_error(
"expected an external list object at '" + std::filesystem::relative(epath, path).
string() +
"'");
122 std::throw_with_nested(std::runtime_error(
"failed to validate external list object at '" + std::filesystem::relative(epath, path).
string() +
"'"));
127 I<decltype(std::declval<uzuki2::List>().size())> len;
128 if (format ==
"json.gz") {
130 uzuki2::json::Options opt;
132 auto gzreader = open_reader<byteme::GzipFileReader>(path /
"list_contents.json.gz", byteme::GzipFileReaderOptions());
133 auto loaded = uzuki2::json::parse<uzuki2::DummyProvisioner>(*gzreader, uzuki2::DummyExternals(num_external), opt);
134 len =
reinterpret_cast<const uzuki2::List*
>(loaded.get())->size();
136 std::throw_with_nested(std::runtime_error(
"failed to validate 'list_contents.json.gz'"));
140 H5::H5File handle(path /
"list_contents.h5", H5F_ACC_RDONLY);
141 auto ghandle = handle.openGroup(type_name);
142 auto loaded = uzuki2::hdf5::parse<uzuki2::DummyProvisioner>(ghandle, uzuki2::DummyExternals(num_external), {});
143 len =
reinterpret_cast<const uzuki2::List*
>(loaded.get())->size();
145 std::throw_with_nested(std::runtime_error(
"failed to validate '" + type_name +
"' in 'list_contents.h5'"));
149 if (version.ge(1, 1, 0)) {
150 if (expected_length.has_value() && *expected_length != len) {
151 throw std::runtime_error(
"value of '/" + type_name +
"/length' from the object metadata differs from the length of the list");
163 const std::string type_name =
"simple_list";
165 const auto& metamap = extract_json_object(metadata.
other, type_name);
166 auto len_info = extract_simple_list_length(metamap);
167 if (len_info.has_value()) {
171 std::string format = extract_simple_list_format(metamap);
172 if (format ==
"hdf5") {
173 H5::H5File handle(path /
"list_contents.h5", H5F_ACC_RDONLY);
174 auto lhandle = handle.openGroup(
"simple_list");
175 auto vhandle = lhandle.openGroup(
"data");
176 return sanisizer::cast<std::size_t>(vhandle.getNumObjs());
181 auto other_dir = path /
"other_contents";
182 std::size_t num_external = 0;
183 if (std::filesystem::exists(other_dir)) {
184 num_external = count_directory_entries(other_dir);
187 uzuki2::json::Options opt;
189 auto gzreader = open_reader<byteme::GzipFileReader>(path /
"list_contents.json.gz", byteme::GzipFileReaderOptions());
190 auto ptr = uzuki2::json::parse<uzuki2::DummyProvisioner>(*gzreader, uzuki2::DummyExternals(num_external), opt);
191 return sanisizer::cast<std::size_t>(
reinterpret_cast<const uzuki2::List*
>(ptr.get())->size());
std::size_t height_of_simple_list(const std::filesystem::path &path, const ObjectMetadata &metadata, const Options &options)
Definition simple_list.hpp:162
void validate(const std::filesystem::path &path, const ObjectMetadata &metadata, const Options &options)
Definition _validate.hpp:107
void validate_simple_list(const std::filesystem::path &path, const ObjectMetadata &metadata, const Options &options)
Definition simple_list.hpp:69