Creates more tests for outgoing packets (#165)

This commit is contained in:
Kamron Batman 2020-06-26 12:04:29 -07:00 • committed by GitHub
parent d76d60d900
commit 24b1a579f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 2321 additions and 1488 deletions

View file

@ -80,5 +80,24 @@ namespace Server.Tests.Network.Packets
{
pos += Encoding.ASCII.GetBytes(str.AsSpan(0, Math.Min(str.Length, max)), bytes.Slice(pos));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void CopyASCIIFixedTo(this string str, ref int pos, int max, Span<byte> bytes)
{
int bytesWritten = Encoding.ASCII.GetBytes(str.AsSpan(0, Math.Min(str.Length, max)), bytes.Slice(pos));
// This is not needed in the current stackalloc implementation, but not guaranteed in the future.
if (bytesWritten < max)
bytes.Slice(pos + bytesWritten, max - bytesWritten).Clear();
pos += max;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Clear(this Span<byte> span, ref int pos, int amount)
{
span.Slice(pos, amount).Clear();
pos += amount;
}
}
}