Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve generated types for constants in ros messages. #47

Open
m-dahl opened this issue May 21, 2023 · 0 comments
Open

Improve generated types for constants in ros messages. #47

m-dahl opened this issue May 21, 2023 · 0 comments

Comments

@m-dahl
Copy link
Collaborator

m-dahl commented May 21, 2023

As discussed in #45, constants are currently generated like this:

#[allow(non_upper_case_globals)]
impl MyCustomMsg {
    pub const MY_CONSTANT_ONE: _bindgen_ty_139 = my_custom_package__msg__MyCustomMsg__MY_CONSTANT_ONE;
}

Instead of the actual type defined in the msg/idl file, we get a bindgen generated type. This is because constants are defined like this in the generated c header files:

enum
{
  my_custom_package__msg__MyCustomMsg__MY_CONSTANT_ONE = 1
};

If we knew the constant was a i8, we could generate the code like this instead:

#[allow(non_upper_case_globals)]
impl MyCustomMsg {
    pub const MY_CONSTANT_ONE: i8 = my_custom_package__msg__MyCustomMsg__MY_CONSTANT_ONE as i8;
}

But since we currently do not read the msg files, I am not sure how to get the actual type of the constant. It could be that we need to start reading the msg files, but that would lead to a large rewrite of the msg generation code. Maybe a fun project for the future...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant