4internal static class NdsOverlayParser
7 private const int EntryLength = 32;
16 public static IReadOnlyList<NdsOverlay> Parse(
17 IImageDataSource source,
20 NdsFileSystem fileSystem,
21 NdsReadOptions options)
23 int length = ValidateLength(table, options);
24 byte[] data =
new byte[length];
25 source.ReadExactly(table.Offset, data);
26 return ParseEntries(data, processor, fileSystem);
37 public static async ValueTask<IReadOnlyList<NdsOverlay>> ParseAsync(
38 IImageDataSource source,
41 NdsFileSystem fileSystem,
42 NdsReadOptions options,
43 CancellationToken cancellationToken)
45 int length = ValidateLength(table, options);
46 byte[] data =
new byte[length];
47 await source.ReadExactlyAsync(table.Offset, data, cancellationToken).ConfigureAwait(
false);
48 return ParseEntries(data, processor, fileSystem);
56 private static NdsOverlay[] ParseEntries(
57 ReadOnlySpan<byte> data,
59 NdsFileSystem fileSystem)
61 var overlays =
new NdsOverlay[data.Length / EntryLength];
62 for (
int index = 0; index < overlays.Length; index++)
64 overlays[index] =
new(processor, data.Slice(index * EntryLength, EntryLength), fileSystem);
74 private static int ValidateLength(NdsRegion table, NdsReadOptions options)
76 if (table.Length % EntryLength != 0 ||
77 table.Length / EntryLength > options.MaximumOverlayCount ||
78 table.Length > Array.MaxLength)
80 throw new InvalidDataException(
"An overlay table has an invalid or excessive length.");
83 return checked((
int)table.Length);
NdsProcessor
Identifies a processor and execution mode.