Update label file cache format

This commit is contained in:
Malin E
2022-08-05 15:12:43 +02:00
parent 62aaa45ff5
commit a2938c8384
2 changed files with 25 additions and 2 deletions

View File

@@ -305,7 +305,16 @@ void RenderableConstellation::initialize() {
for (speck::Labelset::Entry& entry : _labelset.entries) {
if (!entry.identifier.empty()) {
entry.text = _constellationNamesTranslation.at(entry.identifier);
try {
entry.text = _constellationNamesTranslation.at(entry.identifier);
}
catch (const std::out_of_range&) {
std::string message = fmt::format(
"Identifier '{}' could not be found in list of constellations",
entry.identifier
);
throw ghoul::RuntimeError(message, "RenderableConstellation");
}
}
}
}

View File

@@ -37,7 +37,7 @@
namespace {
constexpr int8_t DataCacheFileVersion = 10;
constexpr int8_t LabelCacheFileVersion = 10;
constexpr int8_t LabelCacheFileVersion = 11;
constexpr int8_t ColorCacheFileVersion = 10;
bool startsWith(std::string lhs, std::string_view rhs) noexcept {
@@ -741,6 +741,13 @@ std::optional<Labelset> loadCachedFile(std::filesystem::path path) {
file.read(reinterpret_cast<char*>(&e.position.y), sizeof(float));
file.read(reinterpret_cast<char*>(&e.position.z), sizeof(float));
// Identifier
uint8_t idLen;
file.read(reinterpret_cast<char*>(&idLen), sizeof(uint8_t));
e.identifier.resize(idLen);
file.read(e.identifier.data(), idLen);
// Text
uint16_t len;
file.read(reinterpret_cast<char*>(&len), sizeof(uint16_t));
e.text.resize(len);
@@ -773,6 +780,13 @@ void saveCachedFile(const Labelset& labelset, std::filesystem::path path) {
file.write(reinterpret_cast<const char*>(&e.position.y), sizeof(float));
file.write(reinterpret_cast<const char*>(&e.position.z), sizeof(float));
// Identifier
checkSize<uint8_t>(e.identifier.size(), "Identifier too long");
uint8_t idLen = static_cast<uint8_t>(e.identifier.size());
file.write(reinterpret_cast<const char*>(&idLen), sizeof(uint8_t));
file.write(e.identifier.data(), idLen);
// Text
checkSize<uint16_t>(e.text.size(), "Text too long");
uint16_t len = static_cast<uint16_t>(e.text.size());
file.write(reinterpret_cast<const char*>(&len), sizeof(uint16_t));