Well, the title may not have been very explanatory, but I hope to improve this in the content of the topic.
I made a library in C # in which, so far, it writes packages manually, as in the example below:
//Escrevendo o pacote
SocketPacket Packet = new SocketPacket(PacketID.AccountID);
Packet.WriteString(Username);
Packet.WriteString(Password);
Client.Socket.Send(Packet);
//Lendo o pacote
switch(Packet.ID)
{
.....
case PacketID.AccountID:
string Username = Packet.ReadString();
string Password = Packet.ReadString();
.....
}
It's working fine, but as you can see, I always have to read and write packages manually. However, I had an idea, in which the data of the package would be stored in a class, which would implement an interface, forcing it to have an execution method, as in the example below:
public class AccountPacket : IPacket
{
public string Username { get; set; }
public string Password { get; set; }
public void Execute()
{
....
}
}
Testing on the local server, there is no drastic change in speed, but I can not test on some remote server, in order to check the speed of both methods.
For those who have endured my craze for lengthy explanations, the question would be which of the methods would be recommended for a server, in the exclusive case for real-time gaming (in which packets are always sent non-stop to multiple clients). In the first case, it would be something done manually, and in the second, as I said, I'm using Reflection , next to the GetProperty method.
Thank you to anyone who can respond.