/ src / Ryujinx.Common / Memory / StructByteArrayHelpers.cs
StructByteArrayHelpers.cs
 1  using System;
 2  using System.Runtime.InteropServices;
 3  
 4  namespace Ryujinx.Common.Memory
 5  {
 6      [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
 7      public struct ByteArray128 : IArray<byte>
 8      {
 9          private const int Size = 128;
10  
11          byte _element;
12  
13          public readonly int Length => Size;
14          public ref byte this[int index] => ref AsSpan()[index];
15          public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
16      }
17  
18      [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
19      public struct ByteArray256 : IArray<byte>
20      {
21          private const int Size = 256;
22  
23          byte _element;
24  
25          public readonly int Length => Size;
26          public ref byte this[int index] => ref AsSpan()[index];
27          public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
28      }
29  
30      [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
31      public struct ByteArray512 : IArray<byte>
32      {
33          private const int Size = 512;
34  
35          byte _element;
36  
37          public readonly int Length => Size;
38          public ref byte this[int index] => ref AsSpan()[index];
39          public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
40      }
41  
42      [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
43      public struct ByteArray1024 : IArray<byte>
44      {
45          private const int Size = 1024;
46  
47          byte _element;
48  
49          public readonly int Length => Size;
50          public ref byte this[int index] => ref AsSpan()[index];
51          public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
52      }
53  
54      [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
55      public struct ByteArray2048 : IArray<byte>
56      {
57          private const int Size = 2048;
58  
59          byte _element;
60  
61          public readonly int Length => Size;
62          public ref byte this[int index] => ref AsSpan()[index];
63          public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
64      }
65  
66      [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
67      public struct ByteArray3000 : IArray<byte>
68      {
69          private const int Size = 3000;
70  
71          byte _element;
72  
73          public readonly int Length => Size;
74          public ref byte this[int index] => ref AsSpan()[index];
75          public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
76      }
77  
78      [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
79      public struct ByteArray4096 : IArray<byte>
80      {
81          private const int Size = 4096;
82  
83          byte _element;
84  
85          public readonly int Length => Size;
86          public ref byte this[int index] => ref AsSpan()[index];
87          public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
88      }
89  }