Skip to content

Commit

Permalink
Fix Header not being resolved to std_msgs/Header (#42)
Browse files Browse the repository at this point in the history
This is only the case for ROS1 where `Header` is treated as a special case. See see http://wiki.ros.org/msg#Fields.
  • Loading branch information
achim-k committed Nov 13, 2023
1 parent 7d70732 commit 396eccd
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/parse.ros1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
},
]);
});
});
3 changes: 3 additions & 0 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down

0 comments on commit 396eccd

Please sign in to comment.