15 #include "rclcpp/serialization.hpp"
20 #include "rclcpp/exceptions.hpp"
21 #include "rclcpp/serialized_message.hpp"
23 #include "rcpputils/asserts.hpp"
31 : type_support_(type_support)
33 rcpputils::check_true(
nullptr != type_support,
"Typesupport is nullpointer.");
39 rcpputils::check_true(
nullptr != ros_message,
"ROS message is nullpointer.");
40 rcpputils::check_true(
nullptr != serialized_message,
"Serialized message is nullpointer.");
42 const auto ret = rmw_serialize(
46 if (ret != RMW_RET_OK) {
47 rclcpp::exceptions::throw_from_rcl_error(ret,
"Failed to serialize ROS message.");
54 rcpputils::check_true(
nullptr != serialized_message,
"Serialized message is nullpointer.");
55 rcpputils::check_true(
56 0u != serialized_message->
capacity(),
57 "Wrongly initialized. Serialized message has a capacity of zero.");
58 rcpputils::check_true(
59 0u != serialized_message->
size(),
60 "Wrongly initialized. Serialized message has a size of zero.");
61 rcpputils::check_true(
nullptr != ros_message,
"ROS message is a nullpointer.");
63 const auto ret = rmw_deserialize(
65 if (ret != RMW_RET_OK) {
66 rclcpp::exceptions::throw_from_rcl_error(ret,
"Failed to deserialize ROS message.");
SerializationBase(const rosidl_message_type_support_t *type_support)
Constructor of SerializationBase.
void serialize_message(const void *ros_message, SerializedMessage *serialized_message) const
Serialize a ROS2 message to a serialized stream.
void deserialize_message(const SerializedMessage *serialized_message, void *ros_message) const
Deserialize a serialized stream to a ROS message.
Object oriented version of rcl_serialized_message_t with destructor to avoid memory leaks.
size_t size() const
Get the size of the serialized data buffer.
rcl_serialized_message_t & get_rcl_serialized_message()
Get the underlying rcl_serialized_t handle.
size_t capacity() const
Get the size of allocated memory for the data buffer.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.