Shared protobuf schemas, gRPC contract and bidirectional ROS message conversion.
ROSAdapter and ROSVis include this directory with add_subdirectory, as before.
Build and test through those application projects; ROSData needs no separate build.
rosdata: protobuf messages, gRPC stubs androsdata::SchemaRegistry. Requires protobuf 3.15+ and gRPC C++; has no ROS dependency and is linked by ROSVis.rosdata_ros:rosdata::Converter, linked by ROSAdapter. Enabled byROSDATA_WITH_ROS; additionally requires rclcpp and rosidl_typesupport_introspection_cpp. C++20 or later.
The checked-in generated/ bundle contains 143 Jazzy message types from
builtin_interfaces, std_msgs, geometry_msgs, sensor_msgs, nav_msgs,
trajectory_msgs, visualization_msgs, diagnostic_msgs, shape_msgs, stereo_msgs,
tf2_msgs, rosgraph_msgs, unique_identifier_msgs and actionlib_msgs, plus transitive
rcl_interfaces dependencies. Deprecated types present in those packages are
included too. Services and actions are not exposed as ROS operations.
Protobuf type names follow robotics.ros.<package>__msg__<Message>; the
rosdata.ros_type message option retains the canonical ROS type name.
The umbrella ros_messages.pb.h includes all bundled package definitions.
ROS primitive integers, booleans, floats, strings, nested messages, fixed arrays,
sequences and bounded sequences are mapped explicitly. Numeric arrays use
repeated; arrays of byte/uint8/char use bytes. Signed int8 arrays remain signed
numeric arrays, preserving values such as OccupancyGrid's -1. Wide strings use
UTF-16LE bytes, preserving all code units. Constants and field defaults are
recorded in descriptor options, along with bounds and original ROS field kinds.
IDL long double is rejected during generation rather than narrowed to double.
Optional singular scalars preserve field presence. On protobuf-to-ROS conversion, absent singular fields retain ROS initialization defaults. Repeated fields are authoritative: fixed arrays must contain their full length, including zero-filled arrays. Integer ranges, sequence bounds, string bounds, nested schema agreement and configurable byte/element/depth limits are checked. Empty ROS messages map to empty protobuf messages.
#include "rosdata/converter.h"
rosdata::SchemaRegistry schemas;
rosdata::Converter converter( "sensor_msgs/msg/PointCloud2", schemas );
google::protobuf::Any protobuf = converter.toProtobuf( serializedRosSample );
rclcpp::SerializedMessage restored = converter.toSerialized( protobuf );The converter loads the installed ROS C++ serialization and introspection libraries for its type, validates the generated schema against runtime metadata, then walks fields recursively. No per-type subscription branches or handwritten converters are needed. Libraries remain loaded for the converter's lifetime. Callers handle conversion exceptions. Limits default to 64 MiB per sample, 16 million elements and nesting depth 64. gRPC endpoints allow 72 MiB envelopes.
adapter.proto defines ListTopics, Subscribe, Unsubscribe, GetLatest,
ListSupportedTypes and GetSchema. LatestData carries a protobuf Any, sequence,
receipt time and conversion error. Before the first sample, payload is absent.
Conversion errors preserve the last valid sample and sequence; a successful
sample clears the error. Unsubscribe clears the cache.
SchemaRegistry lists types, creates messages, unpacks Any payloads and exports or loads FileDescriptorSets. Unknown custom packages can be fetched using GetSchema and decoded through protobuf reflection without ROS on the client. Message instances retain their descriptor state. Conflicting definitions are rejected; clients and servers must agree on schemas for packages already known locally. Schemas are split by package so adding a new custom package does not change the standard package files sent to an older client.
Run from a sourced ROS workspace, through the ROSAdapter build. The generator uses the installed rosidl IDL parser and resolves dependencies through the ament index. Ordinary builds use the checked-in schemas and do not run the generator.
source /opt/ros/jazzy/setup.bash
cmake -S ../ROSAdapter -B ../ROSAdapter/build/local \
-DROSDATA_EXTRA_ROS_PACKAGES="my_robot_msgs;another_msgs"
cmake --build ../ROSAdapter/build/local --target rosdata_generate_schemas
cmake --build ../ROSAdapter/build/local --parallelRebuild ROSVis to include the new definitions locally, or let it retrieve the new package's schema at runtime. ROSAdapter still requires the corresponding ROS serialization and introspection libraries to be installed and discoverable.
Commit the generated .proto files and field_numbers.json together. The
manifest retains field numbers for removed fields, emits reserved names/numbers,
and rejects incompatible field-type changes. Do not delete or regenerate it from
scratch after publishing schemas. Rebuild both applications for this migration:
the former String/Int32 payload field numbers are now reserved.
On Ubuntu/Debian:
sudo apt install libgrpc++-dev protobuf-compiler-grpc libprotobuf-dev protobuf-compiler pkg-configCMake tries the gRPC CMake package, then pkg-config grpc++. For custom installs,
set CMAKE_PREFIX_PATH or gRPC_DIR; grpc_cpp_plugin can be selected using
GRPC_CPP_PLUGIN_EXECUTABLE.
ROSAdapter's CTest suite covers all bundled types through actual ROS serialization, nonzero nested/array/binary values, invalid values, and live ROS-to-gRPC subscription/cache behavior. ROSVis's client-test configuration tests ROS-free decoding, dynamic schemas and descriptor lifetime. See the application READMEs for commands.
Generated interface structures originate from the ROS 2 Jazzy packages listed above. Upstream definitions and licensing are available from the ROS projects: https://github.com/ros2/common_interfaces, https://github.com/ros2/rcl_interfaces, https://github.com/ros2/geometry2 and https://github.com/ros2/unique_identifier_msgs.