Files
Il2CppInspectorRedux/VersionedSerialization/ReadableExtensions.cs
LukeFZ 20f90a0926 vendor in newer version of VersionedSerialization
this is done now to reduce the migration burden in the future when this is made into a nuget package (hopefully)
2026-03-13 17:34:07 +01:00

26 lines
905 B
C#

namespace VersionedSerialization;
public static class ReadableExtensions
{
extension<TReadable>(TReadable)
where TReadable : IReadable, new()
{
public static int StructSize(in StructVersion version = default, in ReaderConfig config = default)
=> TReadable.Size(version, config);
public static TReadable FromBytes(ReadOnlySpan<byte> data, bool littleEndian = true, ReaderConfig config = default,
in StructVersion version = default)
{
if (littleEndian)
{
var reader = Reader.LittleEndian(data, config: config);
return reader.ReadVersionedObject<TReadable>(version);
}
else
{
var reader = Reader.BigEndian(data, config: config);
return reader.ReadVersionedObject<TReadable>(version);
}
}
}
}