• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RobotWebTools / rclnodejs / 15771266924

20 Jun 2025 04:30AM UTC coverage: 84.672% (-0.06%) from 84.731%
15771266924

push

github

minggangw
Add RMW serialize and deserialize functions (#1173)

This PR introduces native and JavaScript-level serialization and deserialization for ROS 2 messages using RMW, complete with tests and helper functions.

- Adds C++ RMW bindings (`serialize`/`deserialize`) and registers them in the Node addon  
- Implements `Serialization` JS class and exports `serializeMessage`/`deserializeMessage` in `index.js`  
- Provides basic unit tests and fixes a naming typo (`destroyRawROS`)

Fix: #1172

770 of 999 branches covered (77.08%)

Branch coverage included in aggregate %.

9 of 11 new or added lines in 2 files covered. (81.82%)

1898 of 2152 relevant lines covered (88.2%)

3203.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.43
/lib/serialization.js
1
// Copyright (c) 2025, The Robot Web Tools Contributors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
'use strict';
16

17
const rclnodejs = require('bindings')('rclnodejs');
208✔
18

19
class Serialization {
20
  /**
21
   * Serialize a message to a buffer.
22
   * @param {object} message - The message to serialize.
23
   * @param {function} typeClass - The class of the message type to serialize.
24
   * @return {Buffer} The serialized message as a Buffer.
25
   */
26
  static serializeMessage(message, typeClass) {
27
    if (!(message instanceof typeClass)) {
24!
NEW
28
      throw new TypeError('Message must be a valid ros2 message type');
×
29
    }
30
    return rclnodejs.serialize(
24✔
31
      typeClass.type().pkgName,
32
      typeClass.type().subFolder,
33
      typeClass.type().interfaceName,
34
      message.serialize()
35
    );
36
  }
37

38
  /**
39
   * Deserialize a message from a buffer.
40
   * @param {Buffer} buffer - The buffer containing the serialized message.
41
   * @param {function} typeClass - The class of the message type to deserialize into.
42
   * @return {object} The deserialized message object.
43
   */
44
  static deserializeMessage(buffer, typeClass) {
45
    if (!(buffer instanceof Buffer)) {
24!
NEW
46
      throw new TypeError('Buffer is required for deserialization');
×
47
    }
48
    const rosMsg = new typeClass();
24✔
49
    rclnodejs.deserialize(
24✔
50
      typeClass.type().pkgName,
51
      typeClass.type().subFolder,
52
      typeClass.type().interfaceName,
53
      buffer,
54
      rosMsg.toRawROS()
55
    );
56
    return rosMsg;
24✔
57
  }
58
}
59

60
module.exports = Serialization;
208✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc