问题描述
我已经习惯了从Java,C ++和C#编译类中的某些.proto文件。对于Java和C ++我用Protoc编译器和为C#我用硫辛酸。为Java / C ++类创建的脚本是
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
和为C#类代我有
@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%
这两个脚本引用.proto文件(当然])。我上面的C#脚本,我已经加入 -p:detectMissing
,以产生让我来测试场是否指定的属性;该选项创建 *指定
为其中 IsRequired = FALSE所有领域
。
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
.
我的问题很简单,我想,以确保C#,C ++和Java类保持一致,但对于C#我需要使用 -p :用硫辛酸detectMissing
选项,什么是使用Protoc等价期权?
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?
感谢您的时间。
推荐答案
如果我理解了正确的问题,那么就没有一个真正的等价的选项 - 它们是具有不同的预期用途,不同的工具。如果你的主要驱动力是像对等的使用情况,您可能想看看的protobuf-CSHARP端口,同时移动到C#它保留了非常类似的用法。相比之下,protobuf网没有试图呈现相同的API谷歌 - 它充当发生在protobuf的格式说话的习惯.NET串行
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.
这篇关于硫辛酸比。 Protoc编译器选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!