Skip to content

Commit

Permalink
Fastdds type support extensions (#67)
Browse files Browse the repository at this point in the history
* Extend max_serialized_size interface to account for plain types.

Signed-off-by: Miguel Company <[email protected]>
  • Loading branch information
MiguelCompany authored May 11, 2021
1 parent c043df4 commit 748be56
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ size_t get_serialized_size_@('__'.join([package_name] + list(interface_path.pare
ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(package_name)
size_t max_serialized_size_@('__'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.namespaced_type.name]))(
bool & full_bounded,
bool & is_plain,
size_t current_alignment);

ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(package_name)
Expand Down
30 changes: 25 additions & 5 deletions rosidl_typesupport_fastrtps_c/resource/msg__type_support_c.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT_@(package_name)
@[ end if]@
size_t max_serialized_size_@('__'.join(key))(
bool & full_bounded,
bool & is_plain,
size_t current_alignment);

@[ if key[0] != package_name]@
Expand Down Expand Up @@ -508,6 +509,7 @@ static uint32_t _@(message.structure.namespaced_type.name)__get_serialized_size(
ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(package_name)
size_t max_serialized_size_@('__'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.namespaced_type.name]))(
bool & full_bounded,
bool & is_plain,
size_t current_alignment)
{
size_t initial_alignment = current_alignment;
Expand All @@ -516,7 +518,9 @@ size_t max_serialized_size_@('__'.join([package_name] + list(interface_path.pare
const size_t wchar_size = 4;
(void)padding;
(void)wchar_size;
(void)full_bounded;

full_bounded = true;
is_plain = true;

@[for member in message.structure.members]@
// member: @(member.name)
Expand All @@ -526,11 +530,13 @@ size_t max_serialized_size_@('__'.join([package_name] + list(interface_path.pare
size_t array_size = @(member.type.size);
@[ elif isinstance(member.type, BoundedSequence)]@
size_t array_size = @(member.type.maximum_size);
is_plain = false;
@[ else]@
size_t array_size = 0;
@[ end if]@
@[ if isinstance(member.type, AbstractSequence)]@
full_bounded = false;
is_plain = false;
current_alignment += padding +
eprosima::fastcdr::Cdr::alignment(current_alignment, padding);
@[ end if]@
Expand All @@ -545,6 +551,7 @@ if isinstance(type_, AbstractNestedType):
}@
@[ if isinstance(type_, AbstractGenericString)]@
full_bounded = false;
is_plain = false;
for (size_t index = 0; index < array_size; ++index) {
current_alignment += padding +
eprosima::fastcdr::Cdr::alignment(current_alignment, padding) +
Expand Down Expand Up @@ -577,9 +584,13 @@ if isinstance(type_, AbstractNestedType):
@[ end if]@
@[ else]
for (size_t index = 0; index < array_size; ++index) {
bool inner_full_bounded;
bool inner_is_plain;
current_alignment +=
max_serialized_size_@('__'.join(type_.namespaced_name()))(
full_bounded, current_alignment);
inner_full_bounded, inner_is_plain, current_alignment);
full_bounded &= inner_full_bounded;
is_plain &= inner_is_plain;
}
@[ end if]@
}
Expand All @@ -588,10 +599,19 @@ if isinstance(type_, AbstractNestedType):
return current_alignment - initial_alignment;
}

static size_t _@(message.structure.namespaced_type.name)__max_serialized_size(bool & full_bounded)
static size_t _@(message.structure.namespaced_type.name)__max_serialized_size(char & bounds_info)
{
return max_serialized_size_@('__'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.namespaced_type.name]))(
full_bounded, 0);
bool full_bounded;
bool is_plain;
size_t ret_val;

ret_val = max_serialized_size_@('__'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.namespaced_type.name]))(
full_bounded, is_plain, 0);

bounds_info =
is_plain ? ROSIDL_TYPESUPPORT_FASTRTPS_PLAIN_TYPE :
full_bounded ? ROSIDL_TYPESUPPORT_FASTRTPS_BOUNDED_TYPE : ROSIDL_TYPESUPPORT_FASTRTPS_UNBOUNDED_TYPE;
return ret_val;
}

@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

#include <fastcdr/Cdr.h>

/// Feature define to allow API version detection
#define ROSIDL_TYPESUPPORT_FASTRTPS_HAS_PLAIN_TYPES

#define ROSIDL_TYPESUPPORT_FASTRTPS_UNBOUNDED_TYPE 0x00
#define ROSIDL_TYPESUPPORT_FASTRTPS_BOUNDED_TYPE 0x01
#define ROSIDL_TYPESUPPORT_FASTRTPS_PLAIN_TYPE 0x03

/// Encapsulates the callbacks for getting properties of this rosidl type.
/**
* These callbacks are implemented in the generated sources.
Expand Down Expand Up @@ -60,11 +67,15 @@ typedef struct message_type_support_callbacks_t
/// Callback function to determine the maximum size needed for serialization, which is used for
/// type support initialization.
/**
* \param[out] Whether the maximum serialized size was fully bounded, (i.e. not unbounded strings
* or sequences).
* \param[out] bounds_info Bounds information for the type.
* May return one of the following values:
* - \c ROSIDL_TYPESUPPORT_FASTRTPS_PLAIN_TYPE for POD types
* - \c ROSIDL_TYPESUPPORT_FASTRTPS_BOUNDED_TYPE for fully bounded types,
* (i.e. not unbounded strings or sequences).
* - \c ROSIDL_TYPESUPPORT_FASTRTPS_UNBOUNDED_TYPE for unbounded types
* \return The maximum serialized size, in bytes.
*/
size_t (* max_serialized_size)(bool & full_bounded);
size_t (* max_serialized_size)(char & bounds_info);
} message_type_support_callbacks_t;

#endif // ROSIDL_TYPESUPPORT_FASTRTPS_CPP__MESSAGE_TYPE_SUPPORT_H_
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ size_t
ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(package_name)
max_serialized_size_@(message.structure.namespaced_type.name)(
bool & full_bounded,
bool & is_plain,
size_t current_alignment);

} // namespace typesupport_fastrtps_cpp
Expand Down
28 changes: 24 additions & 4 deletions rosidl_typesupport_fastrtps_cpp/resource/msg__type_support.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ size_t get_serialized_size(
size_t
max_serialized_size_@(type_.name)(
bool & full_bounded,
bool & is_plain,
size_t current_alignment);
} // namespace typesupport_fastrtps_cpp
@[ for ns in reversed(type_.namespaces)]@
Expand Down Expand Up @@ -346,6 +347,7 @@ size_t
ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(package_name)
max_serialized_size_@(message.structure.namespaced_type.name)(
bool & full_bounded,
bool & is_plain,
size_t current_alignment)
{
size_t initial_alignment = current_alignment;
Expand All @@ -354,7 +356,9 @@ max_serialized_size_@(message.structure.namespaced_type.name)(
const size_t wchar_size = 4;
(void)padding;
(void)wchar_size;
(void)full_bounded;

full_bounded = true;
is_plain = true;

@[for member in message.structure.members]@

Expand All @@ -365,11 +369,13 @@ max_serialized_size_@(message.structure.namespaced_type.name)(
size_t array_size = @(member.type.size);
@[ elif isinstance(member.type, BoundedSequence)]@
size_t array_size = @(member.type.maximum_size);
is_plain = false;
@[ else]@
size_t array_size = 0;
@[ end if]@
@[ if isinstance(member.type, AbstractSequence)]@
full_bounded = false;
is_plain = false;
current_alignment += padding +
eprosima::fastcdr::Cdr::alignment(current_alignment, padding);
@[ end if]@
Expand All @@ -384,6 +390,7 @@ if isinstance(type_, AbstractNestedType):
}@
@[ if isinstance(type_, AbstractGenericString)]@
full_bounded = false;
is_plain = false;
for (size_t index = 0; index < array_size; ++index) {
current_alignment += padding +
eprosima::fastcdr::Cdr::alignment(current_alignment, padding) +
Expand Down Expand Up @@ -416,9 +423,13 @@ if isinstance(type_, AbstractNestedType):
@[ end if]@
@[ else]
for (size_t index = 0; index < array_size; ++index) {
bool inner_full_bounded;
bool inner_is_plain;
current_alignment +=
@('::'.join(type_.namespaces))::typesupport_fastrtps_cpp::max_serialized_size_@(type_.name)(
full_bounded, current_alignment);
inner_full_bounded, inner_is_plain, current_alignment);
full_bounded &= inner_full_bounded;
is_plain &= inner_is_plain;
}
@[ end if]@
}
Expand Down Expand Up @@ -456,9 +467,18 @@ static uint32_t _@(message.structure.namespaced_type.name)__get_serialized_size(
return static_cast<uint32_t>(get_serialized_size(*typed_message, 0));
}

static size_t _@(message.structure.namespaced_type.name)__max_serialized_size(bool & full_bounded)
static size_t _@(message.structure.namespaced_type.name)__max_serialized_size(char & bounds_info)
{
return max_serialized_size_@(message.structure.namespaced_type.name)(full_bounded, 0);
bool full_bounded;
bool is_plain;
size_t ret_val;

ret_val = max_serialized_size_@(message.structure.namespaced_type.name)(full_bounded, is_plain, 0);

bounds_info =
is_plain ? ROSIDL_TYPESUPPORT_FASTRTPS_PLAIN_TYPE :
full_bounded ? ROSIDL_TYPESUPPORT_FASTRTPS_BOUNDED_TYPE : ROSIDL_TYPESUPPORT_FASTRTPS_UNBOUNDED_TYPE;
return ret_val;
}

static message_type_support_callbacks_t _@(message.structure.namespaced_type.name)__callbacks = {
Expand Down

0 comments on commit 748be56

Please sign in to comment.