I'm trying to convert an object to a byte stream and I'm using the code below to do it
Code:
public static byte[] ObjectToByteArray(System.Object obj)
{
MemoryStream fs = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
try
{
formatter.Serialize(fs, obj);
return fs.ToArray();
}
catch (Exception e)
{
Debug.Log("Exception sending friend request: " + e.Message);
return null;
}
finally
{
fs.Close();
}
}
The problem is that this puts a large C# header on the front of the byte stream. Is there a way to determine the size of the header, so when I send the stream over a socket, I can skip sending the header? Or better yet, not generate the header at all?