rmw  master
C API providing a middleware abstraction layer which is used to implement the rest of ROS.
Functions
serialized_message.h File Reference
#include "rcutils/allocator.h"
#include "rmw/macros.h"
#include "rmw/types.h"
#include "rmw/visibility_control.h"

Go to the source code of this file.

Functions

rmw_serialized_message_t rmw_get_zero_initialized_serialized_message (void)
 Return a zero initialized serialized message struct. More...
 
rmw_ret_t rmw_serialized_message_init (rmw_serialized_message_t *msg, size_t buffer_capacity, const rcutils_allocator_t *allocator)
 Initialize a zero initialized serialized message struct. More...
 
rmw_ret_t rmw_serialized_message_fini (rmw_serialized_message_t *msg)
 Finalize a serialized message struct. More...
 
rmw_ret_t rmw_serialized_message_resize (rmw_serialized_message_t *msg, size_t new_size)
 Resize the internal buffer for the message byte stream. More...
 

Function Documentation

◆ rmw_get_zero_initialized_serialized_message()

rmw_serialized_message_t rmw_get_zero_initialized_serialized_message ( void  )

Return a zero initialized serialized message struct.

Returns
rmw_serialized_message_t a zero initialized serialized message struct

◆ rmw_serialized_message_init()

rmw_ret_t rmw_serialized_message_init ( rmw_serialized_message_t msg,
size_t  buffer_capacity,
const rcutils_allocator_t allocator 
)

Initialize a zero initialized serialized message struct.

This function may leak if the serialized message struct is already pre-initialized. If the capacity is set to 0, no memory is allocated and the internal buffer is still NULL.

Parameters
msga pointer to the to be initialized serialized message struct
buffer_capacitythe size of the memory to allocate for the byte stream
allocatorthe allocator to use for the memory allocation
Returns
RMW_RET_OK if successful, or
RMW_RET_ERROR if an unexpected error occurs

◆ rmw_serialized_message_fini()

rmw_ret_t rmw_serialized_message_fini ( rmw_serialized_message_t msg)

Finalize a serialized message struct.

Cleans up and deallocates any resources used in a rmw_message_serialized_t. Passing a rmw_serialized_message_t which has not been zero initialized using rmw_get_zero_initialized_serialized_message() to this function is undefined behavior.

Parameters
msgpointer to the serialized message to be cleaned up
Returns
RMW_RET_OK if successful, or
RMW_RET_BAD_ALLOC if memory allocation failed, or
RMW_RET_ERROR if an unexpected error occurs

◆ rmw_serialized_message_resize()

rmw_ret_t rmw_serialized_message_resize ( rmw_serialized_message_t msg,
size_t  new_size 
)

Resize the internal buffer for the message byte stream.

The internal buffer of the serialized message can be resized dynamically if needed. If the new size is smaller than the current capacity, then the memory is truncated. Be aware, that this will deallocate the memory and therefore invalidates any pointers to this storage. If the new size is larger, new memory is getting allocated and the existing content is copied over.

Parameters
msgpointer to the instance of rmw_serialized_message_t which is being resized
new_sizethe new size of the internal buffer
Returns
RMW_RET_OK if successful, or
RMW_RET_BAD_ALLOC if memory allocation failed, or
RMW_RET_ERROR if an unexpected error occurs