简体   繁体   English

对C#和C ++项目使用相同的.proto文件

[英]Using the same .proto file for both a C# and C++ project

I am attempting to use the same .proto file (protobuf) for a C# and a C++ project. 我试图将相同的.proto文件(protobuf)用于C#和C ++项目。 My problem is that the C# file requires an import and some options set (protobuf-csharp-port) while the C++ file doesn't. 我的问题是C#文件需要导入和一些选项设置(protobuf-csharp-port),而C ++文件则不需要。

Is there any way I can tell protoc to ignore imports/options under certain circumstances? 在某些情况下,我有什么方法可以告诉protoc忽略进口/期权?

Currently my only way around this is to create two different .proto files, and update both when changes are made. 目前我唯一的办法就是创建两个不同的.proto文件,并在进行更改时更新这两个文件。

Ah, this chestnut :( 啊,这个栗子:(

Yes, it's a pain. 是的,这很痛苦。 No, I don't have a really nice way round it at the moment. 不,我现在没有一个非常好的方式围绕它。 I'd like a way of saying, "This imported file is only for extension options, and those extensions can be assumed to be available: include the values in the descriptor set, but don't try to resolve the extensions." 我想说一句,“这个导入的文件仅用于扩展选项,并且可以假定这些扩展可用:包含描述符集中的值,但不要尝试解析扩展。” Unfortunately there's no way of doing that. 不幸的是,没有办法做到这一点。

What you can do is just include the C# options when you build the C++ version, and you'll end up with a C++ representation of your C# options. 可以做的只是在构建C ++版本时包含C#选项,并且最终会得到C#选项的C ++表示。 It's not pretty, but it won't actually do any harm. 它不漂亮,但它实际上不会造成任何伤害。 I've not actually done this in C++, but I've ended up generating the Java files for the C# options for exactly this reason before now. 我实际上并没有在C ++中完成这个任务,但我之前就已经为C#选项生成了Java文件。

If you have any other suggestions for how I could change the C# port to improve this, I'd be interested in hearing them... 如果您对如何更改C#端口有任何其他建议以改进这一点,我会有兴趣听到它们...

你能不能导入你的proto文件然后导入C#的proto文件,这些文件需要导入并导入原始​​文件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM