Rewrote packet system to reduce heap allocation

This commit is contained in:
sardelka9515
2022-09-08 12:37:06 -07:00
parent f1fc96bbd7
commit 76c529f1d1
29 changed files with 627 additions and 679 deletions

View File

@ -35,22 +35,6 @@ namespace RageCoop.Server
return "";
}
}
public static (byte, byte[]) GetBytesFromObject(object obj)
{
return obj switch
{
byte _ => (0x01, BitConverter.GetBytes((byte)obj)),
short _ => (0x02, BitConverter.GetBytes((short)obj)),
ushort _ => (0x03, BitConverter.GetBytes((ushort)obj)),
int _ => (0x04, BitConverter.GetBytes((int)obj)),
uint _ => (0x05, BitConverter.GetBytes((uint)obj)),
long _ => (0x06, BitConverter.GetBytes((long)obj)),
ulong _ => (0x07, BitConverter.GetBytes((ulong)obj)),
float _ => (0x08, BitConverter.GetBytes((float)obj)),
bool _ => (0x09, BitConverter.GetBytes((bool)obj)),
_ => (0x0, null),
};
}
public static List<NetConnection> Exclude(this IEnumerable<NetConnection> connections,NetConnection toExclude)
{
return new(connections.Where(e => e != toExclude));