开发者

protobuf-net - problem with deserializing on C++ side :(

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 BufferT开发者_JAVA百科ype = 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


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:

  • serialize the data via C#, to a file (or just look at the bytes on-screen in the debugger)
  • serialize the /same/ data via C++, to a file (or just look at the bytes on-screen in the debugger)

Then:

  • compare the bytes
  • check the length is what you expect (i.e. the number you are passing over)

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[]).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜