ROS 2 rclcpp + rcl - kilted  kilted
ROS 2 C++ Client Library with ROS Client Library
Public Member Functions | List of all members
rclcpp::SerializedMessage Class Reference

Object oriented version of rcl_serialized_message_t with destructor to avoid memory leaks. More...

#include <rclcpp/serialized_message.hpp>

Public Member Functions

 SerializedMessage (const rcl_allocator_t &allocator=rcl_get_default_allocator())
 Default constructor for a SerializedMessage. More...
 
 SerializedMessage (size_t initial_capacity, const rcl_allocator_t &allocator=rcl_get_default_allocator())
 Default constructor for a SerializedMessage. More...
 
 SerializedMessage (const SerializedMessage &other)
 Copy Constructor for a SerializedMessage.
 
 SerializedMessage (const rcl_serialized_message_t &other)
 Constructor for a SerializedMessage from a rcl_serialized_message_t.
 
 SerializedMessage (SerializedMessage &&other)
 Move Constructor for a SerializedMessage.
 
 SerializedMessage (rcl_serialized_message_t &&other)
 Constructor for a SerializedMessage from a moved rcl_serialized_message_t.
 
SerializedMessageoperator= (const SerializedMessage &other)
 Copy assignment operator.
 
SerializedMessageoperator= (const rcl_serialized_message_t &other)
 Copy assignment operator from a rcl_serialized_message_t.
 
SerializedMessageoperator= (SerializedMessage &&other)
 Move assignment operator.
 
SerializedMessageoperator= (rcl_serialized_message_t &&other)
 Move assignment operator from a rcl_serialized_message_t.
 
virtual ~SerializedMessage ()
 Destructor for a SerializedMessage.
 
rcl_serialized_message_tget_rcl_serialized_message ()
 Get the underlying rcl_serialized_t handle.
 
const rcl_serialized_message_tget_rcl_serialized_message () const
 
size_t size () const
 Get the size of the serialized data buffer. More...
 
size_t capacity () const
 Get the size of allocated memory for the data buffer. More...
 
void reserve (size_t capacity)
 Allocate memory in the data buffer. More...
 
rcl_serialized_message_t release_rcl_serialized_message ()
 Release the underlying rcl_serialized_message_t. More...
 

Detailed Description

Object oriented version of rcl_serialized_message_t with destructor to avoid memory leaks.

Definition at line 27 of file serialized_message.hpp.

Constructor & Destructor Documentation

◆ SerializedMessage() [1/2]

rclcpp::SerializedMessage::SerializedMessage ( const rcl_allocator_t allocator = rcl_get_default_allocator())
explicit

Default constructor for a SerializedMessage.

Object oriented version of rcl_serialized_message_t with destructor to avoid memory leaks.

Default constructs a serialized message and initalizes it with initial capacity of 0. The allocator defaults to rcl_get_default_allocator().

Parameters
[in]allocatorThe allocator to be used for the initialization.

Definition at line 48 of file serialized_message.cpp.

◆ SerializedMessage() [2/2]

rclcpp::SerializedMessage::SerializedMessage ( size_t  initial_capacity,
const rcl_allocator_t allocator = rcl_get_default_allocator() 
)
explicit

Default constructor for a SerializedMessage.

Default constructs a serialized message and initalizes it with the provided capacity. The allocator defaults to rcl_get_default_allocator().

Parameters
[in]initial_capacityThe amount of memory to be allocated.
[in]allocatorThe allocator to be used for the initialization.

Definition at line 52 of file serialized_message.cpp.

References RCL_RET_OK.

Member Function Documentation

◆ capacity()

size_t rclcpp::SerializedMessage::capacity ( ) const

Get the size of allocated memory for the data buffer.

Note, this is different from the amount of content in the buffer. This can be obtained via a call to size.

Definition at line 164 of file serialized_message.cpp.

Referenced by rclcpp::SerializationBase::deserialize_message(), and reserve().

Here is the caller graph for this function:

◆ release_rcl_serialized_message()

rcl_serialized_message_t rclcpp::SerializedMessage::release_rcl_serialized_message ( )

Release the underlying rcl_serialized_message_t.

The memory (i.e. the data buffer) of the serialized message will no longer be managed by this instance and the memory won't be deallocated on destruction.

Definition at line 177 of file serialized_message.cpp.

◆ reserve()

void rclcpp::SerializedMessage::reserve ( size_t  capacity)

Allocate memory in the data buffer.

The data buffer of the underlying rcl_serialized_message_t will be resized. This might change the data layout and invalidates all pointers to the data.

Definition at line 169 of file serialized_message.cpp.

References capacity(), and RCL_RET_OK.

Here is the call graph for this function:

◆ size()

size_t rclcpp::SerializedMessage::size ( ) const

Get the size of the serialized data buffer.

Note, this is different from the actual amount of allocated memory. This can be obtained via a call to capacity.

Definition at line 159 of file serialized_message.cpp.

Referenced by rclcpp::SerializationBase::deserialize_message().

Here is the caller graph for this function:

The documentation for this class was generated from the following files: