Serialization of interblock protobuff

I have three applications that interact through ZeroMQ, performing various operations. Various applications:

  • The first is a C ++ application, which is an engine for "hard work", it receives a Protobuf message as a request from a client, does some work and returns a Protobuf message back to this client (or to the one who is connected, a request / response template). This uses 0MQ version 4.0.4 and uses protobuf-2.6.0, where we ourselves created the necessary header files, the Protobuf classes were created by the duct.

  • Secondly, I have Java code and a data provider, it uses jeromq-0.3.4.jar to exchange ZeroMQ messages and protobuf-java-2.6.1.jar to serialize Protobuf, etc.

  • Thirdly, I have C # code that does some analysis and has a nice interface, etc. This uses Marc Gravell protobuf-net ( https://www.nuget.org/packages/protobuf-net/ ) as a NuGet package and NetMQ (native C # port of ZeroMQ) for messaging.

Now C ++ โ†” Java works fine and without problems, however C ++ โ†” C # does not work correctly. When I send a basic request from C # to a C ++ โ€œserverโ€ via

using (NetMQContext context = NetMQContext.Create()) using (var requestSocket = context.CreateRequestSocket()) { requestSocket.Connect(_requestAddress); // "tcp://127.0.0.1:6500" requestSocket.Send(mux.ToByteArray<Taurus.FeedMux>()); } 

from

 public static byte[] ToByteArray<T>(this T o) where T : ProtoBuf.IExtensible { if (o == null) return null; using (MemoryStream ms = new MemoryStream()) { ProtoBuf.Serializer.Serialize(ms, o); return ms.ToArray(); } } 

C ++ code receives a message, but despite setting the required

 Taurus.FeedMux mux = new Taurus.FeedMux(); mux.type = Taurus.FeedMux.Type.OXX; mux.oxx = Oxx.GetOxx(); 

I get an error in a C ++ application

[libprotobuff ERROR .. \\ message_lite.cc:123] Unable to parse a message of type Taurus.FeedMux because it lacks required fields: type

But I clearly set type and in C ++ code the type seems set (using a debugger to check for a deserialized object). I tried two different Protobuf libraries (one I built and the Mark Gravell library through NuGet), as I thought it was a serialization problem, but it did not fix this problem.

I also tried the clrZMQ wrapper library, as well as my own NetMQ library in C #, again this does not help, the message was received using any combination above, but the received one seems incorrect.

What could be wrong here and is there anything I should do that I haven't mentioned?

+2
c # serialization protocol-buffers zeromq protobuf-net
Mar 16 '15 at 12:08
source share
1 answer

I assume that type treated as optional , where, as in C ++, it is marked as required . I donโ€™t see how your model is defined in C #, but if you use the protobuf-net attributes, you can make it serialize through the IsRequired attribute IsRequired :

 [ProtoMember(42, IsRequired = true)] // change the number! public Taurus.FeedMux.Type type {get;set;} 
+1
Mar 16 '15 at 12:25
source share



All Articles