rclnodejs 0.27.5 → 0.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTORS.md +58 -49
- package/README.md +3 -3
- package/binding.gyp +2 -2
- package/lib/client.js +0 -1
- package/lib/lifecycle_publisher.js +1 -1
- package/lib/node.js +1 -8
- package/lib/publisher.js +0 -1
- package/lib/service.js +12 -11
- package/lib/time_source.js +1 -1
- package/package.json +20 -16
- package/rosidl_gen/generator.json +1 -1
- package/rosidl_gen/idl_generator.js +7 -0
- package/rosidl_gen/message_translator.js +4 -1
- package/rosidl_gen/packages.js +3 -3
- package/rosidl_gen/primitive_types.js +2 -2
- package/rosidl_gen/templates/message.dot +206 -248
- package/rostsd_gen/index.js +2 -2
- package/scripts/npm-pack.sh +1 -1
- package/scripts/npmjs-readme.md +3 -3
package/CONTRIBUTORS.md
CHANGED
|
@@ -1,54 +1,63 @@
|
|
|
1
|
-
rclnodejs contributors (sorted alphabetically)
|
|
2
|
-
|
|
1
|
+
# rclnodejs contributors (sorted alphabetically)
|
|
2
|
+
|
|
3
|
+
- **[Alaa El Jawad](https://github.com/ejalaa12), [Ian McElroy](https://github.com/imcelroy)**
|
|
3
4
|
|
|
4
|
-
* **[Alaa El Jawad](https://github.com/ejalaa12), [Ian McElroy](https://github.com/imcelroy)**
|
|
5
5
|
- Fix compatibility with ROS2 parameters array types
|
|
6
6
|
- Unit tests for all parameter types
|
|
7
7
|
- Handle concurrent ROS2 client calls, with unit tests
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
9
|
+
- **[Alex Mikhalev](https://github.com/amikhalev)**
|
|
10
|
+
|
|
11
|
+
- Fix build for AMENT_PREFIX_PATH with multiple entries
|
|
12
|
+
|
|
13
|
+
- **[Felix Divo](https://github.com/felixdivo)**
|
|
14
|
+
|
|
15
|
+
- Code cleanup of index.js, tests cases & message generation
|
|
16
|
+
- Improved shutdown behavior
|
|
17
|
+
- Fixed compilation warnings
|
|
18
|
+
|
|
19
|
+
- **[Hanyia](https://github.com/hanyia)**
|
|
20
|
+
|
|
21
|
+
- Benchmark test script
|
|
22
|
+
|
|
23
|
+
- **[Kenny Yuan](https://github.com/kenny-y)**
|
|
24
|
+
|
|
25
|
+
- Message features: JS generation, typed arrays, plain JS object, compound msgs, many others...
|
|
26
|
+
- npm publish scripts
|
|
27
|
+
- Mac support
|
|
28
|
+
|
|
29
|
+
- **[Matt Richard](https://github.com/mattrichard)**
|
|
30
|
+
|
|
31
|
+
- ROS2 Actions
|
|
32
|
+
- Guard conditions
|
|
33
|
+
- Node utility methods (countPublishers/subscribers...)
|
|
34
|
+
- TypeScript improvements
|
|
35
|
+
- Node 12 compatibility
|
|
36
|
+
|
|
37
|
+
- **[Minggang Wang](https://github.com/minggangw)**
|
|
38
|
+
|
|
39
|
+
- Author, lead developer, maintainer
|
|
40
|
+
- Core, CI
|
|
41
|
+
|
|
42
|
+
- **[Martins Mozeiko](https://github.com/martins-mozeiko)**
|
|
43
|
+
|
|
44
|
+
- QoS new/delete fix
|
|
45
|
+
|
|
46
|
+
- **[Qiuzhong](https://github.com/qiuzhong)**
|
|
47
|
+
|
|
48
|
+
- Test coverage for actions, topics, multi-array messages, cross platform, security
|
|
49
|
+
- Converted from setTimeout to ROS2 Timer
|
|
50
|
+
|
|
51
|
+
- **[Teo Koon Peng](https://github.com/koonpeng)**
|
|
52
|
+
|
|
53
|
+
- TypeScript improvements
|
|
54
|
+
- Added Client#waitForService
|
|
55
|
+
- Code style improvements, e.g., Prettier formatting
|
|
56
|
+
- Improved code generation smarts and efficiency
|
|
57
|
+
|
|
58
|
+
- **[Wayne Parrott](https://github.com/wayneparrott)**
|
|
59
|
+
- TypeScript support with interface generation
|
|
60
|
+
- ROS2 parameter support
|
|
61
|
+
- ROS2 lifecycle node
|
|
62
|
+
- Rate class
|
|
63
|
+
- Node class hierarchy
|
package/README.md
CHANGED
|
@@ -43,9 +43,9 @@ npm i rclnodejs@x.y.z
|
|
|
43
43
|
|
|
44
44
|
#### RCLNODEJS - ROS 2 Version Compatibility
|
|
45
45
|
|
|
46
|
-
| RCLNODEJS Version |
|
|
47
|
-
| :------------------------------------------------------------------------------------------: |
|
|
48
|
-
| latest version (currently [v0.
|
|
46
|
+
| RCLNODEJS Version | Compatible ROS 2 LTS |
|
|
47
|
+
| :------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------: |
|
|
48
|
+
| latest version (currently [v0.28.1](https://github.com/RobotWebTools/rclnodejs/tree/0.28.1)) | [Humble](https://github.com/RobotWebTools/rclnodejs/tree/humble-hawksbill)<br>[Jazzy](https://github.com/RobotWebTools/rclnodejs/tree/jazzy) |
|
|
49
49
|
|
|
50
50
|
## Documentation
|
|
51
51
|
|
package/binding.gyp
CHANGED
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
'OS_LINUX'
|
|
61
61
|
],
|
|
62
62
|
'cflags_cc': [
|
|
63
|
-
'-std=c++
|
|
63
|
+
'-std=c++20'
|
|
64
64
|
],
|
|
65
65
|
'include_dirs':
|
|
66
66
|
[
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
'OS_WINDOWS'
|
|
105
105
|
],
|
|
106
106
|
'cflags_cc': [
|
|
107
|
-
'-std=c++
|
|
107
|
+
'-std=c++20'
|
|
108
108
|
],
|
|
109
109
|
'include_dirs': [
|
|
110
110
|
'./src/third_party/dlfcn-win32/',
|
package/lib/client.js
CHANGED
|
@@ -58,7 +58,6 @@ class Client extends Entity {
|
|
|
58
58
|
request instanceof this._typeClass.Request
|
|
59
59
|
? request
|
|
60
60
|
: new this._typeClass.Request(request);
|
|
61
|
-
requestToSend._willCheckConsistency = this._options.willCheckConsistency;
|
|
62
61
|
|
|
63
62
|
let rawRequest = requestToSend.serialize();
|
|
64
63
|
let sequenceNumber = rclnodejs.sendRequest(this._handle, rawRequest);
|
|
@@ -27,7 +27,7 @@ const Publisher = require('./publisher.js');
|
|
|
27
27
|
*/
|
|
28
28
|
class LifecyclePublisher extends Publisher {
|
|
29
29
|
constructor(handle, typeClass, topic, options) {
|
|
30
|
-
super(handle, typeClass, /*topic=*/'', options);
|
|
30
|
+
super(handle, typeClass, /*topic=*/ '', options);
|
|
31
31
|
|
|
32
32
|
this._enabled = false;
|
|
33
33
|
this._loggger = Logging.getLogger('LifecyclePublisher');
|
package/lib/node.js
CHANGED
|
@@ -116,7 +116,7 @@ class Node extends rclnodejs.ShadowNode {
|
|
|
116
116
|
// override cli parameterOverrides with those specified in options
|
|
117
117
|
if (options.parameterOverrides.length > 0) {
|
|
118
118
|
for (const parameter of options.parameterOverrides) {
|
|
119
|
-
if (!parameter instanceof Parameter) {
|
|
119
|
+
if ((!parameter) instanceof Parameter) {
|
|
120
120
|
throw new TypeError(
|
|
121
121
|
'Parameter-override must be an instance of Parameter.'
|
|
122
122
|
);
|
|
@@ -502,10 +502,6 @@ class Node extends rclnodejs.ShadowNode {
|
|
|
502
502
|
options = Object.assign(options, { isRaw: false });
|
|
503
503
|
}
|
|
504
504
|
|
|
505
|
-
if (options.willCheckConsistency === undefined) {
|
|
506
|
-
options = Object.assign(options, { willCheckConsistency: false });
|
|
507
|
-
}
|
|
508
|
-
|
|
509
505
|
return options;
|
|
510
506
|
}
|
|
511
507
|
|
|
@@ -592,7 +588,6 @@ class Node extends rclnodejs.ShadowNode {
|
|
|
592
588
|
* @param {object} options - The options argument used to parameterize the publisher.
|
|
593
589
|
* @param {boolean} options.enableTypedArray - The topic will use TypedArray if necessary, default: true.
|
|
594
590
|
* @param {QoS} options.qos - ROS Middleware "quality of service" settings for the publisher, default: QoS.profileDefault.
|
|
595
|
-
* @param {boolean} options.willCheckConsistency - Pulisher will check the consistancy of the message to be sent, default: false.
|
|
596
591
|
* @return {Publisher} - An instance of Publisher.
|
|
597
592
|
*/
|
|
598
593
|
createPublisher(typeClass, topic, options) {
|
|
@@ -695,7 +690,6 @@ class Node extends rclnodejs.ShadowNode {
|
|
|
695
690
|
* @param {object} options - The options argument used to parameterize the client.
|
|
696
691
|
* @param {boolean} options.enableTypedArray - The response will use TypedArray if necessary, default: true.
|
|
697
692
|
* @param {QoS} options.qos - ROS Middleware "quality of service" settings for the client, default: QoS.profileDefault.
|
|
698
|
-
* @param {boolean} options.willCheckConsistency - Client will check the consistancy of the message to be sent, default: false.
|
|
699
693
|
* @return {Client} - An instance of Client.
|
|
700
694
|
*/
|
|
701
695
|
createClient(typeClass, serviceName, options) {
|
|
@@ -1696,7 +1690,6 @@ Node.getDefaultOptions = function () {
|
|
|
1696
1690
|
isRaw: false,
|
|
1697
1691
|
qos: QoS.profileDefault,
|
|
1698
1692
|
contentFilter: undefined,
|
|
1699
|
-
willCheckConsistency: false
|
|
1700
1693
|
};
|
|
1701
1694
|
};
|
|
1702
1695
|
|
package/lib/publisher.js
CHANGED
|
@@ -53,7 +53,6 @@ class Publisher extends Entity {
|
|
|
53
53
|
message instanceof this._typeClass
|
|
54
54
|
? message
|
|
55
55
|
: new this._typeClass(message);
|
|
56
|
-
messageToSend._willCheckConsistency = this._options.willCheckConsistency;
|
|
57
56
|
let rawMessage = messageToSend.serialize();
|
|
58
57
|
rclnodejs.publish(this._handle, rawMessage);
|
|
59
58
|
}
|
package/lib/service.js
CHANGED
|
@@ -75,18 +75,19 @@ class Service extends Entity {
|
|
|
75
75
|
|
|
76
76
|
const plainObj = request.toPlainObject(this.typedArrayEnabled);
|
|
77
77
|
const response = new Response(this, headerHandle);
|
|
78
|
-
Promise.resolve(this._callback(plainObj, response)).then(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
Promise.resolve(this._callback(plainObj, response)).then(
|
|
79
|
+
(responseToReturn) => {
|
|
80
|
+
if (!response.sent && responseToReturn) {
|
|
81
|
+
responseToReturn = new this._typeClass.Response(responseToReturn);
|
|
82
|
+
const rawResponse = responseToReturn.serialize();
|
|
83
|
+
rclnodejs.sendResponse(this._handle, rawResponse, headerHandle);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
debug(
|
|
87
|
+
`Service has processed the ${this._serviceName} request and sent the response.`
|
|
88
|
+
);
|
|
84
89
|
}
|
|
85
|
-
|
|
86
|
-
debug(
|
|
87
|
-
`Service has processed the ${this._serviceName} request and sent the response.`
|
|
88
|
-
);
|
|
89
|
-
});
|
|
90
|
+
);
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
static createService(nodeHandle, serviceName, typeClass, options, callback) {
|
package/lib/time_source.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rclnodejs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.1",
|
|
4
4
|
"description": "ROS2.0 JavaScript client with Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"rebuild": "npm run clean && node-gyp -j 16 rebuild",
|
|
19
19
|
"rebuild:dev": "npm run clean && node-gyp -j 16 rebuild --debug",
|
|
20
20
|
"generate-messages": "node scripts/generate_messages.js",
|
|
21
|
+
"generate-messages:dev": "node scripts/generate_messages.js --debug",
|
|
21
22
|
"clean": "node-gyp clean && rimraf ./generated",
|
|
22
23
|
"install": "npm run rebuild",
|
|
23
24
|
"postinstall": "npm run generate-messages",
|
|
@@ -25,7 +26,8 @@
|
|
|
25
26
|
"test": "node --expose-gc ./scripts/run_test.js && npm run dtslint",
|
|
26
27
|
"dtslint": "node scripts/generate_tsd.js",
|
|
27
28
|
"lint": "eslint --max-warnings=0 --ext js,ts index.js types scripts lib example rosidl_gen rosidl_parser test benchmark/rclnodejs && node ./scripts/cpplint.js",
|
|
28
|
-
"format": "clang-format -i -style=file ./src/*.cpp ./src/*.hpp && prettier --write \"{lib,rosidl_gen,rostsd_gen,rosidl_parser,types,example,test,scripts,benchmark}/**/*.{js,md,ts}\" ./*.{js,md,ts}"
|
|
29
|
+
"format": "clang-format -i -style=file ./src/*.cpp ./src/*.hpp && prettier --write \"{lib,rosidl_gen,rostsd_gen,rosidl_parser,types,example,test,scripts,benchmark}/**/*.{js,md,ts}\" ./*.{js,md,ts}",
|
|
30
|
+
"prepare": "husky"
|
|
29
31
|
},
|
|
30
32
|
"bin": {
|
|
31
33
|
"generate-ros-messages": "./scripts/generate_messages.js"
|
|
@@ -41,26 +43,27 @@
|
|
|
41
43
|
"type": "git",
|
|
42
44
|
"url": "git+https://github.com/RobotWebTools/rclnodejs.git"
|
|
43
45
|
},
|
|
46
|
+
"//": "Pin deep-equal to ^1.1.1",
|
|
44
47
|
"devDependencies": {
|
|
45
48
|
"@babel/eslint-parser": "^7.25.9",
|
|
46
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
47
|
-
"@typescript-eslint/parser": "^
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^8.18.0",
|
|
50
|
+
"@typescript-eslint/parser": "^8.18.0",
|
|
48
51
|
"babel-eslint": "^10.1.0",
|
|
49
52
|
"clang-format": "^1.8.0",
|
|
50
|
-
"commander": "^
|
|
53
|
+
"commander": "^12.1.0",
|
|
51
54
|
"deep-equal": "^1.1.1",
|
|
52
|
-
"eslint": "^
|
|
55
|
+
"eslint": "^9.16.0",
|
|
53
56
|
"eslint-config-prettier": "^9.1.0",
|
|
54
57
|
"eslint-plugin-prettier": "^5.2.1",
|
|
55
|
-
"husky": "^
|
|
58
|
+
"husky": "^9.1.7",
|
|
56
59
|
"jsdoc": "^4.0.4",
|
|
57
|
-
"lint-staged": "^
|
|
58
|
-
"mocha": "^
|
|
59
|
-
"
|
|
60
|
-
"sinon": "^15.2.0",
|
|
60
|
+
"lint-staged": "^15.2.10",
|
|
61
|
+
"mocha": "^11.0.2",
|
|
62
|
+
"sinon": "^19.0.2",
|
|
61
63
|
"tree-kill": "^1.2.2",
|
|
62
|
-
"typescript": "^
|
|
64
|
+
"typescript": "^5.7.2"
|
|
63
65
|
},
|
|
66
|
+
"//": "Pin int64-napi to ^1.0.2",
|
|
64
67
|
"dependencies": {
|
|
65
68
|
"@rclnodejs/ref-array-di": "^1.2.2",
|
|
66
69
|
"@rclnodejs/ref-napi": "^4.0.0",
|
|
@@ -77,9 +80,10 @@
|
|
|
77
80
|
"mkdirp": "^3.0.1",
|
|
78
81
|
"mz": "^2.7.0",
|
|
79
82
|
"nan": "^2.22.0",
|
|
80
|
-
"rimraf": "^
|
|
81
|
-
"uuid": "^
|
|
82
|
-
"walk": "^2.3.15"
|
|
83
|
+
"rimraf": "^6.0.1",
|
|
84
|
+
"uuid": "^11.0.3",
|
|
85
|
+
"walk": "^2.3.15",
|
|
86
|
+
"prettier": "^3.4.2"
|
|
83
87
|
},
|
|
84
88
|
"husky": {
|
|
85
89
|
"hooks": {
|
|
@@ -97,4 +101,4 @@
|
|
|
97
101
|
"engines": {
|
|
98
102
|
"node": ">= 16.13.0"
|
|
99
103
|
}
|
|
100
|
-
}
|
|
104
|
+
}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
'use strict';
|
|
16
16
|
|
|
17
17
|
const dot = require('dot');
|
|
18
|
+
const prettier = require('prettier');
|
|
18
19
|
const fse = require('fs-extra');
|
|
19
20
|
const path = require('path');
|
|
20
21
|
const parser = require('../rosidl_parser/rosidl_parser.js');
|
|
@@ -23,6 +24,7 @@ const DistroUtils = require('../lib/distro.js');
|
|
|
23
24
|
|
|
24
25
|
dot.templateSettings.strip = false;
|
|
25
26
|
dot.log = process.env.RCLNODEJS_LOG_VERBOSE || false;
|
|
27
|
+
const isDebug = !!process.argv.find((arg) => arg === '--debug');
|
|
26
28
|
const dots = dot.process({
|
|
27
29
|
path: path.join(__dirname, '../rosidl_gen/templates'),
|
|
28
30
|
});
|
|
@@ -39,6 +41,9 @@ function removeEmptyLines(str) {
|
|
|
39
41
|
* @param {string} code
|
|
40
42
|
*/
|
|
41
43
|
async function writeGeneratedCode(dir, fileName, code) {
|
|
44
|
+
if (fileName.endsWith('.js')) {
|
|
45
|
+
code = await prettier.format(code, { parser: 'babel' });
|
|
46
|
+
}
|
|
42
47
|
await fse.mkdirs(dir);
|
|
43
48
|
await fse.writeFile(path.join(dir, fileName), code);
|
|
44
49
|
}
|
|
@@ -119,6 +124,7 @@ async function generateServiceEventJSStruct(msgInfo, dir) {
|
|
|
119
124
|
messageInfo: msgInfo,
|
|
120
125
|
spec: spec,
|
|
121
126
|
json: JSON.stringify(spec, null, ' '),
|
|
127
|
+
isDebug: isDebug,
|
|
122
128
|
})
|
|
123
129
|
);
|
|
124
130
|
|
|
@@ -148,6 +154,7 @@ function generateMessageJSStructFromSpec(messageInfo, dir, spec) {
|
|
|
148
154
|
messageInfo: messageInfo,
|
|
149
155
|
spec: spec,
|
|
150
156
|
json: JSON.stringify(spec, null, ' '),
|
|
157
|
+
isDebug: isDebug,
|
|
151
158
|
})
|
|
152
159
|
);
|
|
153
160
|
return writeGeneratedCode(dir, fileName, generatedCode);
|
|
@@ -149,7 +149,10 @@ function toPlainObject(message, enableTypedArray = true) {
|
|
|
149
149
|
// TODO(Kenny): make sure Int64 & Uint64 type can be copied here
|
|
150
150
|
obj[name] = message[name];
|
|
151
151
|
}
|
|
152
|
-
} else if (
|
|
152
|
+
} else if (
|
|
153
|
+
def.fields[i].type.isArray &&
|
|
154
|
+
def.fields[i].type.type === 'Constants'
|
|
155
|
+
) {
|
|
153
156
|
// For a constants array, because its field is empty we just return an empty array here.
|
|
154
157
|
obj[name] = [];
|
|
155
158
|
} else {
|
package/rosidl_gen/packages.js
CHANGED
|
@@ -148,10 +148,10 @@ async function generateMsgForSrv(filePath, interfaceInfo, pkgMap) {
|
|
|
148
148
|
await fsp.writeFile(path.join(packagePath, responseMsgName), arr[1]);
|
|
149
149
|
let requestInfo = Object.assign({}, interfaceInfo);
|
|
150
150
|
requestInfo.filePath = path.join(packagePath, requestMsgName);
|
|
151
|
-
requestInfo.interfaceName = requestInfo.interfaceName +
|
|
151
|
+
requestInfo.interfaceName = requestInfo.interfaceName + '_Request';
|
|
152
152
|
let responseInfo = Object.assign({}, interfaceInfo);
|
|
153
153
|
responseInfo.filePath = path.join(packagePath, responseMsgName);
|
|
154
|
-
responseInfo.interfaceName = responseInfo.interfaceName +
|
|
154
|
+
responseInfo.interfaceName = responseInfo.interfaceName + '_Response';
|
|
155
155
|
|
|
156
156
|
addInterfaceInfo(requestInfo, 'messages', pkgMap);
|
|
157
157
|
addInterfaceInfo(responseInfo, 'messages', pkgMap);
|
|
@@ -199,7 +199,7 @@ async function findAmentPackagesInDirectory(dir) {
|
|
|
199
199
|
const rosFiles = Array.prototype.flat ? files.flat() : flat(files);
|
|
200
200
|
const pkgMap = new Map();
|
|
201
201
|
await Promise.all(
|
|
202
|
-
rosFiles.map(filePath => addInterfaceInfos(filePath, dir, pkgMap))
|
|
202
|
+
rosFiles.map((filePath) => addInterfaceInfos(filePath, dir, pkgMap))
|
|
203
203
|
);
|
|
204
204
|
return pkgMap;
|
|
205
205
|
}
|
|
@@ -28,14 +28,14 @@ const StringRefStruct = StructType({
|
|
|
28
28
|
|
|
29
29
|
function initString(str, own = false) {
|
|
30
30
|
if (own) {
|
|
31
|
-
if (!str instanceof Buffer) {
|
|
31
|
+
if ((!str) instanceof Buffer) {
|
|
32
32
|
throw new TypeError(
|
|
33
33
|
'Invalid argument: should provide a Node Buffer to bindingsStringInit()'
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
36
|
rclnodejs.initString(str);
|
|
37
37
|
} else {
|
|
38
|
-
if (!str instanceof StringRefStruct) {
|
|
38
|
+
if ((!str) instanceof StringRefStruct) {
|
|
39
39
|
throw new TypeError(
|
|
40
40
|
'Invalid argument: should provide a type of StringRefStruct'
|
|
41
41
|
);
|
|
@@ -31,7 +31,7 @@ if (it.spec.fields.length === 0) {
|
|
|
31
31
|
},
|
|
32
32
|
"name": "_dummy"
|
|
33
33
|
});
|
|
34
|
-
}
|
|
34
|
+
}
|
|
35
35
|
|
|
36
36
|
function getPrimitiveNameByType(type) {
|
|
37
37
|
if (type.type === 'bool') {
|
|
@@ -69,7 +69,7 @@ function getPrimitiveNameByType(type) {
|
|
|
69
69
|
|
|
70
70
|
function getTypedArrayName(type) {
|
|
71
71
|
const t = type.type.toLowerCase();
|
|
72
|
-
let typedArrayName;
|
|
72
|
+
let typedArrayName = null;
|
|
73
73
|
|
|
74
74
|
switch (t) {
|
|
75
75
|
case 'byte':
|
|
@@ -108,7 +108,6 @@ function getTypedArrayName(type) {
|
|
|
108
108
|
default:
|
|
109
109
|
typedArrayName = '';
|
|
110
110
|
}
|
|
111
|
-
|
|
112
111
|
return typedArrayName;
|
|
113
112
|
}
|
|
114
113
|
|
|
@@ -158,7 +157,7 @@ function isTypedArrayType(type) {
|
|
|
158
157
|
return typedArrayType.indexOf(type.type.toLowerCase()) !== -1;
|
|
159
158
|
}
|
|
160
159
|
|
|
161
|
-
const
|
|
160
|
+
const willUseTypedArray = isTypedArrayType(it.spec.baseType);
|
|
162
161
|
const currentTypedArray = getTypedArrayName(it.spec.baseType);
|
|
163
162
|
const currentTypedArrayElementType = getTypedArrayElementName(it.spec.baseType);
|
|
164
163
|
|
|
@@ -220,7 +219,7 @@ function extractMemberNames(fields) {
|
|
|
220
219
|
}
|
|
221
220
|
}}
|
|
222
221
|
|
|
223
|
-
{{?
|
|
222
|
+
{{? willUseTypedArray}}
|
|
224
223
|
const rclnodejs = require('bindings')('rclnodejs');
|
|
225
224
|
{{?}}
|
|
226
225
|
const ref = require('@rclnodejs/ref-napi');
|
|
@@ -231,116 +230,105 @@ const deallocator = require('../../rosidl_gen/deallocator.js');
|
|
|
231
230
|
const translator = require('../../rosidl_gen/message_translator.js');
|
|
232
231
|
|
|
233
232
|
{{~ it.spec.fields :field}}
|
|
234
|
-
{{? shouldRequire(it.spec.baseType, field.type)}}
|
|
235
|
-
const {{=getWrapperNameByType(field.type)}} = require('../../generated/{{=getPackageNameByType(field.type)}}/{{=getModulePathByType(field.type, it.messageInfo)}}');
|
|
236
|
-
{{?}}
|
|
233
|
+
{{? shouldRequire(it.spec.baseType, field.type)}}
|
|
234
|
+
const {{=getWrapperNameByType(field.type)}} = require('../../generated/{{=getPackageNameByType(field.type)}}/{{=getModulePathByType(field.type, it.messageInfo)}}');
|
|
235
|
+
{{?}}
|
|
237
236
|
{{~}}
|
|
238
237
|
|
|
239
238
|
{{? it.spec.msgName === 'String'}}
|
|
240
239
|
const {{=refObjectType}} = primitiveTypes.string;
|
|
241
240
|
{{??}}
|
|
242
241
|
const {{=refObjectType}} = StructType({
|
|
243
|
-
{{~ it.spec.fields :field}}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
{{~}}
|
|
242
|
+
{{~ it.spec.fields :field}}
|
|
243
|
+
{{? field.type.isPrimitiveType && !field.type.isArray}}
|
|
244
|
+
{{=field.name}}: primitiveTypes.{{=field.type.type}},
|
|
245
|
+
{{?? field.type.isPrimitiveType && field.type.isArray && field.type.isFixedSizeArray}}
|
|
246
|
+
{{=field.name}}: ArrayType(primitiveTypes.{{=field.type.type}}, {{=field.type.arraySize}}),
|
|
247
|
+
{{?? !field.type.isPrimitiveType && field.type.isArray && field.type.isFixedSizeArray}}
|
|
248
|
+
{{=field.name}}: ArrayType({{=getWrapperNameByType(field.type)}}.refObjectType, {{=field.type.arraySize}}),
|
|
249
|
+
{{?? field.type.isArray}}
|
|
250
|
+
{{=field.name}}: {{=getWrapperNameByType(field.type)}}.refObjectArrayType,
|
|
251
|
+
{{??}}
|
|
252
|
+
{{=field.name}}: {{=getWrapperNameByType(field.type)}}.refObjectType,
|
|
253
|
+
{{?}}
|
|
254
|
+
{{~}}
|
|
256
255
|
});
|
|
257
256
|
{{?}}
|
|
258
257
|
|
|
259
258
|
const {{=refArrayType}} = ArrayType({{=refObjectType}});
|
|
260
259
|
const {{=refObjectArrayType}} = StructType({
|
|
261
|
-
{{?
|
|
260
|
+
{{? willUseTypedArray}}
|
|
262
261
|
data: ref.refType(ref.types.{{=currentTypedArrayElementType}}),
|
|
263
|
-
{{??
|
|
262
|
+
{{??}}
|
|
264
263
|
data: {{=refArrayType}},
|
|
265
|
-
{{?}}
|
|
264
|
+
{{?}}
|
|
266
265
|
size: ref.types.size_t,
|
|
267
266
|
capacity: ref.types.size_t
|
|
268
267
|
});
|
|
269
268
|
|
|
270
|
-
|
|
269
|
+
{{/* Define the wrapper class for the message. */}}
|
|
271
270
|
class {{=objectWrapper}} {
|
|
272
|
-
constructor(other
|
|
273
|
-
this.
|
|
274
|
-
this.
|
|
275
|
-
{{~ it.spec.fields :field}}
|
|
276
|
-
{{? field.type.isArray && field.type.isPrimitiveType && !isTypedArrayType(field.type)}}
|
|
277
|
-
this._{{=field.name}}Array = [];
|
|
278
|
-
{{?}}
|
|
279
|
-
{{~}}
|
|
271
|
+
constructor(other) {
|
|
272
|
+
this._initialize();
|
|
273
|
+
this._setDefaults();
|
|
280
274
|
|
|
275
|
+
{{/* Construct `this` from `other`. */}}
|
|
281
276
|
if (typeof other === 'object' && other._refObject) {
|
|
282
277
|
this._refObject = new {{=refObjectType}}(other._refObject.toObject());
|
|
283
278
|
{{~ it.spec.fields :field}}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
{{?}}
|
|
294
|
-
{{?? !field.type.isPrimitiveType || (field.type.type === 'string' && it.spec.msgName !== 'String')}}
|
|
295
|
-
this._wrapperFields.{{=field.name}} = new {{=getWrapperNameByType(field.type)}}(other._wrapperFields.{{=field.name}});
|
|
296
|
-
{{?}}
|
|
279
|
+
{{? field.type.isArray}}
|
|
280
|
+
this._wrapperFields.{{=field.name}} = {{=getWrapperNameByType(field.type)}}.createArray();
|
|
281
|
+
this._wrapperFields.{{=field.name}}.copy(other._wrapperFields.{{=field.name}});
|
|
282
|
+
{{? field.type.isPrimitiveType && !isTypedArrayType(field.type)}}
|
|
283
|
+
this.{{=field.name}} = other.{{=field.name}};
|
|
284
|
+
{{?}}
|
|
285
|
+
{{?? !field.type.isPrimitiveType || (field.type.type === 'string' && it.spec.msgName !== 'String')}}
|
|
286
|
+
this._wrapperFields.{{=field.name}} = new {{=getWrapperNameByType(field.type)}}(other._wrapperFields.{{=field.name}});
|
|
287
|
+
{{?}}
|
|
297
288
|
{{~}}
|
|
298
289
|
} else if (typeof other !== 'undefined') {
|
|
299
|
-
|
|
290
|
+
{{/* Try to construct the message from a plan object of JavaScript. */}}
|
|
300
291
|
translator.constructFromPlanObject(this, other);
|
|
301
|
-
} else {
|
|
302
|
-
this._initMembers();
|
|
303
292
|
}
|
|
304
|
-
this.freeze();
|
|
293
|
+
this.freeze(/*own=*/false);
|
|
305
294
|
}
|
|
306
295
|
|
|
307
|
-
|
|
308
|
-
|
|
296
|
+
{{/* Set default values if the fields of the message have. */}}
|
|
297
|
+
_setDefaults() {
|
|
309
298
|
{{~ it.spec.fields :field}}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
{{?}}
|
|
299
|
+
{{? field.type.isPrimitiveType && !field.type.isArray && field.default_value}}
|
|
300
|
+
{{? field.type.type === 'string' || field.type.type === 'wstring'}}
|
|
301
|
+
this._refObject.{{=field.name}} = "{{=field.default_value.replace(/"/g, '\\"')}}";
|
|
302
|
+
{{??}}
|
|
303
|
+
this._refObject.{{=field.name}} = {{=field.default_value}};
|
|
304
|
+
{{?}}
|
|
305
|
+
{{?? field.type.isPrimitiveType && !isTypedArrayType(field.type) && field.default_value}}
|
|
306
|
+
this._{{=field.name}}Array = {{=JSON.stringify(field.default_value)}};
|
|
307
|
+
{{?? field.type.isPrimitiveType && isTypedArrayType(field.type) && field.default_value}}
|
|
308
|
+
this._wrapperFields.{{=field.name}}.fill({{=getTypedArrayName(field.type)}}.from({{=JSON.stringify(field.default_value)}}));
|
|
309
|
+
{{?}}
|
|
310
|
+
{{~}}
|
|
311
|
+
}
|
|
324
312
|
|
|
325
|
-
|
|
326
|
-
this._wrapperFields
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
313
|
+
_initialize() {
|
|
314
|
+
this._wrapperFields = {};
|
|
315
|
+
this._refObject = new {{=refObjectType}}();
|
|
316
|
+
{{~ it.spec.fields :field}}
|
|
317
|
+
{{? field.type.isArray}}
|
|
318
|
+
this._wrapperFields.{{=field.name}} = {{=getWrapperNameByType(field.type)}}.createArray();
|
|
319
|
+
{{? field.type.type === 'string' && field.type.isFixedSizeArray}}
|
|
320
|
+
for (let i = 0; i < {{=field.type.arraySize}}; i++) {
|
|
321
|
+
primitiveTypes.initString(this._refObject.{{=field.name}}[i]);
|
|
322
|
+
}
|
|
323
|
+
{{?}}
|
|
324
|
+
{{? field.type.isArray && field.type.isPrimitiveType && !isTypedArrayType(field.type)}}
|
|
325
|
+
this._{{=field.name}}Array = [];
|
|
326
|
+
{{?}}
|
|
327
|
+
{{?? !field.type.isPrimitiveType || (field.type.type === 'string' && it.spec.msgName !== 'String')}}
|
|
328
|
+
this._wrapperFields.{{=field.name}} = new {{=getWrapperNameByType(field.type)}}();
|
|
329
|
+
{{?? it.spec.msgName === 'String'}}
|
|
330
|
+
primitiveTypes.initString(this._refObject);
|
|
331
|
+
{{?}}
|
|
344
332
|
{{~}}
|
|
345
333
|
}
|
|
346
334
|
|
|
@@ -367,102 +355,93 @@ class {{=objectWrapper}} {
|
|
|
367
355
|
}
|
|
368
356
|
|
|
369
357
|
toRawROS() {
|
|
370
|
-
this.freeze(true);
|
|
358
|
+
this.freeze(/*own=*/true);
|
|
371
359
|
return this._refObject.ref();
|
|
372
360
|
}
|
|
373
361
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
{{? field.type.isPrimitiveType && !field.type.isArray}}
|
|
377
|
-
if (checkConsistency && !this._{{=field.name}}Intialized) {
|
|
378
|
-
throw new TypeError('Invalid argument: {{=field.name}} in {{=it.spec.msgName}}');
|
|
379
|
-
}
|
|
380
|
-
{{?}}
|
|
381
|
-
{{~}}
|
|
382
|
-
|
|
362
|
+
{{ /*Assign values to the ref object wrapped by `this`. */ }}
|
|
363
|
+
freeze(own) {
|
|
383
364
|
{{~ it.spec.fields :field}}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
365
|
+
{{? field.type.isArray && field.type.isPrimitiveType && !isTypedArrayType(field.type) && field.type.isFixedSizeArray}}
|
|
366
|
+
{{? field.type.type === 'string'}}
|
|
367
|
+
for (let i = 0; i < {{=field.type.arraySize}}; i++) {
|
|
368
|
+
if (own) {
|
|
369
|
+
primitiveTypes.initString(this._refObject.{{=field.name}}[i].ref(), own);
|
|
370
|
+
} else {
|
|
371
|
+
if (this._{{=field.name}}Array.length === {{=field.type.arraySize}}) {
|
|
372
|
+
const value = this._{{=field.name}}Array[i];
|
|
373
|
+
this._refObject.{{=field.name}}[i].data = value;
|
|
374
|
+
this._refObject.{{=field.name}}[i].size = Buffer.byteLength(value);
|
|
375
|
+
this._refObject.{{=field.name}}[i].capacity = Buffer.byteLength(value) + 1;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
{{??}}
|
|
380
|
+
{{/* For non-TypedArray like int64/uint64/bool. */}}
|
|
381
|
+
this._refObject.{{=field.name}} = this._{{=field.name}}Array;
|
|
382
|
+
{{?}}
|
|
383
|
+
{{?? field.type.isArray && field.type.isPrimitiveType && isTypedArrayType(field.type) && field.type.isFixedSizeArray}}
|
|
384
|
+
this._refObject.{{=field.name}} = Array.from(this._wrapperFields.{{=field.name}}.data);
|
|
385
|
+
{{?? field.type.isArray && field.type.isPrimitiveType && !isTypedArrayType(field.type)}}
|
|
387
386
|
if (own) {
|
|
388
|
-
|
|
387
|
+
this._wrapperFields.{{=field.name}}.fill([]);
|
|
389
388
|
} else {
|
|
390
|
-
|
|
391
|
-
const value = this._{{=field.name}}Array[i];
|
|
392
|
-
this._refObject.{{=field.name}}[i].data = value;
|
|
393
|
-
this._refObject.{{=field.name}}[i].size = Buffer.byteLength(value);
|
|
394
|
-
this._refObject.{{=field.name}}[i].capacity = Buffer.byteLength(value) + 1;
|
|
395
|
-
}
|
|
389
|
+
this._wrapperFields.{{=field.name}}.fill(this._{{=field.name}}Array);
|
|
396
390
|
}
|
|
397
|
-
|
|
398
|
-
// For non-typed array like int64/uint64/bool.
|
|
399
|
-
{{?? true}}
|
|
400
|
-
this._refObject.{{=field.name}} = this._{{=field.name}}Array;
|
|
401
|
-
{{?}}
|
|
402
|
-
{{?? field.type.isArray && field.type.isPrimitiveType && isTypedArrayType(field.type) && field.type.isFixedSizeArray}}
|
|
403
|
-
this._refObject.{{=field.name}} = Array.from(this._wrapperFields.{{=field.name}}.data);
|
|
404
|
-
{{?? field.type.isArray && field.type.isPrimitiveType && !isTypedArrayType(field.type)}}
|
|
405
|
-
if (!own) {
|
|
406
|
-
this._wrapperFields.{{=field.name}}.fill(this._{{=field.name}}Array);
|
|
407
|
-
this._wrapperFields.{{=field.name}}.freeze(own, checkConsistency);
|
|
391
|
+
this._wrapperFields.{{=field.name}}.freeze(own);
|
|
408
392
|
this._refObject.{{=field.name}} = this._wrapperFields.{{=field.name}}.refObject;
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
393
|
+
{{?? field.type.isArray && field.type.isPrimitiveType && isTypedArrayType(field.type)}}
|
|
394
|
+
if (own) {
|
|
395
|
+
this._wrapperFields.{{=field.name}}.fill({{=getTypedArrayName(field.type)}}.from([]));
|
|
396
|
+
}
|
|
397
|
+
this._wrapperFields.{{=field.name}}.freeze(own);
|
|
412
398
|
this._refObject.{{=field.name}} = this._wrapperFields.{{=field.name}}.refObject;
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
399
|
+
{{?? field.type.isArray && !field.type.isPrimitiveType && field.type.isFixedSizeArray}}
|
|
400
|
+
for (let i = 0; i < {{=field.type.arraySize}}; i++) {
|
|
401
|
+
if (this._wrapperFields.{{=field.name}}.data[i]) {
|
|
402
|
+
this._wrapperFields.{{=field.name}}.data[i].freeze(own);
|
|
403
|
+
this._refObject.{{=field.name}}[i] = this._wrapperFields.{{=field.name}}.data[i].refObject;
|
|
404
|
+
}
|
|
419
405
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
this._wrapperFields.{{=field.name}}.
|
|
427
|
-
this._wrapperFields.{{=field.name}}.freeze(own, checkConsistency);
|
|
406
|
+
{{?? field.type.isArray || !field.type.isPrimitiveType}}
|
|
407
|
+
{{? field.type.isArray}}
|
|
408
|
+
if (own) {
|
|
409
|
+
this._wrapperFields.{{=field.name}}.fill([]);
|
|
410
|
+
}
|
|
411
|
+
{{?}}
|
|
412
|
+
this._wrapperFields.{{=field.name}}.freeze(own);
|
|
428
413
|
this._refObject.{{=field.name}} = this._wrapperFields.{{=field.name}}.refObject;
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
this._wrapperFields.{{=field.name}}.
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
{{?}}
|
|
414
|
+
{{?? field.type.type === 'string' && it.spec.msgName !== 'String'}}
|
|
415
|
+
if (own) {
|
|
416
|
+
this._wrapperFields.{{=field.name}}.freeze(own);
|
|
417
|
+
}
|
|
418
|
+
this._refObject.{{=field.name}} = this._wrapperFields.{{=field.name}}.refObject;
|
|
419
|
+
{{?? it.spec.msgName === 'String'}}
|
|
420
|
+
if (own) {
|
|
421
|
+
primitiveTypes.initString(this._refObject.ref(), own);
|
|
422
|
+
}
|
|
423
|
+
{{?}}
|
|
441
424
|
{{~}}
|
|
442
425
|
}
|
|
443
426
|
|
|
444
427
|
serialize() {
|
|
445
|
-
this.freeze(/*own=*/false
|
|
428
|
+
this.freeze(/*own=*/false);
|
|
446
429
|
return this._refObject.ref();
|
|
447
430
|
}
|
|
448
431
|
|
|
449
432
|
deserialize(refObject) {
|
|
450
433
|
{{~ it.spec.fields :field}}
|
|
451
|
-
{{? field.type.isPrimitiveType && !field.type.isArray}}
|
|
452
|
-
this._{{=field.name}}Intialized = true;
|
|
453
|
-
{{?}}
|
|
454
|
-
|
|
455
434
|
{{? field.type.isArray && field.type.isPrimitiveType && field.type.isFixedSizeArray && isTypedArrayType(field.type)}}
|
|
456
435
|
this._wrapperFields.{{=field.name}}.fill(refObject.{{=field.name}}.toArray());
|
|
457
436
|
{{?? field.type.isArray && field.type.isPrimitiveType && field.type.isFixedSizeArray && !isTypedArrayType(field.type)}}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
437
|
+
{{? field.type.type === 'string'}}
|
|
438
|
+
for (let index = 0; index < {{=field.type.arraySize}}; index++) {
|
|
439
|
+
this._{{=field.name}}Array[index] = refObject.{{=field.name}}[index].data;
|
|
440
|
+
}
|
|
441
|
+
{{??}}
|
|
442
|
+
{{/* For non-TypedArray like int64/uint64/bool. */}}
|
|
443
|
+
this._{{=field.name}}Array = refObject.{{=field.name}}.toArray();
|
|
444
|
+
{{?}}
|
|
466
445
|
{{?? field.type.isArray && field.type.isPrimitiveType && !isTypedArrayType(field.type)}}
|
|
467
446
|
refObject.{{=field.name}}.data.length = refObject.{{=field.name}}.size;
|
|
468
447
|
for (let index = 0; index < refObject.{{=field.name}}.size; index++) {
|
|
@@ -474,7 +453,7 @@ class {{=objectWrapper}} {
|
|
|
474
453
|
for (let i = 0; i < {{=field.type.arraySize}}; i++) {
|
|
475
454
|
this._wrapperFields.{{=field.name}}.data[i].copyRefObject(refObject.{{=field.name}}[i]);
|
|
476
455
|
}
|
|
477
|
-
{{??
|
|
456
|
+
{{?? field.type.isArray || !field.type.isPrimitiveType}}
|
|
478
457
|
this._wrapperFields.{{=field.name}}.copyRefObject(refObject.{{=field.name}});
|
|
479
458
|
{{?? field.type.type === 'string' && it.spec.msgName !== 'String'}}
|
|
480
459
|
this._wrapperFields.{{=field.name}}.data = refObject.{{=field.name}}.data;
|
|
@@ -493,9 +472,8 @@ class {{=objectWrapper}} {
|
|
|
493
472
|
{{? field.type.isArray && !field.type.isFixedSizeArray}}
|
|
494
473
|
if (refObject.{{=field.name}}.size != 0) {
|
|
495
474
|
{{=getWrapperNameByType(field.type)}}.ArrayType.freeArray(refObject.{{=field.name}});
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
} else {
|
|
475
|
+
{{/* We don't need to free the memory for TypedArray objects, because v8 takes the ownership of it. */}}
|
|
476
|
+
if (!{{=getWrapperNameByType(field.type)}}.ArrayType.useTypedArray) {
|
|
499
477
|
deallocator.freeStructMember(refObject.{{=field.name}}, {{=getWrapperNameByType(field.type)}}.refObjectArrayType, 'data');
|
|
500
478
|
}
|
|
501
479
|
}
|
|
@@ -548,27 +526,18 @@ class {{=objectWrapper}} {
|
|
|
548
526
|
{{?? !field.type.isPrimitiveType && !field.type.isArray}}
|
|
549
527
|
return this._wrapperFields.{{=field.name}};
|
|
550
528
|
{{?? !field.type.isArray && field.type.type === 'string' && it.spec.msgName !== 'String'}}
|
|
551
|
-
if (!this._{{=field.name}}Intialized) {
|
|
552
|
-
return undefined;
|
|
553
|
-
}
|
|
554
529
|
return this._wrapperFields.{{=field.name}}.data;
|
|
555
|
-
{{??
|
|
556
|
-
if (!this._{{=field.name}}Intialized) {
|
|
557
|
-
return undefined;
|
|
558
|
-
}
|
|
530
|
+
{{??}}
|
|
559
531
|
return this._refObject.{{=field.name}};
|
|
560
532
|
{{?}}
|
|
561
533
|
}
|
|
562
534
|
|
|
563
535
|
set {{=field.name}}(value) {
|
|
564
|
-
{{? field.type.isPrimitiveType && !field.type.isArray}}
|
|
565
|
-
this._{{=field.name}}Intialized = true;
|
|
566
|
-
{{?}}
|
|
567
|
-
|
|
568
536
|
{{?field.type.isArray && field.type.isFixedSizeArray}}
|
|
569
537
|
if (value.length !== {{=field.type.arraySize}}) {
|
|
570
538
|
throw new RangeError('The length of the array must be {{=field.type.arraySize}}.');
|
|
571
539
|
}
|
|
540
|
+
|
|
572
541
|
{{?}}
|
|
573
542
|
{{?field.type.isArray && field.type.isUpperBound}}
|
|
574
543
|
if (value.length > {{=field.type.arraySize}}) {
|
|
@@ -590,11 +559,11 @@ class {{=objectWrapper}} {
|
|
|
590
559
|
}
|
|
591
560
|
{{?? !field.type.isArray && field.type.type === 'string' && it.spec.msgName !== 'String'}}
|
|
592
561
|
this._wrapperFields.{{=field.name}}.data = value;
|
|
593
|
-
{{??
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
562
|
+
{{??}}
|
|
563
|
+
{{? it.spec.msgName === 'String'}}
|
|
564
|
+
this._refObject.size = Buffer.byteLength(value);
|
|
565
|
+
this._refObject.capacity = Buffer.byteLength(value) + 1;
|
|
566
|
+
{{?}}
|
|
598
567
|
this._refObject.{{=field.name}} = value;
|
|
599
568
|
{{?}}
|
|
600
569
|
}
|
|
@@ -604,26 +573,22 @@ class {{=objectWrapper}} {
|
|
|
604
573
|
this._refObject = new {{=refObjectType}}(refObject.toObject());
|
|
605
574
|
|
|
606
575
|
{{~ it.spec.fields :field}}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
}
|
|
624
|
-
{{?? !field.type.isPrimitiveType || field.type.isArray || (field.type.type === 'string' && it.spec.msgName !== 'String')}}
|
|
625
|
-
this._wrapperFields.{{=field.name}}.copyRefObject(this._refObject.{{=field.name}});
|
|
626
|
-
{{?}}
|
|
576
|
+
{{? field.type.isArray && field.type.isPrimitiveType && !isTypedArrayType(field.type)}}
|
|
577
|
+
refObject.{{=field.name}}.data.length = refObject.{{=field.name}}.size;
|
|
578
|
+
for (let index = 0; index < refObject.{{=field.name}}.size; index++) {
|
|
579
|
+
this._{{=field.name}}Array[index] = refObject.{{=field.name}}.data[index].data;
|
|
580
|
+
}
|
|
581
|
+
{{?? field.type.isArray && field.type.isPrimitiveType && field.type.isFixedSizeArray}}
|
|
582
|
+
this._wrapperFields.{{=field.name}}.fill(refObject.{{=field.name}}.toArray());
|
|
583
|
+
{{?? field.type.isArray && !field.type.isPrimitiveType && field.type.isFixedSizeArray}}
|
|
584
|
+
this._refObject.{{=field.name}} = refObject.{{=field.name}};
|
|
585
|
+
this._wrapperFields.{{=field.name}}.size = {{=field.type.arraySize}}
|
|
586
|
+
for (let i = 0; i < {{=field.type.arraySize}}; i++) {
|
|
587
|
+
this._wrapperFields.{{=field.name}}.data[i].copyRefObject(refObject.{{=field.name}}[i]);
|
|
588
|
+
}
|
|
589
|
+
{{?? !field.type.isPrimitiveType || field.type.isArray || (field.type.type === 'string' && it.spec.msgName !== 'String')}}
|
|
590
|
+
this._wrapperFields.{{=field.name}}.copyRefObject(this._refObject.{{=field.name}});
|
|
591
|
+
{{?}}
|
|
627
592
|
{{~}}
|
|
628
593
|
}
|
|
629
594
|
|
|
@@ -631,15 +596,11 @@ class {{=objectWrapper}} {
|
|
|
631
596
|
this._refObject = new {{=refObjectType}}(other._refObject.toObject());
|
|
632
597
|
|
|
633
598
|
{{~ it.spec.fields :field}}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
this._{{=field.name}}Array = other._{{=field.name}}Array.slice();
|
|
640
|
-
{{?? !field.type.isPrimitiveType || field.type.isArray || (field.type.type === 'string' && it.spec.msgName !== 'String')}}
|
|
641
|
-
this._wrapperFields.{{=field.name}}.copy(other._wrapperFields.{{=field.name}});
|
|
642
|
-
{{?}}
|
|
599
|
+
{{? field.type.isArray && field.type.isPrimitiveType && !isTypedArrayType(field.type)}}
|
|
600
|
+
this._{{=field.name}}Array = other._{{=field.name}}Array.slice();
|
|
601
|
+
{{?? !field.type.isPrimitiveType || field.type.isArray || (field.type.type === 'string' && it.spec.msgName !== 'String')}}
|
|
602
|
+
this._wrapperFields.{{=field.name}}.copy(other._wrapperFields.{{=field.name}});
|
|
603
|
+
{{?}}
|
|
643
604
|
{{~}}
|
|
644
605
|
}
|
|
645
606
|
|
|
@@ -657,7 +618,7 @@ class {{=objectWrapper}} {
|
|
|
657
618
|
}
|
|
658
619
|
}
|
|
659
620
|
|
|
660
|
-
|
|
621
|
+
{{/* Define the wrapper class for the message array. */}}
|
|
661
622
|
class {{=arrayWrapper}} {
|
|
662
623
|
constructor(size = 0) {
|
|
663
624
|
this._resize(size);
|
|
@@ -668,15 +629,15 @@ class {{=arrayWrapper}} {
|
|
|
668
629
|
}
|
|
669
630
|
|
|
670
631
|
fill(values) {
|
|
671
|
-
{{?
|
|
632
|
+
{{? willUseTypedArray}}
|
|
672
633
|
if (Array.isArray(values)) {
|
|
673
|
-
|
|
634
|
+
{{/* Convert to TypedArray. */}}
|
|
674
635
|
this._wrappers = new {{=currentTypedArray}}(values);
|
|
675
636
|
} else {
|
|
676
637
|
this._wrappers = values;
|
|
677
638
|
}
|
|
678
639
|
{{?? isPrimitivePackage(it.spec.baseType)}}
|
|
679
|
-
|
|
640
|
+
{{/* For primitive arrays, only string/bool/int64/uint64 array drops here. */}}
|
|
680
641
|
const length = values.length;
|
|
681
642
|
this._resize(length);
|
|
682
643
|
for (let i = 0; i < length; ++i) {
|
|
@@ -684,7 +645,7 @@ class {{=arrayWrapper}} {
|
|
|
684
645
|
wrapper.data = values[i];
|
|
685
646
|
this._wrappers[i] = wrapper;
|
|
686
647
|
}
|
|
687
|
-
{{??
|
|
648
|
+
{{??}}
|
|
688
649
|
const length = values.length;
|
|
689
650
|
this._resize(length);
|
|
690
651
|
values.forEach((value, index) => {
|
|
@@ -697,11 +658,10 @@ class {{=arrayWrapper}} {
|
|
|
697
658
|
{{?}}
|
|
698
659
|
}
|
|
699
660
|
|
|
700
|
-
|
|
661
|
+
{{/* Put all data currently stored in `this._wrappers` into `this._refObject`. */}}
|
|
701
662
|
freeze(own) {
|
|
702
|
-
{{
|
|
703
|
-
|
|
704
|
-
{{?? true}}
|
|
663
|
+
{{/* When it's a TypedArray: no need to copy to `this._refArray`. */}}
|
|
664
|
+
{{? !willUseTypedArray}}
|
|
705
665
|
this._wrappers.forEach((wrapper, index) => {
|
|
706
666
|
wrapper.freeze(own);
|
|
707
667
|
this._refArray[index] = wrapper.refObject;
|
|
@@ -714,12 +674,12 @@ class {{=arrayWrapper}} {
|
|
|
714
674
|
if (this._refObject.capacity === 0) {
|
|
715
675
|
this._refObject.data = null
|
|
716
676
|
} else {
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
677
|
+
{{? willUseTypedArray}}
|
|
678
|
+
const buffer = Buffer.from(new Uint8Array(this._wrappers.buffer));
|
|
679
|
+
this._refObject.data = buffer;
|
|
680
|
+
{{??}}
|
|
681
|
+
this._refObject.data = this._refArray.buffer;
|
|
682
|
+
{{?}}
|
|
723
683
|
}
|
|
724
684
|
}
|
|
725
685
|
|
|
@@ -738,7 +698,6 @@ class {{=arrayWrapper}} {
|
|
|
738
698
|
set size(value) {
|
|
739
699
|
if (typeof value != 'number') {
|
|
740
700
|
throw new TypeError('Invalid argument: should provide a number to {{=arrayWrapper}}.size setter');
|
|
741
|
-
return;
|
|
742
701
|
}
|
|
743
702
|
return this._resize(value);
|
|
744
703
|
}
|
|
@@ -761,11 +720,10 @@ class {{=arrayWrapper}} {
|
|
|
761
720
|
_resize(size) {
|
|
762
721
|
if (size < 0) {
|
|
763
722
|
throw new RangeError('Invalid argument: should provide a positive number');
|
|
764
|
-
return;
|
|
765
723
|
}
|
|
766
|
-
{{?
|
|
724
|
+
{{? willUseTypedArray}}
|
|
767
725
|
this._refArray = undefined;
|
|
768
|
-
{{??
|
|
726
|
+
{{??}}
|
|
769
727
|
this._refArray = new {{=refArrayType}}(size);
|
|
770
728
|
{{?}}
|
|
771
729
|
|
|
@@ -773,9 +731,9 @@ class {{=arrayWrapper}} {
|
|
|
773
731
|
this._refObject.size = size;
|
|
774
732
|
this._refObject.capacity = size;
|
|
775
733
|
|
|
776
|
-
{{?
|
|
734
|
+
{{? willUseTypedArray}}
|
|
777
735
|
this._wrappers = new {{=currentTypedArray}}(size);
|
|
778
|
-
{{??
|
|
736
|
+
{{??}}
|
|
779
737
|
this._wrappers = new Array();
|
|
780
738
|
for (let i = 0; i < size; i++) {
|
|
781
739
|
this._wrappers.push(new {{=objectWrapper}}());
|
|
@@ -783,22 +741,21 @@ class {{=arrayWrapper}} {
|
|
|
783
741
|
{{?}}
|
|
784
742
|
}
|
|
785
743
|
|
|
786
|
-
|
|
744
|
+
{{/* Copy all data from `this._refObject` into `this._wrappers`. */}}
|
|
787
745
|
copyRefObject(refObject) {
|
|
788
746
|
this._refObject = refObject;
|
|
789
747
|
|
|
790
|
-
{{?
|
|
748
|
+
{{? willUseTypedArray}}
|
|
791
749
|
const byteLen = refObject.size * ref.types.{{=currentTypedArrayElementType}}.size;
|
|
792
|
-
|
|
750
|
+
{{/* An ArrayBuffer object doesn't hold the ownership of memory block starting from address for TypedArray. */}}
|
|
793
751
|
const arrayBuffer = refObject.data.length !== 0 ?
|
|
794
752
|
rclnodejs.createArrayBufferFromAddress(refObject.data.hexAddress(), byteLen) :
|
|
795
753
|
Buffer.alloc(0);
|
|
796
754
|
this._wrappers = new {{=currentTypedArray}}(arrayBuffer);
|
|
797
|
-
{{??
|
|
755
|
+
{{??}}
|
|
798
756
|
let refObjectArray = this._refObject.data;
|
|
799
757
|
refObjectArray.length = this._refObject.size;
|
|
800
758
|
this._resize(this._refObject.size);
|
|
801
|
-
|
|
802
759
|
for (let index = 0; index < this._refObject.size; index++) {
|
|
803
760
|
this._wrappers[index].copyRefObject(refObjectArray[index]);
|
|
804
761
|
}
|
|
@@ -811,10 +768,10 @@ class {{=arrayWrapper}} {
|
|
|
811
768
|
}
|
|
812
769
|
|
|
813
770
|
this._resize(other.size);
|
|
814
|
-
{{?
|
|
771
|
+
{{? willUseTypedArray}}
|
|
815
772
|
this._wrappers = other._wrappers.slice();
|
|
816
|
-
{{??
|
|
817
|
-
|
|
773
|
+
{{??}}
|
|
774
|
+
{{/* Deep copy for non-TypedArray. */}}
|
|
818
775
|
other._wrappers.forEach((wrapper, index) => {
|
|
819
776
|
this._wrappers[index].copy(wrapper);
|
|
820
777
|
});
|
|
@@ -822,9 +779,8 @@ class {{=arrayWrapper}} {
|
|
|
822
779
|
}
|
|
823
780
|
|
|
824
781
|
static freeArray(refObject) {
|
|
825
|
-
{{
|
|
826
|
-
|
|
827
|
-
{{?? true}}
|
|
782
|
+
{{/* We don't need to free the memory for TypedArray objects, because v8 takes the ownership of it. */}}
|
|
783
|
+
{{? !willUseTypedArray}}
|
|
828
784
|
let refObjectArray = refObject.data;
|
|
829
785
|
refObjectArray.length = refObject.size;
|
|
830
786
|
for (let index = 0; index < refObject.size; index++) {
|
|
@@ -842,7 +798,7 @@ class {{=arrayWrapper}} {
|
|
|
842
798
|
}
|
|
843
799
|
|
|
844
800
|
static get useTypedArray() {
|
|
845
|
-
return {{=
|
|
801
|
+
return {{=willUseTypedArray}};
|
|
846
802
|
}
|
|
847
803
|
|
|
848
804
|
get classType() {
|
|
@@ -851,19 +807,21 @@ class {{=arrayWrapper}} {
|
|
|
851
807
|
}
|
|
852
808
|
|
|
853
809
|
{{? it.spec.constants != undefined && it.spec.constants.length}}
|
|
854
|
-
|
|
855
|
-
{{~ it.spec.constants :c}}
|
|
856
|
-
{{? c.type === "string"}}
|
|
857
|
-
Object.defineProperty({{=objectWrapper}}, "{{=c.name}}", {value: "{{=c.value}}", writable: false, enumerable: true, configurable: true});
|
|
858
|
-
{{??
|
|
859
|
-
Object.defineProperty({{=objectWrapper}}, "{{=c.name}}", {value: {{=c.value}}, writable: false, enumerable: true, configurable: true});
|
|
860
|
-
{{?}}
|
|
861
|
-
{{~}}
|
|
810
|
+
{{/* Define constants ({{=it.spec.constants.length}} in total). */}}
|
|
811
|
+
{{~ it.spec.constants :c}}
|
|
812
|
+
{{? c.type === "string"}}
|
|
813
|
+
Object.defineProperty({{=objectWrapper}}, "{{=c.name}}", {value: "{{=c.value}}", writable: false, enumerable: true, configurable: true});
|
|
814
|
+
{{??}}
|
|
815
|
+
Object.defineProperty({{=objectWrapper}}, "{{=c.name}}", {value: {{=c.value}}, writable: false, enumerable: true, configurable: true});
|
|
816
|
+
{{?}}
|
|
817
|
+
{{~}}
|
|
862
818
|
{{?}}
|
|
863
819
|
|
|
864
820
|
module.exports = {{=objectWrapper}};
|
|
865
821
|
|
|
822
|
+
{{? it.isDebug}}
|
|
866
823
|
/*
|
|
867
824
|
* The following is the original spec object coming from parser:
|
|
868
825
|
{{=it.json}}
|
|
869
826
|
*/
|
|
827
|
+
{{?}}
|
package/rostsd_gen/index.js
CHANGED
|
@@ -363,8 +363,8 @@ function isInternalServiceEventMsgInterface(rosMsgInterface) {
|
|
|
363
363
|
let subFolder = rosMsgInterface.type().subFolder;
|
|
364
364
|
// Some package puts .srv files under srvs/, e.g., slam_toolbox.
|
|
365
365
|
return (
|
|
366
|
-
(subFolder == 'srv' || subFolder == 'srvs' || subFolder == 'action')
|
|
367
|
-
|
|
366
|
+
(subFolder == 'srv' || subFolder == 'srvs' || subFolder == 'action') &&
|
|
367
|
+
name.endsWith('_Event')
|
|
368
368
|
);
|
|
369
369
|
}
|
|
370
370
|
|
package/scripts/npm-pack.sh
CHANGED
|
@@ -27,7 +27,7 @@ cp -f scripts/npmjs-readme.md $MODULEDIR/README.md
|
|
|
27
27
|
|
|
28
28
|
pushd . > /dev/null
|
|
29
29
|
cd $WORKDIR
|
|
30
|
-
FILENAME=`npm pack $RAWMODULEDIR`
|
|
30
|
+
FILENAME=`npm pack $RAWMODULEDIR | awk '{for(i=1; i<=NF; i++) if ($i ~ /rclnodejs-.*\.tgz/) print $i}'`
|
|
31
31
|
TARFILENAME="$WORKDIR/$FILENAME"
|
|
32
32
|
|
|
33
33
|
popd > /dev/null
|
package/scripts/npmjs-readme.md
CHANGED
|
@@ -43,9 +43,9 @@ npm i rclnodejs@x.y.z
|
|
|
43
43
|
|
|
44
44
|
#### RCLNODEJS - ROS 2 Version Compatibility
|
|
45
45
|
|
|
46
|
-
| RCLNODEJS Version |
|
|
47
|
-
| :------------------------------------------------------------------------------------------: |
|
|
48
|
-
| latest version (currently [v0.
|
|
46
|
+
| RCLNODEJS Version | Compatible ROS 2 LTS |
|
|
47
|
+
| :------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------: |
|
|
48
|
+
| latest version (currently [v0.28.1](https://github.com/RobotWebTools/rclnodejs/tree/0.28.1)) | [Humble](https://github.com/RobotWebTools/rclnodejs/tree/humble-hawksbill)<br>[Jazzy](https://github.com/RobotWebTools/rclnodejs/tree/jazzy) |
|
|
49
49
|
|
|
50
50
|
## Documentation
|
|
51
51
|
|