Skip to content

Commit bcd7cc1

Browse files
author
Minggang Wang
committed
Use null-terminated string in the tests when sending a raw topic
Fix #771
1 parent d98c429 commit bcd7cc1

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

lib/node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ class Node extends rclnodejs.ShadowNode {
602602
* @param {boolean} options.enableTypedArray - The topic will use TypedArray if necessary, default: true.
603603
* @param {QoS} options.qos - ROS Middleware "quality of service" settings for the subscription, default: QoS.profileDefault.
604604
* @param {boolean} options.isRaw - The topic is serialized when true, default: false.
605-
* @param {SubscriptionCallback} callback - The callback to be call when receiving the topic subscribed.
605+
* @param {SubscriptionCallback} callback - The callback to be call when receiving the topic subscribed. The topic will be an instance of null-terminated Buffer when options.isRaw is true.
606606
* @return {Subscription} - An instance of Subscription.
607607
* @see {@link SubscriptionCallback}
608608
*/

test/test-raw-pub-sub.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ describe('rclnodejs publisher test suite', function () {
4545
{ isRaw: true },
4646
(msg) => {
4747
clearInterval(timer);
48-
assert.deepStrictEqual(Buffer.compare(msg, topic), 0);
48+
49+
// The received Buffer is null-terminated.
50+
const buffer = Buffer.concat([topic, Buffer.from([0x00])]);
51+
assert.deepStrictEqual(Buffer.compare(msg, buffer), 0);
4952
done();
5053
}
5154
);

types/node.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ declare module 'rclnodejs' {
247247
* @param typeClass - Type of ROS messages the subscription will subscribe to
248248
* @param topic - Name of the topic the subcription will subscribe to.
249249
* @param options - Configuration options, see DEFAULT_OPTIONS
250-
* @param callback - Called when a new message is received.
250+
* @param callback - Called when a new message is received. The serialized message will be null-terminated.
251251
* @returns New instance of Subscription.
252252
*/
253253
createSubscription<T extends TypeClass<MessageTypeClassName>>(

0 commit comments

Comments
 (0)