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

发布于 2024-09-09 01:44:50 字数 206 浏览 1 评论 0原文

我尝试对 C# 和 C++ 项目使用相同的 .proto 文件 (protobuf)。我的问题是 C# 文件需要导入并设置一些选项 (protobuf-csharp-port),而 C++ 文件不需要。

有什么方法可以告诉 protoc 在某些情况下忽略导入/选项吗?

目前,我解决此问题的唯一方法是创建两个不同的 .proto 文件,并在进行更改时更新这两个文件。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

待天淡蓝洁白时 2024-09-16 01:44:50

啊,这个栗子:(

是的,这很痛苦。不,我现在没有一个很好的方法来解决它。我想要一种说法,“这个导入的文件仅用于扩展选项,而那些可以假设扩展是可用的:包括描述符集中的值,但不要尝试解析扩展。”不幸的是,没有办法做到这一点。

可以做的只是包括当你构建 C++ 版本时,你会得到 C# 选项的 C# 选项,这并不漂亮,但实际上不会造成任何损害,我实际上没有在 C++ 中这样做过,但我。之前正是出于这个原因,我最终生成了 C# 选项的 Java 文件。

如果您对我如何更改 C# 端口以改进这一点有任何其他建议,我有兴趣听听它们...

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

叹沉浮 2024-09-16 01:44:50

您是否可以只拥有不导入的原型文件,然后拥有需要导入的 C# 原型文件并导入原始​​文件?

Could you just have your proto files without import then proto files for C# that have required imports and import your original files?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文