October 27th, 2013, 09:23 PM
Converting an object to a byte stream
I'm trying to convert an object to a byte stream and I'm using the code below to do it
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?
public static byte ObjectToByteArray(System.Object obj)
MemoryStream fs = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
catch (Exception e)
Debug.Log("Exception sending friend request: " + e.Message);
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.