Skip to content

Add rosidl_buffer and rosidl_buffer_backend for native Buffer type support#941

Open
nvcyc wants to merge 4 commits intorollingfrom
native_buffer/1-rosidl_buffer
Open

Add rosidl_buffer and rosidl_buffer_backend for native Buffer type support#941
nvcyc wants to merge 4 commits intorollingfrom
native_buffer/1-rosidl_buffer

Conversation

@nvcyc
Copy link

@nvcyc nvcyc commented Mar 13, 2026

Description

This pull request adds rosidl_buffer and rosidl_buffer_backend packages - core C++ buffer types for the ROS 2 native buffer feature. This package introduces rosidl::Buffer<T>, a polymorphic container that's designed to replace std::vector<T> for uint8[] message fields (to be adopted in later pull requests; we focus on only the core buffer types in this pull request.) The native buffer type and its backend class enable vendor-specific memory buffer implementation (CUDA, ROCm, etc.) while maintaining backward compatibility for existing CPU-based std::vector<T> user code.

This pull request consists of the following key components:

  • Buffer<T>: PIMPL-based container providing std::vector<T>-compatible API. All vector-compatible operations (element access, iterators, modifiers) are CPU-only and throw std::runtime_error for non-CPU backends. Backend management APIs (get_backend_type(), get_impl(), to_vector()) work for all backends.
  • BufferImplBase<T>: Minimal abstract base class of buffer implementation. All backend-specific APIs are to be provided by the vendor-specific backend implementations.
  • CpuBufferImpl<T>: CPU-based buffer implementation wrapping std::vector<T>.
  • BufferBackend: Abstract interface for vendor-specific buffer backend implementations.

Is this user-facing behavior change?

This pull request does not change existing behavior.
When adopted in later pull requests, message types with uint8[] fields (e.g., sensor_msgs/msg/Image.data) will use rosidl::Buffer<uint8_t> instead of std::vector<uint8_t>. For CPU backends (the default), Buffer<T> is a transparent drop-in replacement.

Did you use Generative AI?

Yes. Claude (claude-4.6-opus) via Cursor was used to assist with the std::vector<T> compatibility feature in the rosidl::Buffer<T> class and generate portions of the unit tests.

Additional Information

This package/PL is part of the broader ROS2 native buffer feature introduced in this post.

@nvcyc nvcyc force-pushed the native_buffer/1-rosidl_buffer branch 3 times, most recently from cee2760 to ea59c56 Compare March 14, 2026 20:16
Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work @nvcyc!

Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct.

@nvcyc nvcyc requested a review from MiguelCompany March 22, 2026 17:47
nvcyc added 4 commits March 22, 2026 17:55
…pport

Signed-off-by: CY Chen <cyc@nvidia.com>
Signed-off-by: CY Chen <cyc@nvidia.com>
Signed-off-by: CY Chen <cyc@nvidia.com>
Signed-off-by: CY Chen <cyc@nvidia.com>
@nvcyc nvcyc force-pushed the native_buffer/1-rosidl_buffer branch from 326b4f8 to c53b788 Compare March 22, 2026 17:55
Copy link
Contributor

@MiguelCompany MiguelCompany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

3 participants