From ad337df11a3939dea833fc39d7ee555a427b9d09 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Wed, 19 Feb 2025 23:17:55 -0500 Subject: [SharedCache] Warn when loading BNDB with different shared cache metadata version This does not actually give the user control to exit early, that looks to need core changes. --- view/sharedcache/core/SharedCache.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'view/sharedcache/core/SharedCache.cpp') diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp index 9e578384..a9d8a70b 100644 --- a/view/sharedcache/core/SharedCache.cpp +++ b/view/sharedcache/core/SharedCache.cpp @@ -3594,6 +3594,21 @@ bool SharedCacheMetadata::ViewHasMetadata(BinaryView* view) return view->QueryMetadata(Tag); } +std::optional SharedCacheMetadata::ViewMetadataVersion(BinaryView* view) +{ + // Whether the view has compatible metadata. I.e. if the version differs. + Ref viewMetadata = view->QueryMetadata(Tag); + if (!viewMetadata) + return std::nullopt; + DeserializationContext context; + rapidjson::ParseResult result = context.doc.Parse(viewMetadata->GetString().c_str()); + if (!result) + return std::nullopt; + if (!context.doc.HasMember("metadataVersion")) + return std::nullopt; + return context.doc["metadataVersion"].GetUint(); +} + // static std::optional SharedCacheMetadata::LoadFromView(BinaryView* view) { -- cgit v1.3.1