Question

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.

Was it helpful?

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.

OTHER TIPS

As Jon Skeet said, I would think SerializeAsString will return the protocol buffer in it's text representation (see https://developers.google.com/protocol-buffers/docs/overview) i.e.

# Textual representation of a protocol buffer.
# This is *not* the binary format used on the wire.
person {
  name: "John Doe"
  email: "jdoe@example.com"
}

A simple write of the string will determine if this is correct. This format has no relation to the binary format so can not be deserialised you ar try to do.

The options (in best to worst order) are * Serialise to byte Array and send / retrieve as bytes * Serialise to byte Array and encode / decode byte Array as Base64 * Encode as String like you are doing and use the String-Deserialise.

I do not use C or C# so can not advise on the Code to use

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top