From 45249fb4d514dbe5ef7623e2116aa1ee0ebc98b6 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 29 Aug 2023 07:13:00 +0000 Subject: [PATCH] [SkyMarshal] Fix printing char-like things 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 --- .../skymarshal/templates/lcmtype.hpp.template | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/third_party/skymarshal/skymarshal/templates/lcmtype.hpp.template b/third_party/skymarshal/skymarshal/templates/lcmtype.hpp.template index 719530cc9..bcf90e256 100644 --- a/third_party/skymarshal/skymarshal/templates/lcmtype.hpp.template +++ b/third_party/skymarshal/skymarshal/templates/lcmtype.hpp.template @@ -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(obj.{{member.name}}[i]); + {% else %} stream << obj.{{member.name}}[i]; + {% endif %} if (i + 1 < obj.{{member.name}}.size()) { stream << ", "; } @@ -155,6 +161,10 @@ class {{lcmtype.name}} {# Multidimensional arrays will require some complicated stuff #} stream << "{{member.name}}="{{ 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(obj.{{member.name}}){{ comma(loop.last) }}; {% else %} stream << "{{member.name}}=" << obj.{{member.name}}{{ comma(loop.last) }}; {% endif %}