Skip to content

Commit d0dddb6

Browse files
committed
accept scoped spans in SpanHelper
1 parent e73ee91 commit d0dddb6

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

TACTLib/Helpers/SpanHelper.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,43 @@ namespace TACTLib.Helpers
55
{
66
public static class SpanHelper
77
{
8-
public static Span<byte> Advance(ref Span<byte> input, int numBytes)
8+
public static Span<T> Advance<T>(scoped ref Span<T> input, int numEntries)
99
{
10-
var result = input.Slice(0, numBytes);
11-
input = input.Slice(numBytes);
10+
var result = input.Slice(0, numEntries);
11+
input = input.Slice(numEntries);
1212

1313
return result;
1414
}
1515

16-
public static ReadOnlySpan<byte> Advance(ref ReadOnlySpan<byte> input, int numBytes)
16+
public static ReadOnlySpan<T> Advance<T>(scoped ref ReadOnlySpan<T> input, int numEntries)
1717
{
18-
var result = input.Slice(0, numBytes);
19-
input = input.Slice(numBytes);
18+
var result = input.Slice(0, numEntries);
19+
input = input.Slice(numEntries);
2020

2121
return result;
2222
}
2323

24-
public static unsafe ref T ReadStruct<T>(ref Span<byte> input) where T : unmanaged
24+
public static unsafe ref T ReadStruct<T>(scoped ref Span<byte> input) where T : unmanaged
2525
{
2626
ref var result = ref MemoryMarshal.AsRef<T>(input);
2727
input = input.Slice(sizeof(T));
2828
return ref result;
2929
}
3030

31-
public static unsafe T ReadStruct<T>(ref ReadOnlySpan<byte> input) where T : unmanaged
31+
public static unsafe T ReadStruct<T>(scoped ref ReadOnlySpan<byte> input) where T : unmanaged
3232
{
3333
var result = MemoryMarshal.Read<T>(input);
3434
input = input.Slice(sizeof(T));
3535
return result;
3636
}
3737

38-
public static unsafe ReadOnlySpan<T> ReadArray<T>(ref ReadOnlySpan<byte> input, int count) where T : unmanaged
38+
public static unsafe ReadOnlySpan<T> ReadArray<T>(scoped ref ReadOnlySpan<byte> input, int count) where T : unmanaged
3939
{
4040
var resultBytes = Advance(ref input, sizeof(T) * count);
4141
return MemoryMarshal.Cast<byte, T>(resultBytes);
4242
}
4343

44-
public static byte ReadByte(ref Span<byte> input)
44+
public static byte ReadByte(scoped ref Span<byte> input)
4545
{
4646
var result = input[0];
4747
input = input.Slice(1);

0 commit comments

Comments
 (0)