Nanopb带套件选项在导入时引起错误

发布于 2025-02-05 11:49:39 字数 1100 浏览 3 评论 0原文

我正在与nanopb挣扎,以获取具有* mangle_names的另一个软件包的枚举:m_strip_package in .options file。这是一种轻松地重现问题的方法:

我有一个包含folder_a和folder_b的root_folder。 在folder_a中,我有file_a.proto和file_a.options:

file_a.proto:

syntax = "proto2";

package folder_A;

enum my_enum {
    ENUM_0 = 0;
    ENUM_1 = 1;
    ENUM_2 = 2;
}

file_a.options:

* mangle_names:M_STRIP_PACKAGE

在folder_b中,我有file_b.proto:

syntax = "proto2";

package folder_B;

import "folder_A/file_A.proto";

message dummy  {
    required folder_A.my_enum value  = 1;
}

我尝试使用以下命令生成proto file:

nanopb_generator.py -d -d。 -我 。 -i。\ folder_b \。\ folder_a \file_a.proto。\ folder_b \ file_b.proto

crippt失败,错误excection:无法找到enum type folder_a_my_enum在生成folder_b_dummy code的默认值时, >

但是,如果我删除file_a.options,则可以正常工作。 另外,如果我通过消息替换枚举,即使使用file_a.options可以正常工作。

我的问题是:您是否知道是否可以使用选项* mangle_names:m_strip_package和同时导入枚举?

我使用nanopb-0.4.4。

谢谢 !

I am struggling with nanopb to get the enum of another package which has * mangle_names:M_STRIP_PACKAGE in .options file. Here is a way to reproduce the problem easily :

I have a root_folder containing folder_A and folder_B.
In folder_A, I have file_A.proto and file_A.options :

file_A.proto:

syntax = "proto2";

package folder_A;

enum my_enum {
    ENUM_0 = 0;
    ENUM_1 = 1;
    ENUM_2 = 2;
}

file_A.options:

* mangle_names:M_STRIP_PACKAGE

In folder_B, I have file_B.proto :

syntax = "proto2";

package folder_B;

import "folder_A/file_A.proto";

message dummy  {
    required folder_A.my_enum value  = 1;
}

I try to generate proto file with the following command:

nanopb_generator.py -D . -I . -I .\folder_B\ .\folder_A\file_A.proto .\folder_B\file_B.proto

The script fails with error Exception: Could not find enum type folder_A_my_enum while generating default values for folder_B_dummy.

But if I remove the file_A.options, it works correctly.
Also if I replace the enum by a message, it works correctly even with file_A.options.

My question is : do you know if it is possible to use the option * mangle_names:M_STRIP_PACKAGE and import enum at the same time ?

I use nanopb-0.4.5.

Thank you !

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

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

发布评论

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

评论(1

花想c 2025-02-12 11:49:39

当前M_STRIP_PACKAGE从另一个软件包导入时不起作用。我已经在问题跟踪器中添加了问题: https://github.com/nanapb/nanopb/问题/783

只要所有导入的文件都属于同一软件包并且具有相同的名称杂交设置,否则用名称杂交的导入似乎可以正常工作。

当您使用多个软件包名称时,从类型中剥离包名称是一个好主意,这也值得怀疑。这听起来像是名称碰撞的食谱。

Currently M_STRIP_PACKAGE does not work when there are imports from another package. I have added the problem to the issue tracker: https://github.com/nanopb/nanopb/issues/783

Imports with name mangling seem to work fine, as long as all imported files belong to the same package and have same name mangling settings.

It is also questionable whether stripping the package name from types is a good idea when you are using multiple package names. It sounds like a recipe for name collisions.

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