Inline binary reading to avoid polluting `RealmAccess` with nested class

This commit is contained in:
Dean Herbert 2023-06-09 17:34:27 +09:00
parent a9071e7afd
commit 53f935714e
1 changed files with 8 additions and 18 deletions

View File

@ -912,9 +912,14 @@ void convertOnlineIDs<T>() where T : RealmObject
if (stream == null)
continue;
int version = new ReplayVersionParser().Parse(stream);
if (version < LegacyScoreEncoder.FIRST_LAZER_VERSION)
score.IsLegacyScore = true;
// Trimmed down logic from LegacyScoreDecoder to extract the version from replays.
using (SerializationReader sr = new SerializationReader(stream))
{
sr.ReadByte(); // Ruleset.
int version = sr.ReadInt32();
if (version < LegacyScoreEncoder.FIRST_LAZER_VERSION)
score.IsLegacyScore = true;
}
}
}
catch (Exception e)
@ -1145,20 +1150,5 @@ public void Dispose()
isDisposed = true;
}
}
/// <summary>
/// A trimmed down <see cref="LegacyScoreDecoder"/> specialised to extract the version from replays.
/// </summary>
private class ReplayVersionParser
{
public int Parse(Stream stream)
{
using (SerializationReader sr = new SerializationReader(stream))
{
sr.ReadByte(); // Ruleset.
return sr.ReadInt32();
}
}
}
}
}