mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-11-04 15:18:59 +01:00
24 lines
748 B
C#
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];
|
|
}
|
|
}
|
|
}
|