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

RobotWebTools / rclnodejs / 19071410104

04 Nov 2025 02:08PM UTC coverage: 83.072% (+0.4%) from 82.711%
19071410104

Pull #1320

github

web-flow
Merge 9cad4567e into 3ad842cc4
Pull Request #1320: feat: add structured error handling with class error hierarchy

1032 of 1365 branches covered (75.6%)

Branch coverage included in aggregate %.

161 of 239 new or added lines in 25 files covered. (67.36%)

29 existing lines in 1 file now uncovered.

2354 of 2711 relevant lines covered (86.83%)

459.93 hits per line

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

73.33
/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('./native_loader.js');
26✔
18
const { TypeValidationError } = require('./errors.js');
26✔
19

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

41
  /**
42
   * Deserialize a message from a buffer.
43
   * @param {Buffer} buffer - The buffer containing the serialized message.
44
   * @param {function} typeClass - The class of the message type to deserialize into.
45
   * @return {object} The deserialized message object.
46
   */
47
  static deserializeMessage(buffer, typeClass) {
48
    if (!(buffer instanceof Buffer)) {
3!
NEW
49
      throw new TypeValidationError('buffer', buffer, 'Buffer', {
×
50
        entityType: 'serializer',
51
      });
52
    }
53
    const rosMsg = new typeClass();
3✔
54
    rclnodejs.deserialize(
3✔
55
      typeClass.type().pkgName,
56
      typeClass.type().subFolder,
57
      typeClass.type().interfaceName,
58
      buffer,
59
      rosMsg.toRawROS()
60
    );
61
    return rosMsg;
3✔
62
  }
63
}
64

65
module.exports = Serialization;
26✔
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