Skip to content

Commit

Permalink
Refs #20310: Review 2 suggestions on rosidl_typesupport_fastrtps_cpp
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Dominguez <[email protected]>
  • Loading branch information
Mario-DL committed Feb 28, 2024
1 parent f7c21dc commit 7b9c81a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// Holds generated methods related with keys
typedef struct message_type_support_key_callbacks_t
{
/// Callback function for message serialization
/// Callback function for key serialization
/**
* \param[in] untyped_ros_message Type erased pointer to message instance.
* \param [in,out] Serialized FastCDR data object.
Expand All @@ -39,10 +39,10 @@ typedef struct message_type_support_key_callbacks_t
const void * untyped_ros_message,
eprosima::fastcdr::Cdr & cdr);

/// Callback function for message deserialization
/// Callback function for key deserialization
/**
* \param [in] Serialized FastCDR data object.
* \param[out] untyped_ros_message Type erased pointer to message instance.
* \param [out] untyped_ros_message Type erased pointer to message instance.
* \return true if deserialization succeeded, false otherwise.
*/
bool (* cdr_deserialize_key)(
Expand All @@ -51,21 +51,19 @@ typedef struct message_type_support_key_callbacks_t

/// Callback function to get size of the key data
/**
* \return The size of the serialized message in bytes.
* \param [in] untyped_ros_message Type erased pointer to message instance
* \return The size of the serialized key in bytes.
*/
size_t (* get_serialized_size_key)(
const void * untyped_ros_message,
size_t initial_alignment);
const void * untyped_ros_message);

/// Callback function to determine the maximum size needed for key serialization,
/// which is used for key type support initialization.
/**
* \param [in] initial_alignment Initial alignment to be incrementally calculated.
* \param [in,out] is_unbounded Whether the key has any unbounded member.
* \return The maximum key serialized size, in bytes.
*/
size_t (* max_serialized_size_key)(
size_t initial_aligment,
bool & is_unbounded);

} message_type_support_key_callbacks_t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ header_files = [
#include "@(header_file)"
@[end for]@

struct message_type_support_key_callbacks_t;
@[for ns in message.structure.namespaced_type.namespaces]@

namespace @(ns)
Expand Down
25 changes: 19 additions & 6 deletions rosidl_typesupport_fastrtps_cpp/resource/msg__type_support.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ namespace @(ns)
namespace typesupport_fastrtps_cpp
{
@{

# Generates the definition for the serialization family of methods given a structure member
# member: the member to serialize
# suffix: the suffix name of the method. Will be used in case of recursion

def generate_member_for_cdr_serialize(member, suffix):
from rosidl_generator_cpp import msg_type_only_to_cpp
from rosidl_generator_cpp import msg_type_to_cpp
Expand Down Expand Up @@ -312,6 +317,11 @@ cdr_deserialize(
}

@{

# Generates the definition for the get_serialized_size family of methods given a structure member
# member: the member to serialize
# suffix: the suffix name of the method. Will be used in case of recursion

def generate_member_for_get_serialized_size(member, suffix):
from rosidl_generator_cpp import msg_type_only_to_cpp
from rosidl_generator_cpp import msg_type_to_cpp
Expand Down Expand Up @@ -401,6 +411,11 @@ get_serialized_size(
}

@{

# Generates the definition for the max_serialized_size family of methods given a structure member
# member: the member to serialize
# suffix: the suffix name of the method. Will be used in case of recursion

def generate_member_for_max_serialized_size(member, suffix):
from rosidl_generator_cpp import msg_type_only_to_cpp
from rosidl_generator_cpp import msg_type_to_cpp
Expand Down Expand Up @@ -530,7 +545,7 @@ cdr_deserialize_key(
{
(void)ros_message;
(void)cdr;

// TODO
return false;
}

Expand Down Expand Up @@ -616,18 +631,16 @@ _@(message.structure.namespaced_type.name)__cdr_deserialize_key(
static
size_t
_@(message.structure.namespaced_type.name)__get_serialized_size_key(
const void * untyped_ros_message,
size_t initial_alignment)
const void * untyped_ros_message)
{
auto typed_message =
static_cast<const @('::'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.namespaced_type.name])) *>(
untyped_ros_message);

return static_cast<uint32_t>(get_serialized_size_key(*typed_message, initial_alignment));
return get_serialized_size_key(*typed_message, 0);
}

static size_t _@(message.structure.namespaced_type.name)__max_serialized_size_key(
size_t current_alignment,
bool & is_unbounded)
{
bool full_bounded = true;
Expand All @@ -636,7 +649,7 @@ static size_t _@(message.structure.namespaced_type.name)__max_serialized_size_ke
size_t ret_val = max_serialized_size_key_@(message.structure.namespaced_type.name)(
full_bounded,
is_plain,
current_alignment);
0);

is_unbounded = !full_bounded;
return ret_val;
Expand Down

0 comments on commit 7b9c81a

Please sign in to comment.