2022-02-04 09:45:38 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using Shared.Packet.Packets;
|
|
|
|
|
|
2022-02-10 01:44:50 +00:00
|
|
|
|
namespace Shared.Packet;
|
2022-02-04 09:45:38 +00:00
|
|
|
|
|
|
|
|
|
public static class PacketUtils {
|
|
|
|
|
public static void SerializeHeaded<T>(Span<byte> data, PacketHeader header, T t) where T : struct, IPacket {
|
|
|
|
|
header.Serialize(data);
|
|
|
|
|
t.Serialize(data[Constants.HeaderSize..]);
|
|
|
|
|
}
|
2022-02-10 01:44:50 +00:00
|
|
|
|
|
2022-02-04 09:45:38 +00:00
|
|
|
|
public static T Deserialize<T>(Span<byte> data) where T : IPacket, new() {
|
|
|
|
|
T packet = new T();
|
|
|
|
|
packet.Deserialize(data);
|
|
|
|
|
return packet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int SizeOf<T>() where T : struct, IPacket {
|
|
|
|
|
return Constants.HeaderSize + Marshal.SizeOf<T>();
|
|
|
|
|
}
|
|
|
|
|
}
|