refactoring: heap -> span

This commit is contained in:
2022-04-30 08:20:17 +04:00
parent 9ab5d4aca5
commit 2dd81cd859
36 changed files with 494 additions and 489 deletions
+36
View File
@@ -0,0 +1,36 @@
using System;
using System.Runtime.CompilerServices;
using NetStack.Buffers;
namespace Ragon.Core
{
public static class ProtocolHeader
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void WriteUShort(ushort id, ref Span<byte> data) {
data[0] = (byte)(id & 0x00FF);
data[1] = (byte)((id & 0xFF00) >> 8);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ushort ReadUShort(ref ReadOnlySpan<byte> data)
{
return (ushort)(data[0] + (data[1] << 8));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void WriteInt(int id, ref Span<byte> data) {
data[0] = (byte)(id & 0x00FF);
data[1] = (byte)((id & 0xFF00) >> 8);
data[2] = (byte)((id & 0xFF00) >> 16);
data[3] = (byte)((id & 0xFF00) >> 24);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ReadInt(ref ReadOnlySpan<byte> data)
{
return (ushort)(data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24));
}
}
}