2

I have some .proto files used to compile classes from Java, C++ and C#. For Java and C++ I use the Protoc compiler and for the C# I use Protogen. The scripts for the Java/C++ class creation is

@ECHO OFF
SET SRC_DIR=%~dp0

REM Make Java and C++

SET JAVA_OUT_DIR=%SRC_DIR%\..\taurus-messages-java\src\main\java
if not exist %JAVA_OUT_DIR% (
mkdir %JAVA_OUT_DIR%
)

SET CPP_OUT_DIR=%SRC_DIR%\..\taurus-messages-cpp
if not exist %CPP_OUT_DIR% (
mkdir %CPP_OUT_DIR%
)

protoc -I=%SRC_DIR% --java_out=%JAVA_OUT_DIR% --cpp_out=%CPP_OUT_DIR% %SRC_DIR%taurus-mux.proto
protoc -I=%SRC_DIR% --java_out=%JAVA_OUT_DIR% --cpp_out=%CPP_OUT_DIR% %SRC_DIR%taurus-backtest.proto

and for the C# class generation I have

@ECHO OFF
SET WORK_DIR=%~dp0
SET OUT_DIR=%WORK_DIR%\Messages
SET SRC_DIR=%WORK_DIR%\..\..\..\Taurus\trunk\taurus-messages-proto\

if not exist %OUT_DIR% (
mkdir %OUT_DIR%
)

cd %SRC_DIR%

protogen -p:detectMissing -i:taurus-backtest.proto -o:%OUT_DIR%\TaurusBacktest.cs
protogen -p:detectMissing -i:taurus-mux.proto -o:%OUT_DIR%\TaurusMux.cs

cd %WORK_DIR%

both script reference the .proto files (of course ;]). I the above C# script I have added -p:detectMissing in order to generate properties that allow me to test whether or not a field is specified; the option creates *Specified for all fields where IsRequired = false.

My question is simple, I want to make sure the C#, C++ and Java classes remain aligned, but for C# I need to use -p:detectMissing option with Protogen, what is the equivalent option using Protoc?

Thanks for your time.

MoonKnight
  • 23,214
  • 40
  • 145
  • 277

1 Answers1

1

If I have understood the question correctly, then there isn't really an "equivalent" option - they are different tools with different intended uses. If your main driver is like-for-like usage you might want to look at protobuf-csharp-port, which retains a very similar usage while moving to C#. By contrast, protobuf-net makes no attempt to present the same API as google - it acts as an idiomatic .NET serializer that happens to talk in the protobuf format.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Right, I think that is my problem. The Java classes and C++ classes are obviously both being generated by Protoc, so I can get my Java and C++ codes to pass serialized version of the "same" class types and this works. But when I am attempting to do this with the C# classes generated by Protogen, the expected C++ object is corrupt (because the classes are not the same - as you have pointed out). Based on the this clarification, do you still think protobuf-csharp-port can help me pass my serialized classes from C# to C++? – MoonKnight Mar 16 '15 at 16:25
  • If not, how else can I achieve this? Ps. I have read http://stackoverflow.com/questions/2522376/how-to-choose-between-protobuf-csharp-port-and-protobuf-net. Thanks very much for your time... – MoonKnight Mar 16 '15 at 16:26
  • 1
    How can you achieve *what* exactly? What *precisely* is it that you want to have happen differently? – Marc Gravell Mar 16 '15 at 16:52
  • I would like to know how exactly I can get my C++ code using the protoc generated files to talk with my C# code using protogen generated files? I understand what you are saying about your own protobuf-net library, so I have A. Download protobuf-2.6.0.tar from https://developers.google.com/protocol-buffers/docs/downloads and extract the contents to C:\Program Files. B. Built following the instructions in C:\Program Files\protobuf-2.6.0\vsprojects\readme.txt, so not I have a protobuf-net.dll which I assume will contain the correct serializer, but this serialization too fails... – MoonKnight Mar 16 '15 at 17:03
  • with `[libprotobuff ERROR ..\\message_lite.cc:123] Can't parse message of type "Taurus.FeedMux" because it is missing required fields: type`. This is the first time I have worked with such protocol-buffers and would like to know A. How to use the same .proto files I use to generate my Java and C++ classes to generate my C# classes (I think I am doing this right using Protogen)? B. What serializer to use to get the serialized messages (serialized using some correct C# library), to be consumed and deserialized correctly by my C++ code? – MoonKnight Mar 16 '15 at 17:06
  • "Talk to" is a very wooly description. We don't know what's going wrong at the moment - or what yo're trying. "this serialization too fails" is a very unclear description of the problem you're facing. Ideally, show a short but complete pair of programs (e.g. one in C++ and one in C#) where one program serializes some data and the other deserializes it. – Jon Skeet Mar 16 '15 at 17:07
  • Hi @JonSkeet, thanks very much for taking a look. I appreciate my description is "wooly", apologies. I have asked this question previously (which Marc shed some light on http://stackoverflow.com/questions/29076447/cross-platform-protobuf-serialization). The "Talk To" is referring to communication via ZeroMQ. I can send information between Java and C++ applications (both Java and C++ protobuf classes being generated by protoc) via ZeroMQ. and I can send a message from my C# to C++, but the `byte[]` sent is not being deserialized correctly... – MoonKnight Mar 16 '15 at 17:20
  • I suggest you take ZeroMQ out of the equation to start with. Write to a file in one process, read from a file in the other process. Get that working first. – Jon Skeet Mar 16 '15 at 17:21
  • I believe (following Marcs very helpful suggestion) that this is down to the way I am auto generating my classes - they don't match across platforms. It is very difficult to get some code snippets that show the problem dues to the number of reference libraries. I will take a look at doing this now. – MoonKnight Mar 16 '15 at 17:22