2 using System.Runtime.CompilerServices;
7 internal static class WriteOnlyMessageExtensions
10 public static IWriteMessage WithHeader(
this IWriteMessage msg,
ClientPacketHeader header)
12 msg.WriteByte((
byte)header);
16 public static IWriteMessage WithHeader(
this IWriteMessage msg,
ServerPacketHeader header)
18 msg.WriteByte((
byte)header);
22 public static void WriteNetSerializableStruct(
this IWriteMessage msg, INetSerializableStruct serializableStruct)
24 serializableStruct.Write(msg);
27 public static NetOutgoingMessage ToLidgren(
this IWriteMessage msg, NetPeer peer)
29 NetOutgoingMessage outMsg = peer.CreateMessage();
30 outMsg.Write(msg.Buffer, 0, msg.LengthBytes);
35 internal static class NetIncomingMessageExtensions
37 public static T ReadHeader<T>(
this NetIncomingMessage msg) where T : Enum
39 byte header = msg.ReadByte();
40 return Unsafe.As<byte, T>(ref header);
43 public static IReadMessage ToReadMessage(
this NetIncomingMessage msg)
45 return new ReadWriteMessage(msg.Data, 0, msg.LengthBits, copyBuf:
false);
49 internal static class DeliveryMethodExtensions
51 public static NetDeliveryMethod ToLidgren(
this DeliveryMethod deliveryMethod) =>
54 DeliveryMethod.Unreliable => NetDeliveryMethod.Unreliable,
55 DeliveryMethod.Reliable => NetDeliveryMethod.ReliableOrdered,
56 _ => NetDeliveryMethod.Unreliable
59 public static Steamworks.P2PSend ToSteam(
this DeliveryMethod deliveryMethod) =>
62 DeliveryMethod.Reliable => Steamworks.P2PSend.Reliable,
63 _ => Steamworks.P2PSend.Unreliable