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. My problem is that the C# file requires an import and some options set (protobuf-csharp-port) while the C++ file doesn't.

Is there any way I can tell protoc to ignore imports/options under certain circumstances?

Currently my only way around this is to create two different .proto files, and update both when changes are made.


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

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#的原始文件需要导入和导入你的原始文件?

链接地址: http://www.djcxy.com/p/64782.html

上一篇: 关于iPhone上的ProtocolBuffers

下一篇: 对于C#和C ++项目使用相同的.proto文件