I'm currently working on code that serializes in one application (C ++) and needs to deserialize it in another (C #). I am trying to use google proto + protobuf-net but something is not working.
Both .cc and .cs message definition files were generated with their respective compilers from the same .proto file.
Data is sent via UDP, and messages (~ 40B) easily fit into a single datagram.
In C ++, the boost: asio size is used to transfer data, the corresponding code is:
ProtocolBufferdata data; ... boost::asio::streambuf b; std::ostream os(&b); data.SerializeToOstream(&os); m_Socket.send_to(b.data(), m_Endpoint);
I am sure that this works correctly, because with the help of wirehark I can at least see all the lines that I expect in a datagram. On the C # side, using Begin / End, we get the following in the callback:
byte[] buffer .... public void ReceiveData(IAsyncResult iar) { try { Socket remote = (Socket)iar.AsyncState; int recv = remote.EndReceive(iar); using (MemoryStream memStream = new MemoryStream()) { memStream.Write(buffer, 0, recv); ProtoData data = ProtoBuf.Serializer.Deserialize<ProtoData >(memStream); onReceive(data); } } catch (Exception ex) { ... } finally { socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveData), socket); } }
The buffer has the expected number of bytes in it and has control lines. The protobuf-net container has all the default values.
I am a little puzzled by what is happening here, and it is almost impossible to connect the debugger to the client application, as it is being deployed as a plug-in for another application that does not work very well with the remote debugger. I would appreciate any advice, it puzzled me.