sequenceplanner/r2r

Improve generated types for constants in ros messages.

Opened this issue · 0 comments

m-dahl commented

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