aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Common/Memory/SpanReader.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ryujinx.Common/Memory/SpanReader.cs')
-rw-r--r--src/Ryujinx.Common/Memory/SpanReader.cs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Ryujinx.Common/Memory/SpanReader.cs b/src/Ryujinx.Common/Memory/SpanReader.cs
index 673932d0..9a1a0a3f 100644
--- a/src/Ryujinx.Common/Memory/SpanReader.cs
+++ b/src/Ryujinx.Common/Memory/SpanReader.cs
@@ -24,6 +24,24 @@ namespace Ryujinx.Common.Memory
return value;
}
+ public bool TryRead<T>(out T value) where T : unmanaged
+ {
+ int valueSize = Unsafe.SizeOf<T>();
+
+ if (valueSize > _input.Length)
+ {
+ value = default;
+
+ return false;
+ }
+
+ value = MemoryMarshal.Cast<byte, T>(_input)[0];
+
+ _input = _input.Slice(valueSize);
+
+ return true;
+ }
+
public ReadOnlySpan<byte> GetSpan(int size)
{
ReadOnlySpan<byte> data = _input.Slice(0, size);