I am using Flatbuffers to serialize some data, which is then sent over the network via TCP. I can deserialize it just fine in the client application, but I have a problem with some image data that I am sending.
I have my flatbuffers schema defined as follows:
namespace datapacket;
table FlatDataPacket {
id:string;
framedata:[ubyte];
}
root_type FlatDataPacket;
I deserialize my data like so:
ByteBuffer bb = new ByteBuffer(buffer);
var flatDataPacket = FlatDataPacket.GetRootAsFlatDataPacket(bb);
Now, in flatDataPacket
, my Id
is just fine, however, my imagedata
length is 8 and when I try to convert to an image, I get an exception:
for (int i = 0; i < flatDataPacket.FramedataLength; i++)
{
incomingPacket.FrameBytes[i] = flatDataPacket.GetFramedata(i);
}
Image returnImage = Image.FromStream(new MemoryStream(incomingPacket.FrameBytes));//Throws exception
Exception:
An exception of type 'System.ArgumentException' occurred in System.Drawing.dll but was not handled in user code
Additional information: Parameter is not valid.
What am I doing wrong? If I do this without flatbuffers and use either JSON or send just the image data, the image gets sent and deserialized just fine. Am I using the incorrect data type ubyte
?