Protogen Vs. Protoc Compiler Options

有些话、适合烂在心里 提交于 2020-01-11 10:57:06

问题


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.


回答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.



来源:https://stackoverflow.com/questions/29081021/protogen-vs-protoc-compiler-options

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!