mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-28 06:03:05 +00:00
21 lines
No EOL
653 B
C#
21 lines
No EOL
653 B
C#
using System.Runtime.InteropServices;
|
|
using Shared.Packet.Packets;
|
|
|
|
namespace Shared.Packet;
|
|
|
|
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..]);
|
|
}
|
|
|
|
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>();
|
|
}
|
|
} |