Skip to content

fix(generator): emit .msg syntax in _fields_and_field_types for bounded types#262

Open
vik-shah-ai wants to merge 1 commit into
ros2:rollingfrom
vik-shah-ai:fix/fields_and_field_types_msg_syntax
Open

fix(generator): emit .msg syntax in _fields_and_field_types for bounded types#262
vik-shah-ai wants to merge 1 commit into
ros2:rollingfrom
vik-shah-ai:fix/fields_and_field_types_msg_syntax

Conversation

@vik-shah-ai

Copy link
Copy Markdown

Problem

_fields_and_field_types / get_fields_and_field_types() currently emits OMG IDL 4.2 syntax for bounded strings and sequences:

sequence<string<256>, 32>   # bounded sequence of bounded strings
sequence<string<256>>       # unbounded sequence of bounded strings
sequence<string, 10>        # bounded sequence of unbounded strings
sequence<char>              # unbounded sequence of char
string<5>                   # bounded string

The canonical ROS 2 .msg syntax for these is:

string<=256[<=32]
string<=256[]
string[<=10]
char[]
string<=5

This matters because get_fields_and_field_types() is used by tools that build ros2msg-encoded MCAP schemas (e.g. rosbag2-to-MCAP converters, mcap_utils in downstream tooling). The MCAP registry spec requires ros2msg schema data to contain .msg-syntax definitions. Consumers such as Foxglove reject the IDL form and silently fail to decode topics with bounded string arrays.

Changes

  • Remove IDL-style sequence<> prefix/suffix from _fields_and_field_types template.
  • Emit bounded string bound with <= (string<=N) instead of <N>.
  • Emit sequence/array suffixes in .msg syntax: [<=N] (bounded), [] (unbounded), [N] (fixed).
  • Update test_interfaces.py expected values to match.

SLOT_TYPES (which holds rosidl_parser.definition objects) is unchanged and remains the correct API for programmatic type inspection.

Relation to issue #99

Issue #99 proposes deprecating get_fields_and_field_types() in favour of SLOT_TYPES. This fix is complementary: until that deprecation lands and all consumers have migrated, the string API should emit valid .msg syntax rather than leaking IDL internals.

@vik-shah-ai vik-shah-ai changed the base branch from master to rolling June 17, 2026 13:56
…ed types

_fields_and_field_types / get_fields_and_field_types() is documented as a
Python introspection API for message field types. However it was emitting
OMG IDL 4.2 syntax for bounded strings and sequences:

    sequence<string<256>, 32>   (IDL)

instead of the canonical ROS 2 .msg syntax:

    string<=256[<=32]           (.msg)

This breaks any consumer that passes the output directly to the MCAP
ros2msg schema encoder (e.g. mcap_utils _build_ros2_schema()), because
the ros2msg schema encoding requires .msg syntax per the MCAP registry
spec (https://mcap.dev/spec/registry#ros2msg). Foxglove and other
ros2msg-aware tools reject the IDL form.

Changes:
- Remove IDL-style sequence<> prefix/suffix generation in the
  _fields_and_field_types dict template.
- Emit bounded string bound with <= (string<=N) instead of <N>.
- Emit bounded sequence bound as [<=N], unbounded sequence as [],
  fixed-size array as [N] -- all matching .msg syntax.
- Update test_interfaces.py expected values accordingly.

The SLOT_TYPES tuple (rosidl_parser.definition objects) is unchanged
and remains the correct API for programmatic type inspection.

Signed-off-by: Vikrant Shah <vikrant.shah@applied.co>
@vik-shah-ai vik-shah-ai force-pushed the fix/fields_and_field_types_msg_syntax branch from 82f5f9a to a719377 Compare June 17, 2026 13:58
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

Successfully merging this pull request may close these issues.

1 participant