Skip to content

Commit e6d7df4

Browse files
Resolve discussions
1 parent 6c439a7 commit e6d7df4

File tree

8 files changed

+29
-29
lines changed

8 files changed

+29
-29
lines changed

example/topics/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ The `subscriber/` directory contains examples of nodes that subscribe to topics:
152152

153153
- **Message Type**: `sensor_msgs/msg/LaserScan`
154154
- **Topic**: `scan`
155-
- **Functionality**: Shows how 'typed', 'plain', and 'json' modes affect message serialization
155+
- **Functionality**: Shows how 'default', 'plain', and 'json' modes affect message serialization
156156
- **Features**: Message serialization control for web applications and JSON compatibility
157157
- **Run Command**: `node subscriber/subscription-serialization-modes-example.js`
158158

example/topics/subscriber/subscription-json-utilities-example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024 rclnodejs contributors. All rights reserved.
1+
// Copyright (c) 2025 Mahmoud Alghalayini. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

example/topics/subscriber/subscription-serialization-modes-example.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024 rclnodejs contributors. All rights reserved.
1+
// Copyright (c) 2025 Mahmoud Alghalayini. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -19,19 +19,19 @@ const rclnodejs = require('../../../index.js');
1919
/**
2020
* This example demonstrates the use of serialization modes for subscriptions.
2121
* Serialization modes allow you to control how TypedArrays are handled in messages:
22-
* - 'typed' (default): Keep TypedArrays for performance
22+
* - 'default': Use native rclnodejs behavior (respects enableTypedArray setting)
2323
* - 'plain': Convert TypedArrays to regular arrays
2424
* - 'json': Fully JSON-safe (converts TypedArrays, BigInt, Infinity, etc.)
2525
*/
2626
async function main() {
2727
await rclnodejs.init();
2828
const node = new rclnodejs.Node('serialization_modes_example_node');
2929

30-
// Default mode: 'typed' - keeps TypedArrays
30+
// Default mode: 'default' - uses native rclnodejs behavior
3131
node.createSubscription(
3232
'sensor_msgs/msg/LaserScan',
3333
'/laser_scan',
34-
{ serializationMode: 'typed' },
34+
{ serializationMode: 'default' },
3535
(msg) => {
3636
console.log(
3737
`[TYPED] ranges: ${msg.ranges ? msg.ranges.constructor.name : 'undefined'}`

lib/message_serialization.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024 rclnodejs contributors. All rights reserved.
1+
// Copyright (c) 2025 Mahmoud Alghalayini. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -127,13 +127,13 @@ function toJSONString(obj, space) {
127127
/**
128128
* Apply serialization mode conversion to a message object
129129
* @param {*} message - The message object to convert
130-
* @param {string} serializationMode - The serialization mode ('typed', 'plain', 'json')
130+
* @param {string} serializationMode - The serialization mode ('default', 'plain', 'json')
131131
* @returns {*} The converted message
132132
*/
133133
function applySerializationMode(message, serializationMode) {
134134
switch (serializationMode) {
135-
case 'typed':
136-
// No conversion needed - keep TypedArrays
135+
case 'default':
136+
// No conversion needed - use native rclnodejs behavior
137137
return message;
138138

139139
case 'plain':
@@ -146,7 +146,7 @@ function applySerializationMode(message, serializationMode) {
146146

147147
default:
148148
throw new TypeError(
149-
`Invalid serializationMode: ${serializationMode}. Valid modes are: 'typed', 'plain', 'json'`
149+
`Invalid serializationMode: ${serializationMode}. Valid modes are: 'default', 'plain', 'json'`
150150
);
151151
}
152152
}
@@ -157,7 +157,7 @@ function applySerializationMode(message, serializationMode) {
157157
* @returns {boolean} True if valid
158158
*/
159159
function isValidSerializationMode(mode) {
160-
return ['typed', 'plain', 'json'].includes(mode);
160+
return ['default', 'plain', 'json'].includes(mode);
161161
}
162162

163163
module.exports = {

lib/node.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,10 @@ class Node extends rclnodejs.ShadowNode {
534534
}
535535

536536
if (options.serializationMode === undefined) {
537-
options = Object.assign(options, { serializationMode: 'typed' });
537+
options = Object.assign(options, { serializationMode: 'default' });
538538
} else if (!isValidSerializationMode(options.serializationMode)) {
539539
throw new TypeError(
540-
`Invalid serializationMode: ${options.serializationMode}. Valid modes are: 'typed', 'plain', 'json'`
540+
`Invalid serializationMode: ${options.serializationMode}. Valid modes are: 'default', 'plain', 'json'`
541541
);
542542
}
543543

@@ -675,8 +675,8 @@ class Node extends rclnodejs.ShadowNode {
675675
* @param {boolean} options.enableTypedArray - The topic will use TypedArray if necessary, default: true.
676676
* @param {QoS} options.qos - ROS Middleware "quality of service" settings for the subscription, default: QoS.profileDefault.
677677
* @param {boolean} options.isRaw - The topic is serialized when true, default: false.
678-
* @param {string} [options.serializationMode='typed'] - Controls message serialization format:
679-
* 'typed' (default): Keep TypedArrays for performance,
678+
* @param {string} [options.serializationMode='default'] - Controls message serialization format:
679+
* 'default': Use native rclnodejs behavior (respects enableTypedArray setting),
680680
* 'plain': Convert TypedArrays to regular arrays,
681681
* 'json': Fully JSON-safe (handles TypedArrays, BigInt, etc.).
682682
* @param {object} [options.contentFilter=undefined] - The content-filter, default: undefined.
@@ -1933,7 +1933,7 @@ class Node extends rclnodejs.ShadowNode {
19331933
* isRaw: false,
19341934
* qos: QoS.profileDefault,
19351935
* contentFilter: undefined,
1936-
* serializationMode: 'typed',
1936+
* serializationMode: 'default',
19371937
* }
19381938
*/
19391939
Node.getDefaultOptions = function () {
@@ -1942,7 +1942,7 @@ Node.getDefaultOptions = function () {
19421942
isRaw: false,
19431943
qos: QoS.profileDefault,
19441944
contentFilter: undefined,
1945-
serializationMode: 'typed',
1945+
serializationMode: 'default',
19461946
};
19471947
};
19481948

lib/subscription.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Subscription extends Entity {
4343
this._topic = topic;
4444
this._callback = callback;
4545
this._isRaw = options.isRaw || false;
46-
this._serializationMode = options.serializationMode || 'typed';
46+
this._serializationMode = options.serializationMode || 'default';
4747
this._node = node;
4848

4949
if (node && eventCallbacks) {
@@ -59,7 +59,7 @@ class Subscription extends Entity {
5959
} else {
6060
let message = msg.toPlainObject(this.typedArrayEnabled);
6161

62-
if (this._serializationMode !== 'typed') {
62+
if (this._serializationMode !== 'default') {
6363
message = applySerializationMode(message, this._serializationMode);
6464
}
6565

test/test-serialization-modes.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024 rclnodejs contributors. All rights reserved.
1+
// Copyright (c) 2025 Mahmoud Alghalayini. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -88,7 +88,7 @@ describe('Serialization Modes Tests', function () {
8888

8989
it('Test serializationMode option validation', function () {
9090
assert.doesNotThrow(() => {
91-
node._validateOptions({ serializationMode: 'typed' });
91+
node._validateOptions({ serializationMode: 'default' });
9292
node._validateOptions({ serializationMode: 'plain' });
9393
node._validateOptions({ serializationMode: 'json' });
9494
});
@@ -105,7 +105,7 @@ describe('Serialization Modes Tests', function () {
105105
typedSubscription = node.createSubscription(
106106
'std_msgs/msg/String',
107107
'/test_topic_typed',
108-
{ serializationMode: 'typed' },
108+
{ serializationMode: 'default' },
109109
() => {}
110110
);
111111

@@ -123,7 +123,7 @@ describe('Serialization Modes Tests', function () {
123123
() => {}
124124
);
125125

126-
assert.strictEqual(typedSubscription.serializationMode, 'typed');
126+
assert.strictEqual(typedSubscription.serializationMode, 'default');
127127
assert.strictEqual(plainSubscription.serializationMode, 'plain');
128128
assert.strictEqual(jsonSubscription.serializationMode, 'json');
129129

@@ -141,6 +141,6 @@ describe('Serialization Modes Tests', function () {
141141
() => {}
142142
);
143143

144-
assert.strictEqual(subscription.serializationMode, 'typed');
144+
assert.strictEqual(subscription.serializationMode, 'default');
145145
});
146146
});

types/node.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ declare module 'rclnodejs' {
1515
/**
1616
* Valid serialization modes for message conversion
1717
*/
18-
type SerializationMode = 'typed' | 'plain' | 'json';
18+
type SerializationMode = 'default' | 'plain' | 'json';
1919

2020
/**
2121
* A filter description similar to a SQL WHERE clause that limits
@@ -62,9 +62,9 @@ declare module 'rclnodejs' {
6262
isRaw?: boolean;
6363

6464
/**
65-
* Controls message serialization format, default: 'typed'.
65+
* Controls message serialization format, default: 'default'.
6666
*
67-
* - 'typed': Keep TypedArrays for performance
67+
* - 'default': Use native rclnodejs behavior (respects enableTypedArray setting)
6868
* - 'plain': Convert TypedArrays to regular arrays
6969
* - 'json': Fully JSON-safe (handles TypedArrays, BigInt, etc.)
7070
*/
@@ -91,7 +91,7 @@ declare module 'rclnodejs' {
9191
* qos: QoS.profileDefault,
9292
* isRaw: false,
9393
* contentFilter: undefined,
94-
* serializationMode: 'typed'
94+
* serializationMode: 'default'
9595
* }
9696
* ```
9797
*/

0 commit comments

Comments
 (0)