Streamlines packet tests (#175)

This commit is contained in:
Kamron Batman 2020-07-11 00:29:53 -07:00 • committed by GitHub
parent 6a727c3401
commit 7d20cf7642
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 1782 additions and 1684 deletions

View file

@ -1,10 +1,11 @@
using System;
using System.Buffers;
using System.IO.Compression;
using System.Text;
namespace Server.Tests.Network.Packets
{
public class GumpUtilities
public static class GumpUtilities
{
public static readonly byte[] NoMoveBuffer = Encoding.ASCII.GetBytes("{ nomove }");
public static readonly byte[] NoCloseBuffer = Encoding.ASCII.GetBytes("{ noclose }");
@ -16,25 +17,28 @@ namespace Server.Tests.Network.Packets
public const string NoDispose = "{ nodispose }";
public const string NoResize = "{ noresize }";
public static int WritePacked(ReadOnlySpan<byte> source, Span<byte> dest)
public static void WritePacked(this Span<byte> dest, ref int pos, ReadOnlySpan<byte> source)
{
int length = source.Length;
if (length == 0)
{
dest.Slice(0, 4).Clear();
return 4;
#if NO_LOCAL_INIT
dest.Write(ref pos, 0);
#else
pos += 4;
#endif
return;
}
ulong packLength = (ulong)dest.Length - 8;
ZlibError ce = Zlib.Pack(dest.Slice(8), ref packLength, source, ZlibQuality.Default);
ZlibError ce = Zlib.Pack(dest.Slice(pos + 8), ref packLength, source, ZlibQuality.Default);
if (ce != ZlibError.Okay) Console.WriteLine("ZLib error: {0} (#{1})", ce, (int)ce);
((int)(4 + packLength)).CopyTo(dest.Slice(0, 4));
length.CopyTo(dest.Slice(4, 4));
return (int)(8 + packLength);
dest.Write(ref pos, (int)(4 + packLength));
dest.Write(ref pos, length);
pos += (int)packLength;
}
}
}