4internal static class NdsBannerParser
11 public static NdsBanner? Parse(
12 IImageDataSource source,
14 NdsReadOptions options)
21 Span<byte> versionBytes = stackalloc
byte[2];
22 source.ReadExactly(offset, versionBytes);
23 int size = GetValidatedSize(NdsBinary.ReadUInt16(versionBytes, 0), options);
24 byte[] data =
new byte[size];
25 source.ReadExactly(offset, data);
26 return NdsBanner.Parse(data);
35 public static async ValueTask<NdsBanner?> ParseAsync(
36 IImageDataSource source,
38 NdsReadOptions options,
39 CancellationToken cancellationToken)
46 byte[] versionBytes =
new byte[2];
47 await source.ReadExactlyAsync(offset, versionBytes, cancellationToken).ConfigureAwait(
false);
48 int size = GetValidatedSize(NdsBinary.ReadUInt16(versionBytes, 0), options);
49 byte[] data =
new byte[size];
50 await source.ReadExactlyAsync(offset, data, cancellationToken).ConfigureAwait(
false);
51 return NdsBanner.Parse(data);
58 private static int GetValidatedSize(ushort version, NdsReadOptions options)
60 int size = NdsBanner.GetSize(version);
61 if (size > options.MaximumBannerBytes)
63 throw new InvalidDataException(
"The banner exceeds the configured parsing limit.");