Skip to content

Commit a053eed

Browse files
committed
added example for partial message conversion
Signed-off-by: Dominik Authaler <[email protected]>
1 parent 7b762e9 commit a053eed

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test_dynmsg/examples/conversion_cpp.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,20 @@ int main()
6262
printf("%s\n", msg_from_yaml.frame_id.c_str());
6363
printf("%d s, %d ns\n", msg_from_yaml.stamp.sec, msg_from_yaml.stamp.nanosec);
6464

65+
printf("\n");
66+
67+
// Note: In case only a portion of the message is of interest, it is also possible to limit the conversion
68+
// to this part of the message. This can be beneficial if only a few members of large messages are
69+
// further processed (e.g. width and height fields of a Pointcloud2 message without further need for obtaining
70+
// detailed information about the individual points).
71+
YAML::Node partial_yaml_msg = dynmsg::cpp::selected_member_to_yaml(ros_msg, "stamp");
72+
const std::string partial_yaml_string = dynmsg::yaml_to_string(partial_yaml_msg);
73+
74+
// Prints solely the 'stamp' sub-message (but also works for extracting values of individual message fields
75+
// which are not a message on their own)
76+
// sec: 4
77+
// nanosec: 20
78+
printf("%s\n", partial_yaml_string.c_str());
79+
6580
return 0;
6681
}

0 commit comments

Comments
 (0)