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
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
|
|
|
public struct PacketHeader : IPacket {
|
|
|
|
|
// public int Length;
|
|
|
|
|
public Guid Id;
|
|
|
|
|
public PacketType Type;
|
2022-03-11 05:59:02 +00:00
|
|
|
|
public short PacketSize;
|
|
|
|
|
|
|
|
|
|
public short Size => 20;
|
2022-02-10 01:44:50 +00:00
|
|
|
|
|
2022-02-04 09:45:38 +00:00
|
|
|
|
public void Serialize(Span<byte> data) {
|
|
|
|
|
MemoryMarshal.Write(data, ref Id);
|
|
|
|
|
MemoryMarshal.Write(data[16..], ref Type);
|
2022-03-14 23:48:30 +00:00
|
|
|
|
MemoryMarshal.Write(data[18..], ref PacketSize);
|
2022-02-04 09:45:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 04:29:34 +00:00
|
|
|
|
public void Deserialize(ReadOnlySpan<byte> data) {
|
2022-02-04 09:45:38 +00:00
|
|
|
|
Id = MemoryMarshal.Read<Guid>(data);
|
|
|
|
|
Type = MemoryMarshal.Read<PacketType>(data[16..]);
|
2022-04-27 05:45:47 +00:00
|
|
|
|
PacketSize = MemoryMarshal.Read<short>(data[18..]);
|
2022-02-04 09:45:38 +00:00
|
|
|
|
}
|
2021-11-29 04:04:34 +00:00
|
|
|
|
}
|