Files
defrain-shooter-unity/Assets/Mirror/Runtime/Transport/Telepathy/Telepathy/Utils.cs
2021-10-25 09:20:01 +02:00

24 lines
748 B
C#

namespace Telepathy
{
public static class Utils
{
// IntToBytes version that doesn't allocate a new byte[4] each time.
// -> important for MMO scale networking performance.
public static void IntToBytesBigEndianNonAlloc(int value, byte[] bytes, int offset = 0)
{
bytes[offset + 0] = (byte)(value >> 24);
bytes[offset + 1] = (byte)(value >> 16);
bytes[offset + 2] = (byte)(value >> 8);
bytes[offset + 3] = (byte)value;
}
public static int BytesToIntBigEndian(byte[] bytes)
{
return (bytes[0] << 24) |
(bytes[1] << 16) |
(bytes[2] << 8) |
bytes[3];
}
}
}