Skip to content

Commit

Permalink
Change generated code in rosidl_typesupport_fastrtps_cpp
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
  • Loading branch information
MiguelCompany committed Feb 26, 2024
1 parent 221cd95 commit 7f79e20
Showing 1 changed file with 9 additions and 29 deletions.
38 changes: 9 additions & 29 deletions rosidl_typesupport_fastrtps_cpp/resource/msg__type_support.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,13 @@ cdr_serialize(
@[ if not isinstance(member.type.value_type, (NamespacedType, AbstractWString))]@
cdr << ros_message.@(member.name);
@[ else]@
@[ if isinstance(member.type.value_type, AbstractWString)]@
std::wstring wstr;
@[ end if]@
for (size_t i = 0; i < @(member.type.size); i++) {
@[ if isinstance(member.type.value_type, NamespacedType)]@
@('::'.join(member.type.value_type.namespaces))::typesupport_fastrtps_cpp::cdr_serialize(
ros_message.@(member.name)[i],
cdr);
@[ else]@
rosidl_typesupport_fastrtps_cpp::u16string_to_wstring(ros_message.@(member.name)[i], wstr);
cdr << wstr;
rosidl_typesupport_fastrtps_cpp::cdr_serialize(cdr, ros_message.@(member.name)[i]);
@[ end if]@
}
@[ end if]@
Expand All @@ -138,17 +134,13 @@ cdr_serialize(
cdr.serializeArray(&(ros_message.@(member.name)[0]), size);
}
@[ else]@
@[ if isinstance(member.type.value_type, AbstractWString)]@
std::wstring wstr;
@[ end if]@
for (size_t i = 0; i < size; i++) {
@[ if isinstance(member.type.value_type, BasicType) and member.type.value_type.typename == 'boolean']@
cdr << (ros_message.@(member.name)[i] ? true : false);
@[ elif isinstance(member.type.value_type, BasicType) and member.type.value_type.typename == 'wchar']@
cdr << static_cast<wchar_t>(ros_message.@(member.name)[i]);
@[ elif isinstance(member.type.value_type, AbstractWString)]@
rosidl_typesupport_fastrtps_cpp::u16string_to_wstring(ros_message.@(member.name)[i], wstr);
cdr << wstr;
rosidl_typesupport_fastrtps_cpp::cdr_serialize(cdr, ros_message.@(member.name)[i]);
@[ elif not isinstance(member.type.value_type, NamespacedType)]@
cdr << ros_message.@(member.name)[i];
@[ else]@
Expand All @@ -167,9 +159,7 @@ cdr_serialize(
cdr << static_cast<wchar_t>(ros_message.@(member.name));
@[ elif isinstance(member.type, AbstractWString)]@
{
std::wstring wstr;
rosidl_typesupport_fastrtps_cpp::u16string_to_wstring(ros_message.@(member.name), wstr);
cdr << wstr;
rosidl_typesupport_fastrtps_cpp::cdr_serialize(cdr, ros_message.@(member.name));
}
@[ elif not isinstance(member.type, NamespacedType)]@
cdr << ros_message.@(member.name);
Expand All @@ -196,19 +186,15 @@ cdr_deserialize(
@[ if not isinstance(member.type.value_type, (NamespacedType, AbstractWString))]@
cdr >> ros_message.@(member.name);
@[ else]@
@[ if isinstance(member.type.value_type, AbstractWString)]@
std::wstring wstr;
@[ end if]@
for (size_t i = 0; i < @(member.type.size); i++) {
@[ if isinstance(member.type.value_type, NamespacedType)]@
@('::'.join(member.type.value_type.namespaces))::typesupport_fastrtps_cpp::cdr_deserialize(
cdr,
ros_message.@(member.name)[i]);
@[ else]@
cdr >> wstr;
bool succeeded = rosidl_typesupport_fastrtps_cpp::wstring_to_u16string(wstr, ros_message.@(member.name)[i]);
bool succeeded = rosidl_typesupport_fastrtps_cpp::cdr_deserialize(cdr, ros_message.@(member.name)[i]);
if (!succeeded) {
fprintf(stderr, "failed to create wstring from u16string\n");
fprintf(stderr, "failed to deserialize u16string\n");
return false;
}
@[ end if]@
Expand All @@ -227,9 +213,6 @@ cdr_deserialize(
cdr.deserializeArray(&(ros_message.@(member.name)[0]), size);
}
@[ else]@
@[ if isinstance(member.type.value_type, AbstractWString)]@
std::wstring wstr;
@[ end if]@
for (size_t i = 0; i < size; i++) {
@[ if isinstance(member.type.value_type, BasicType) and member.type.value_type.typename == 'boolean']@
uint8_t tmp;
Expand All @@ -240,10 +223,9 @@ cdr_deserialize(
cdr >> tmp;
ros_message.@(member.name)[i] = static_cast<char16_t>(tmp);
@[ elif isinstance(member.type.value_type, AbstractWString)]@
cdr >> wstr;
bool succeeded = rosidl_typesupport_fastrtps_cpp::wstring_to_u16string(wstr, ros_message.@(member.name)[i]);
bool succeeded = rosidl_typesupport_fastrtps_cpp::cdr_deserialize(cdr, ros_message.@(member.name)[i]);
if (!succeeded) {
fprintf(stderr, "failed to create wstring from u16string\n");
fprintf(stderr, "failed to deserialize u16string\n");
return false;
}
@[ elif not isinstance(member.type.value_type, NamespacedType)]@
Expand Down Expand Up @@ -271,11 +253,9 @@ cdr_deserialize(
}
@[ elif isinstance(member.type, AbstractWString)]@
{
std::wstring wstr;
cdr >> wstr;
bool succeeded = rosidl_typesupport_fastrtps_cpp::wstring_to_u16string(wstr, ros_message.@(member.name));
bool succeeded = rosidl_typesupport_fastrtps_cpp::cdr_deserialize(cdr, ros_message.@(member.name));
if (!succeeded) {
fprintf(stderr, "failed to create wstring from u16string\n");
fprintf(stderr, "failed to deserialize u16string\n");
return false;
}
}
Expand Down

0 comments on commit 7f79e20

Please sign in to comment.