Skip to content

Commit

Permalink
fix: missed ushort reader/writer
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpach committed Sep 2, 2019
1 parent 68ce632 commit 74faf2a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
9 changes: 0 additions & 9 deletions Assets/Mirror/Runtime/NetworkReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ public byte ReadByte()
}
return buffer.Array[buffer.Offset + Position++];
}
// read char the same way that NetworkWriter writes it (2 bytes)
public short ReadInt16() => (short)ReadUInt16();
public ushort ReadUInt16()
{
ushort value = 0;
value |= ReadByte();
value |= (ushort)(ReadByte() << 8);
return value;
}
public int ReadInt32() => (int)ReadUInt32();
public uint ReadUInt32()
{
Expand Down
18 changes: 9 additions & 9 deletions Assets/Mirror/Runtime/NetworkWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ public void WriteBytes(byte[] buffer, int offset, int count)
stream.Write(buffer, offset, count);
}

public void WriteUInt16(ushort value)
{
WriteByte((byte)(value & 0xFF));
WriteByte((byte)(value >> 8));
}

public void WriteUInt32(uint value)
{
WriteByte((byte)(value & 0xFF));
Expand All @@ -93,7 +87,7 @@ public void WriteUInt64(ulong value)

#region Obsoletes
[Obsolete("Use WriteUInt16 instead")]
public void Write(ushort value) => WriteUInt16(value);
public void Write(ushort value) => this.WriteUInt16(value);

[Obsolete("Use WriteUInt32 instead")]
public void Write(uint value) => WriteUInt32(value);
Expand All @@ -109,13 +103,13 @@ public void WriteUInt64(ulong value)

// write char the same way that NetworkReader reads it (2 bytes)
[Obsolete("Use WriteChar instead")]
public void Write(char value) => WriteUInt16((ushort)value);
public void Write(char value) => this.WriteUInt16((ushort)value);

[Obsolete("Use WriteBoolean instead")]
public void Write(bool value) => WriteByte((byte)(value ? 1 : 0));

[Obsolete("Use WriteInt16 instead")]
public void Write(short value) => WriteUInt16((ushort)value);
public void Write(short value) => this.WriteUInt16((ushort)value);

[Obsolete("Use WriteInt32 instead")]
public void Write(int value) => WriteUInt32((uint)value);
Expand Down Expand Up @@ -208,6 +202,12 @@ public static class NetworkWriterExtensions

public static void WriteBoolean(this NetworkWriter writer, bool value) => writer.WriteByte((byte)(value ? 1 : 0));

public static void WriteUInt16(this NetworkWriter writer, ushort value)
{
writer.WriteByte((byte)(value & 0xFF));
writer.WriteByte((byte)(value >> 8));
}

public static void WriteInt16(this NetworkWriter writer, short value) => writer.WriteUInt16((ushort)value);

public static void WriteSingle(this NetworkWriter writer, float value)
Expand Down

0 comments on commit 74faf2a

Please sign in to comment.