Skip to content

Commit

Permalink
fix: Use big endian for packet size
Browse files Browse the repository at this point in the history
Tcp transport uses big endian now, just like Telepathy and Apathy
  • Loading branch information
paulpach committed Mar 10, 2020
1 parent f96a927 commit 1ddcbec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions Assets/Mirror/Runtime/Transport/Tcp/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ public abstract class Common
protected static int BytesToInt(byte[] bytes)
{
return
bytes[0] |
(bytes[1] << 8) |
(bytes[2] << 16) |
(bytes[3] << 24);
bytes[3] |
(bytes[2] << 8) |
(bytes[1] << 16) |
(bytes[0] << 24);

}

protected static void WriteSize(int length, byte[] bytes)
{
bytes[0] = (byte)length;
bytes[1] = (byte)(length >> 8);
bytes[2] = (byte)(length >> 16);
bytes[3] = (byte)(length >> 24);
bytes[3] = (byte)length;
bytes[2] = (byte)(length >> 8);
bytes[1] = (byte)(length >> 16);
bytes[0] = (byte)(length >> 24);
}

// send message (via stream) with the <size,content> message structure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public static async Task<byte[]> ReadExactlyAsync(this Stream stream, int size)

public static void WriteInt(this Stream stream, int length)
{
stream.WriteByte((byte)length);
stream.WriteByte((byte)(length >> 8));
stream.WriteByte((byte)(length >> 16));
stream.WriteByte((byte)(length >> 24));
stream.WriteByte((byte)(length >> 16));
stream.WriteByte((byte)(length >> 8));
stream.WriteByte((byte)length);
}

public static void WritePrefixedData(this Stream stream, ArraySegment<byte> data)
Expand Down

0 comments on commit 1ddcbec

Please sign in to comment.