Reputation: 391
I am using ProtoBuf-Net in my .NET application to serialize the following : (in .proto format)
message ProtoScreenBuffer {
optional int32 MediaId = 1;
optional bytes Data = 2;
optional bool LastBuffer = 3;
optional int64 StartTime = 4;
optional int64 StopTime = 5;
optional int32 Flags = 6;
optional int32 BufferSubType = 7;
optional int32 BufferType = 8;
optional Guid Guid = 9;
repeated int32 EncryptedDataStart = 10;
repeated int32 EncryptedDataLength = 11;
}
My aim is to serialize this and inject it into an ASF file, as a single sample.
I call this to serialize :
MemoryStream ms = new MemoryStream();
Serializer.Serialize<ProtoScreenBuffer>(ms, ProtoScreenBuffer.CreateProtoScreenBuffer (buffer));
then I get a byte array from the ms object :
ms.ToArray();
and I put this byte array in the ASF. The big problem is on my C++ app which reads the ASF sample just fine, I get a memory access violation when I try to deserialize it :(
this is my C++ code :
m_screenBuffer.ParseFromArray(serBuffer, dwInputDataLen);
(where m_screenBuffer is ProtoScreenBuffer, serBuffer is the raw byte array I got from the ASF file, and dwInputDataLen is the length of it.)
Are any of the things I'm doing here wrong , for what I'm trying to do (serialize in C# .NET and deserialize in C++?)
Thanks alot.
Roey
Upvotes: 2
Views: 2721
Reputation: 1064184
Hmm... the only thing in there that I might expect to be messy is the Guid
(I recently realised that my encoding of this appears to be fairly crazy-endian). So I think that should work fine, give or take some messy code to decipher the Guid
.
To rule out an encoding error, what I would suggest is:
Then:
That should indicate whether it is the encoding, vs something to do with passing the wrong memory address or similar.
Also - check you aren't using GetBuffer()
(or at least, if you do use GetBuffer()
, make sure you use the .Length
from the MemoryStream
, and not from the oversized byte[]
).
Upvotes: 1