aboutsummaryrefslogtreecommitdiff
path: root/src/ARMeilleure/Translation/PTC/PtcFormatter.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ARMeilleure/Translation/PTC/PtcFormatter.cs')
-rw-r--r--src/ARMeilleure/Translation/PTC/PtcFormatter.cs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/ARMeilleure/Translation/PTC/PtcFormatter.cs b/src/ARMeilleure/Translation/PTC/PtcFormatter.cs
index ddac3133..60953dcd 100644
--- a/src/ARMeilleure/Translation/PTC/PtcFormatter.cs
+++ b/src/ARMeilleure/Translation/PTC/PtcFormatter.cs
@@ -28,6 +28,26 @@ namespace ARMeilleure.Translation.PTC
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Dictionary<TKey, TValue> DeserializeAndUpdateDictionary<TKey, TValue>(Stream stream, Func<Stream, TValue> valueFunc, Func<TKey, TValue, (TKey, TValue)> updateFunc) where TKey : struct
+ {
+ Dictionary<TKey, TValue> dictionary = new();
+
+ int count = DeserializeStructure<int>(stream);
+
+ for (int i = 0; i < count; i++)
+ {
+ TKey key = DeserializeStructure<TKey>(stream);
+ TValue value = valueFunc(stream);
+
+ (key, value) = updateFunc(key, value);
+
+ dictionary.Add(key, value);
+ }
+
+ return dictionary;
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static List<T> DeserializeList<T>(Stream stream) where T : struct
{
List<T> list = new();