Hello there! In our current code, we use structs to represent a packet;
Packet<Data>
Packet<Data>
. This packet (struct) has a
ushort Identifier
ushort Identifier
and a
Codec<Data> Codec
Codec<Data> Codec
.
This
Identifier
Identifier
should be unique, but currently we assign these manually:
Packet<String> SendMessage = new Packet<String>(0, CodecString.UTF8);
Packet<String> SendMessage = new Packet<String>(0, CodecString.UTF8);
This isn't ideal, so I considered using an Enum to represent the packet Id's, however that would mean that the packets would be in 2 places, the enum and the
Packet
Packet
instance holding the codec.
Is there a way to combine this? The ideal solution would be an enum with generic
<Data>
<Data>
to allow enforcing the codec used:
public void SendPacket<Data>(PacketEnum<Data> enumType, Data data){}
public void SendPacket<Data>(PacketEnum<Data> enumType, Data data){}