Expose MessageInfo metadata on subscription callbacks#1440
Merged
minggangw merged 3 commits intoRobotWebTools:developfrom Mar 17, 2026
Merged
Expose MessageInfo metadata on subscription callbacks#1440minggangw merged 3 commits intoRobotWebTools:developfrom
minggangw merged 3 commits intoRobotWebTools:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for delivering subscription message metadata (“MessageInfo”) to user callbacks when the callback declares two parameters, aligning rclnodejs behavior with similar ROS client APIs.
Changes:
- Introduces a new
MessageInfoJS/TS API and exports it from the main module. - Adds a native
rclTakeWithInfobinding to retrievermw_message_info_talongside a taken message. - Updates subscription callback typings and adds tests validating metadata delivery for 2-arg callbacks.
Reviewed changes
Copilot reviewed 6 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| types/subscription.d.ts | Expands subscription callback types to optionally accept MessageInfo. |
| types/message_info.d.ts | Adds TypeScript declarations for the new MessageInfo API. |
| types/index.d.ts | References the new message_info.d.ts so it’s included in published typings. |
| src/rcl_subscription_bindings.cpp | Adds rclTakeWithInfo native binding returning message metadata. |
| lib/message_info.js | Adds JS MessageInfo wrapper and toPlainObject(). |
| lib/subscription.js | Detects whether callback wants metadata via callback.length and forwards metadata when present. |
| lib/node.js | Uses rclTakeWithInfo when metadata is requested and passes MessageInfo into subscription callbacks. |
| index.js | Exports MessageInfo on the public rclnodejs module. |
| test/test-message-info.js | Adds tests for presence/absence of metadata based on callback arity and basic field expectations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lib/node.js
Outdated
Comment on lines
+265
to
+271
| if (subscription.wantsMessageInfo) { | ||
| // Re-take with info for raw subscriptions that want metadata | ||
| // Note: raw take doesn't support info, pass null | ||
| subscription.processResponse(rawMessage, null); | ||
| } else { | ||
| subscription.processResponse(rawMessage); | ||
| } |
lib/node.js
Outdated
Comment on lines
+266
to
+267
| // Re-take with info for raw subscriptions that want metadata | ||
| // Note: raw take doesn't support info, pass null |
This was referenced Mar 18, 2026
minggangw
added a commit
that referenced
this pull request
Mar 18, 2026
Exposes ROS 2 message metadata (timestamps, sequence numbers, publisher GID) to subscription callbacks, matching rclpy's `MessageInfo` pattern. When a subscription callback declares two parameters, it automatically receives a `MessageInfo` object as the second argument containing metadata from the middleware layer. Single-parameter callbacks are unchanged — no performance overhead, full backward compatibility. **New files:** - `lib/message_info.js` — `MessageInfo` class wrapping native `rmw_message_info_t` fields: `sourceTimestamp` (bigint), `receivedTimestamp` (bigint), `publicationSequenceNumber` (bigint), `receptionSequenceNumber` (bigint), `publisherGid` (Buffer). Includes `toPlainObject()` helper. - `types/message_info.d.ts` — Full TypeScript declarations for `MessageInfo`. - `test/test-message-info.js` — 6 tests covering: MessageInfo delivery with 2-param callbacks, non-delivery with 1-param callbacks, timestamp validity, timestamp ordering, `toPlainObject()`, and export verification. **Modified files:** - `src/rcl_subscription_bindings.cpp` — Added `RclTakeWithInfo()` native function that calls `rcl_take()` with `rmw_message_info_t` (instead of `nullptr`) and returns a JS object with all metadata fields as BigInts and a GID Buffer. Registered as `rclTakeWithInfo` binding. Added `#include <rmw/types.h>`. - `lib/subscription.js` — Added `_wantsMessageInfo` flag detected via `callback.length >= 2`. Added `wantsMessageInfo` readonly getter. Updated `processResponse()` to accept optional `messageInfo` second parameter and forward it to the callback when the flag is set. - `lib/node.js` — Updated subscription spin loop: when `subscription.wantsMessageInfo` is true, uses `rclTakeWithInfo` and wraps the result in `MessageInfo`; otherwise uses the existing `rclTake` path (zero overhead for 1-param callbacks). Added `MessageInfo` require. - `index.js` — Exported `MessageInfo` class. - `types/index.d.ts` — Added `/// <reference>` for `message_info.d.ts`. - `types/subscription.d.ts` — Updated `SubscriptionCallback` and `SubscriptionWithRawMessageCallback` type aliases to accept optional second `MessageInfo` parameter via union types. Fix: #1439
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Exposes ROS 2 message metadata (timestamps, sequence numbers, publisher GID) to subscription callbacks, matching rclpy's
MessageInfopattern. When a subscription callback declares two parameters, it automatically receives aMessageInfoobject as the second argument containing metadata from the middleware layer. Single-parameter callbacks are unchanged — no performance overhead, full backward compatibility.New files:
lib/message_info.js—MessageInfoclass wrapping nativermw_message_info_tfields:sourceTimestamp(bigint),receivedTimestamp(bigint),publicationSequenceNumber(bigint),receptionSequenceNumber(bigint),publisherGid(Buffer). IncludestoPlainObject()helper.types/message_info.d.ts— Full TypeScript declarations forMessageInfo.test/test-message-info.js— 6 tests covering: MessageInfo delivery with 2-param callbacks, non-delivery with 1-param callbacks, timestamp validity, timestamp ordering,toPlainObject(), and export verification.Modified files:
src/rcl_subscription_bindings.cpp— AddedRclTakeWithInfo()native function that callsrcl_take()withrmw_message_info_t(instead ofnullptr) and returns a JS object with all metadata fields as BigInts and a GID Buffer. Registered asrclTakeWithInfobinding. Added#include <rmw/types.h>.lib/subscription.js— Added_wantsMessageInfoflag detected viacallback.length >= 2. AddedwantsMessageInforeadonly getter. UpdatedprocessResponse()to accept optionalmessageInfosecond parameter and forward it to the callback when the flag is set.lib/node.js— Updated subscription spin loop: whensubscription.wantsMessageInfois true, usesrclTakeWithInfoand wraps the result inMessageInfo; otherwise uses the existingrclTakepath (zero overhead for 1-param callbacks). AddedMessageInforequire.index.js— ExportedMessageInfoclass.types/index.d.ts— Added/// <reference>formessage_info.d.ts.types/subscription.d.ts— UpdatedSubscriptionCallbackandSubscriptionWithRawMessageCallbacktype aliases to accept optional secondMessageInfoparameter via union types.Fix: #1439