StructByteArrayHelpers.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace Ryujinx.Common.Memory
  4. {
  5. [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
  6. public struct ByteArray128 : IArray<byte>
  7. {
  8. private const int Size = 128;
  9. byte _element;
  10. public int Length => Size;
  11. public ref byte this[int index] => ref AsSpan()[index];
  12. public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
  13. }
  14. [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
  15. public struct ByteArray256 : IArray<byte>
  16. {
  17. private const int Size = 256;
  18. byte _element;
  19. public int Length => Size;
  20. public ref byte this[int index] => ref AsSpan()[index];
  21. public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
  22. }
  23. [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
  24. public struct ByteArray512 : IArray<byte>
  25. {
  26. private const int Size = 512;
  27. byte _element;
  28. public int Length => Size;
  29. public ref byte this[int index] => ref AsSpan()[index];
  30. public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
  31. }
  32. [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
  33. public struct ByteArray1024 : IArray<byte>
  34. {
  35. private const int Size = 1024;
  36. byte _element;
  37. public 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. [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
  42. public struct ByteArray2048 : IArray<byte>
  43. {
  44. private const int Size = 2048;
  45. byte _element;
  46. public int Length => Size;
  47. public ref byte this[int index] => ref AsSpan()[index];
  48. public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
  49. }
  50. [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
  51. public struct ByteArray4096 : IArray<byte>
  52. {
  53. private const int Size = 4096;
  54. byte _element;
  55. public int Length => Size;
  56. public ref byte this[int index] => ref AsSpan()[index];
  57. public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
  58. }
  59. }