Skip to content

Commit

Permalink
[SkyMarshal] Fix printing char-like things
Browse files Browse the repository at this point in the history
The LCM boolean, int8_t, uint8_t, and byte are aliases of signed or
unsigned char in C++, so they get printed as ascii 0/1/etc, which is
silly, especially since ascii 0 and 1 aren't even printable characters.
Print bools as bools, and the others as ints.  LCM doesn't have a char
type, so if you wanted that you're out of luck.

Topic: skymarshal-print-bools
Reviewers: nikhil,peter,danny
GitOrigin-RevId: a640504b22f5af0fd523f51f32799e9d1bc44198
  • Loading branch information
aaron-skydio committed Sep 1, 2023
1 parent d2c7d54 commit 45249fb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions third_party/skymarshal/skymarshal/templates/lcmtype.hpp.template
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,13 @@ class {{lcmtype.name}}
{% if member.dims | length == 1 %}
stream << "{{member.name}}=[";
for (size_t i = 0; i < obj.{{member.name}}.size(); ++i) {
{% if member.type_ref.name == "boolean" %}
stream << (obj.{{member.name}}[i] ? "true" : "false");
{% elif member.type_ref.name in ("int8_t", "uint8_t", "byte") %}
stream << static_cast<int16_t>(obj.{{member.name}}[i]);
{% else %}
stream << obj.{{member.name}}[i];
{% endif %}
if (i + 1 < obj.{{member.name}}.size()) {
stream << ", ";
}
Expand All @@ -155,6 +161,10 @@ class {{lcmtype.name}}
{# Multidimensional arrays will require some complicated stuff #}
stream << "{{member.name}}=<MULTIDIMENSIONAL ARRAY {{ array_type_str(member) }}>"{{ comma(loop.last) }};
{% endif %}
{% elif member.type_ref.name == "boolean" %}
stream << "{{member.name}}=" << (obj.{{member.name}} ? "true" : "false"){{ comma(loop.last) }};
{% elif member.type_ref.name in ("int8_t", "uint8_t", "byte") %}
stream << "{{member.name}}=" << static_cast<int16_t>(obj.{{member.name}}){{ comma(loop.last) }};
{% else %}
stream << "{{member.name}}=" << obj.{{member.name}}{{ comma(loop.last) }};
{% endif %}
Expand Down

0 comments on commit 45249fb

Please sign in to comment.