I use "protobuf-net" for Serializing a structure, but it returns an empty array.
public static byte[] PacketToArray(Packet packet)
{
IFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
Serializer.Serialize(stream, packet);
byte[] packetArray = stream.GetBuffer();
stream.Close();
return packetArray;
}
packetArray[] ist at the ending "{byte[0]}" but there should be some data in. The data of "packet" is:
[ProtoContract]
public struct Packet
{
[ProtoMember(1)]
public int opcode;
[ProtoMember(2)]
public string message;
}
And in the testings the values vor opcode is 0 and for message its null. Where is the Problem?
ToByteArray()instead ofGetBuffer()- it won't fix this problem, but it will give you a byte array with the right amount of data, when you've got the rest working.