Search code examples
c#c++protocol-buffersprotobuf-netqpid

Issue with transferring a double property from C++ To C# with Google Protocol Buffer and Protobuf-C#


I am attempting to send an object as a serialized string from C++ to C# over QPID which is a messaging system. I currently have a Google proto file as such:

package Serializable;

message Order_ser 
{
    optional  int32 openord = 1 [default = 0];
    optional  int32 oldord = 2 [default = 0]; 
    optional  double price = 3 [default = 0];
}

I get the error at C# end when transferring the object through C++

Protocol message tag had invalid wire type.

This only happens if i assign a value to a double type such as price.


Solution

  • Despite the name, I don't believe that SerializeAsString really converts it into text - so you shouldn't be treating it as text at the C# side. I strongly suspect that it's the interpretation of the binary data as UTF-8-encoded text which is going wrong.

    I know nothing of QPID, but assuming you can transfer arbitrary binary messages that way, that's what you should do. If you can't transfer arbitrary binary messages over QPID, then Protocol Buffers may well not be an appropriate solution for you - they're really designed as an efficient binary representation. You could base64-encode the data of course, but you may well find there are more appropriate approaches.