I'm trying to simplify a Send function on a server I'm building. I'd like to reduce the number of methods that send data by having it so the sent information is specified in the parameters.
For example, going from lots of methods like this:
public static void QueryUsername( string text )
{
PacketBuffer buffer = new PacketBuffer();
buffer.Write( Outbound.DoesUserExist );
buffer.Write( text );
ClientTCP.SendData( buffer.ToArray() );
buffer.Dispose();
}
To a single method like this:
public static void Send( Outbound packageIndex, params object[] parameter )
{
PacketBuffer buffer = new PacketBuffer();
buffer.Write( packageIndex );
foreach ( object item in parameter )
{
buffer.Write( item );
}
ClientTCP.SendData( buffer.ToArray() );
buffer.Dispose();
}
I'm having difficulty figuring out how to pass the parameter
data through the Write
method though.
Anyone have any suggestions on how I can achieve this?
The Write
method has 5 overloads that transform different types into bytes so they can be packaged and sent between the client and server.