Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rmw serialized to rcutils serialized #145

Merged
merged 3 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rmw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ set(rmw_sources
"src/convert_rcutils_ret_to_rmw_ret.c"
"src/error_handling.c"
"src/names_and_types.c"
"src/serialized_message.c"
"src/sanity_checks.c"
"src/node_security_options.c"
"src/validate_full_topic_name.c"
Expand Down
81 changes: 8 additions & 73 deletions rmw/include/rmw/serialized_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,79 +20,14 @@ extern "C"
{
#endif

#include "rcutils/allocator.h"

#include "rmw/macros.h"
#include "rmw/types.h"
#include "rmw/visibility_control.h"

/// Return a zero initialized serialized message struct.
/**
* \return rmw_serialized_message_t a zero initialized serialized message struct
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_serialized_message_t
rmw_get_zero_initialized_serialized_message(void);

/// 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.
*
* \param msg a pointer to the to be initialized serialized message struct
* \param buffer_capacity the size of the memory to allocate for the byte stream
* \param allocator the allocator to use for the memory allocation
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_ERROR` if an unexpected error occurs
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_serialized_message_init(
rmw_serialized_message_t * msg,
size_t buffer_capacity,
const rcutils_allocator_t * allocator);

/// 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.
*
* \param msg pointer to the serialized message to be cleaned up
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_BAD_ALLOC` if memory allocation failed, or
* \return `RMW_RET_ERROR` if an unexpected error occurs
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_serialized_message_fini(rmw_serialized_message_t * msg);

/// 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.
*
* \param msg pointer to the instance of rmw_serialized_message_t which is being resized
* \param new_size the new size of the internal buffer
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_BAD_ALLOC` if memory allocation failed, or
* \return `RMW_RET_ERROR` if an unexpected error occurs
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_serialized_message_resize(rmw_serialized_message_t * msg, size_t new_size);
#include "rcutils/types/serialized_message.h"

// aliases for rcutils_serialized_message_t
typedef rcutils_serialized_message_t rmw_serialized_message_t;
#define rmw_get_zero_initialized_serialized_message rcutils_get_zero_initialized_serialized_message
#define rmw_serialized_message_init rcutils_serialized_message_init
#define rmw_serialized_message_fini rcutils_serialized_message_fini
#define rmw_serialized_message_resize rcutils_serialized_message_resize

#if __cplusplus
}
Expand Down
10 changes: 1 addition & 9 deletions rmw/include/rmw/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern "C"
// map rcutils specific log levels to rmw speicfic type
#include <rcutils/logging.h>

#include "rmw/serialized_message.h"
#include "rmw/visibility_control.h"

typedef int rmw_ret_t;
Expand Down Expand Up @@ -222,15 +223,6 @@ typedef struct RMW_PUBLIC_TYPE rmw_gid_t
uint8_t data[RMW_GID_STORAGE_SIZE];
} rmw_gid_t;

typedef struct RMW_PUBLIC_TYPE rmw_serialized_message_t
{
// serialized message data
char * buffer;
size_t buffer_length;
size_t buffer_capacity;
rcutils_allocator_t allocator;
} rmw_serialized_message_t;

typedef struct RMW_PUBLIC_TYPE rmw_message_info_t
{
// const rmw_time_t received_timestamp;
Expand Down
115 changes: 0 additions & 115 deletions rmw/src/serialized_message.c

This file was deleted.

2 changes: 1 addition & 1 deletion rmw/test/test_serialized_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "rcutils/allocator.h"

#include "rmw/serialized_message.h"
#include "rmw/types.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Is this change necessary ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Karsten1987 ping?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need that for the return values.


TEST(test_serialized_message, default_initialization) {
auto serialized_msg = rmw_get_zero_initialized_serialized_message();
Expand Down