generated from Nexus-Mods/NexusMods.App.Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to upgrading the index flag data type to support unique attrib…
…utes. Implement migration for old values, and add an example DB from the app that is in the old format, so that we can verify that upgrading to the new format works as expected.
- Loading branch information
Showing
10 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/NexusMods.MnemonicDB.Abstractions/Attributes/IndexedFlagsAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using NexusMods.MnemonicDB.Abstractions.BuiltInEntities; | ||
using NexusMods.MnemonicDB.Abstractions.ElementComparers; | ||
using NexusMods.MnemonicDB.Abstractions.ValueSerializers; | ||
|
||
namespace NexusMods.MnemonicDB.Abstractions.Attributes; | ||
|
||
/// <summary> | ||
/// An attribute that defines the indexing status of an attribute, this is stored as a custom attribute type because | ||
/// older DBs store data in a different format and a conversion on read is required. | ||
/// </summary> | ||
public class IndexedFlagsAttribute : ScalarAttribute<IndexedFlags, byte, UInt8Serializer> | ||
{ | ||
/// <inheritdoc /> | ||
public IndexedFlagsAttribute(string ns, string name) : | ||
base(ns, name) | ||
{ | ||
DefaultValue = IndexedFlags.None; | ||
} | ||
|
||
/// <summary> | ||
/// This performs the proper conversion from the low level representation to the high level representation. Taking | ||
/// into consideration old attribute formats | ||
/// </summary> | ||
public override IndexedFlags ReadValue(ReadOnlySpan<byte> span, ValueTag tag, AttributeResolver resolver) | ||
{ | ||
// Old format, an attribute's existance means it's indexed | ||
if (tag == ValueTag.Null) | ||
return IndexedFlags.Indexed; | ||
if (tag == ValueTag.UInt8) | ||
return (IndexedFlags)span[0]; | ||
return IndexedFlags.None; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override byte ToLowLevel(IndexedFlags value) | ||
{ | ||
return (byte)value; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override IndexedFlags FromLowLevel(byte value, AttributeResolver resolver) | ||
{ | ||
throw new NotSupportedException("This method should never be called."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+1.33 MB
tests/NexusMods.MnemonicDB.Tests/Resources/Databases/SDV.2_5_2025.rocksdb.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters