Networkwriter consistency (#2399)

* NetworkWriter consistency: Write(U)Ints moved to static extension methods for consistency with all the other writer functions like WriteUInt16.
This makes life easier because weaver looks for all Write(U)Int functions in the same place. Otherwise packed writes can't be removed in a later PR without breaking weaver (which is also evidence for being bad design before)

* NetworkReader consistency: removed redundant Read(U)Ints
This commit is contained in:
vis2k 2020-11-07 17:49:12 +01:00 committed by GitHub
parent 06e2d7ceda
commit a857707321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 50 deletions

View File

@ -63,30 +63,6 @@ public byte ReadByte()
} }
return buffer.Array[buffer.Offset + Position++]; return buffer.Array[buffer.Offset + Position++];
} }
public int ReadInt32() => (int)ReadUInt32();
public uint ReadUInt32()
{
uint value = 0;
value |= ReadByte();
value |= (uint)(ReadByte() << 8);
value |= (uint)(ReadByte() << 16);
value |= (uint)(ReadByte() << 24);
return value;
}
public long ReadInt64() => (long)ReadUInt64();
public ulong ReadUInt64()
{
ulong value = 0;
value |= ReadByte();
value |= ((ulong)ReadByte()) << 8;
value |= ((ulong)ReadByte()) << 16;
value |= ((ulong)ReadByte()) << 24;
value |= ((ulong)ReadByte()) << 32;
value |= ((ulong)ReadByte()) << 40;
value |= ((ulong)ReadByte()) << 48;
value |= ((ulong)ReadByte()) << 56;
return value;
}
// read bytes into the passed buffer // read bytes into the passed buffer
public byte[] ReadBytes(byte[] bytes, int count) public byte[] ReadBytes(byte[] bytes, int count)

View File

@ -142,32 +142,6 @@ public void WriteBytes(byte[] buffer, int offset, int count)
position += count; position += count;
} }
public void WriteUInt32(uint value)
{
EnsureLength(position + 4);
buffer[position++] = (byte)value;
buffer[position++] = (byte)(value >> 8);
buffer[position++] = (byte)(value >> 16);
buffer[position++] = (byte)(value >> 24);
}
public void WriteInt32(int value) => WriteUInt32((uint)value);
public void WriteUInt64(ulong value)
{
EnsureLength(position + 8);
buffer[position++] = (byte)value;
buffer[position++] = (byte)(value >> 8);
buffer[position++] = (byte)(value >> 16);
buffer[position++] = (byte)(value >> 24);
buffer[position++] = (byte)(value >> 32);
buffer[position++] = (byte)(value >> 40);
buffer[position++] = (byte)(value >> 48);
buffer[position++] = (byte)(value >> 56);
}
public void WriteInt64(long value) => WriteUInt64((ulong)value);
/// <summary> /// <summary>
/// Writes any type that mirror supports /// Writes any type that mirror supports
/// </summary> /// </summary>
@ -208,6 +182,30 @@ public static void WriteUInt16(this NetworkWriter writer, ushort value)
public static void WriteInt16(this NetworkWriter writer, short value) => writer.WriteUInt16((ushort)value); public static void WriteInt16(this NetworkWriter writer, short value) => writer.WriteUInt16((ushort)value);
public static void WriteUInt32(this NetworkWriter writer, uint value)
{
writer.WriteByte((byte)value);
writer.WriteByte((byte)(value >> 8));
writer.WriteByte((byte)(value >> 16));
writer.WriteByte((byte)(value >> 24));
}
public static void WriteInt32(this NetworkWriter writer, int value) => writer.WriteUInt32((uint)value);
public static void WriteUInt64(this NetworkWriter writer, ulong value)
{
writer.WriteByte((byte)value);
writer.WriteByte((byte)(value >> 8));
writer.WriteByte((byte)(value >> 16));
writer.WriteByte((byte)(value >> 24));
writer.WriteByte((byte)(value >> 32));
writer.WriteByte((byte)(value >> 40));
writer.WriteByte((byte)(value >> 48));
writer.WriteByte((byte)(value >> 56));
}
public static void WriteInt64(this NetworkWriter writer, long value) => writer.WriteUInt64((ulong)value);
public static void WriteSingle(this NetworkWriter writer, float value) public static void WriteSingle(this NetworkWriter writer, float value)
{ {
UIntFloat converter = new UIntFloat UIntFloat converter = new UIntFloat