From 396eccd410ed0f7285ae457e14b1b7c01574d592 Mon Sep 17 00:00:00 2001 From: Hans-Joachim Krauch Date: Mon, 13 Nov 2023 15:47:46 -0300 Subject: [PATCH] Fix `Header` not being resolved to `std_msgs/Header` (#42) This is only the case for ROS1 where `Header` is treated as a special case. See see http://wiki.ros.org/msg#Fields. --- src/parse.ros1.test.ts | 67 ++++++++++++++++++++++++++++++++++++++++++ src/parse.ts | 3 ++ 2 files changed, 70 insertions(+) diff --git a/src/parse.ros1.test.ts b/src/parse.ros1.test.ts index 36050a4..5229b0b 100644 --- a/src/parse.ros1.test.ts +++ b/src/parse.ros1.test.ts @@ -556,4 +556,71 @@ describe("fixupTypes", () => { }, ]); }); + + it("correctly resolves Header to std_msgs/Header", () => { + const messageDefinition = ` + StampedBool stamped_bool + ================================================================================ + MSG: custom_msg/StampedBool + Header header + bool data + ================================================================================ + MSG: std_msgs/Header + uint32 seq + time stamp + string frame_id`; + const types = parse(messageDefinition); + expect(types).toEqual([ + { + definitions: [ + { + type: "custom_msg/StampedBool", + isArray: false, + name: "stamped_bool", + isComplex: true, + }, + ], + }, + { + name: "custom_msg/StampedBool", + definitions: [ + { + type: "std_msgs/Header", + isArray: false, + name: "header", + isComplex: true, + }, + { + type: "bool", + isArray: false, + name: "data", + isComplex: false, + }, + ], + }, + { + name: "std_msgs/Header", + definitions: [ + { + type: "uint32", + isArray: false, + name: "seq", + isComplex: false, + }, + { + type: "time", + isArray: false, + name: "stamp", + isComplex: false, + }, + { + type: "string", + isArray: false, + name: "frame_id", + isComplex: false, + }, + ], + }, + ]); + }); }); diff --git a/src/parse.ts b/src/parse.ts index ebf632b..408c421 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -154,6 +154,9 @@ function findTypeByName( if (name.includes("/")) { // Fully-qualified name, match exact return typeName === name; + } else if (name === "Header") { + // Header is a special case, see http://wiki.ros.org/msg#Fields + return typeName === `std_msgs/Header`; } else if (typeNamespace) { // Type namespace is given, create fully-qualified name and match exact return typeName === `${typeNamespace}/${name}`;