-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose raw CDR stream for publish and subscribe (#186)
* publish raw function * take raw * linters * add rmw_serialize functions * rmw_fastrtps_cpp/src/rmw_serialize memory leak when creating typesupport * linters * comparison size_t with unsigned int * remove asserts * refactor take code * use rcutls macro * changes for rebase * warn unused * fix typo * raw->serialized * use size_t (#206)
- Loading branch information
1 parent
a33f9f8
commit 636721d
Showing
11 changed files
with
290 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "fastcdr/FastBuffer.h" | ||
|
||
#include "rmw/error_handling.h" | ||
#include "rmw/serialized_message.h" | ||
#include "rmw/rmw.h" | ||
|
||
#include "./type_support_common.hpp" | ||
#include "./ros_message_serialization.hpp" | ||
|
||
extern "C" | ||
{ | ||
rmw_ret_t | ||
rmw_serialize( | ||
const void * ros_message, | ||
const rosidl_message_type_support_t * type_support, | ||
rmw_serialized_message_t * serialized_message) | ||
{ | ||
const rosidl_message_type_support_t * ts = get_message_typesupport_handle( | ||
type_support, rosidl_typesupport_introspection_c__identifier); | ||
if (!ts) { | ||
ts = get_message_typesupport_handle( | ||
type_support, rosidl_typesupport_introspection_cpp::typesupport_identifier); | ||
if (!ts) { | ||
RMW_SET_ERROR_MSG("type support not from this implementation"); | ||
return RMW_RET_ERROR; | ||
} | ||
} | ||
|
||
auto tss = _create_message_type_support(ts->data, ts->typesupport_identifier); | ||
eprosima::fastcdr::FastBuffer buffer; | ||
eprosima::fastcdr::Cdr ser( | ||
buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); | ||
|
||
auto ret = _serialize_ros_message(ros_message, ser, tss, ts->typesupport_identifier); | ||
auto data_length = static_cast<size_t>(ser.getSerializedDataLength()); | ||
if (serialized_message->buffer_capacity < data_length) { | ||
if (rmw_serialized_message_resize(serialized_message, data_length) != RMW_RET_OK) { | ||
RMW_SET_ERROR_MSG("unable to dynamically resize serialized message"); | ||
return RMW_RET_ERROR; | ||
} | ||
} | ||
memcpy(serialized_message->buffer, ser.getBufferPointer(), data_length); | ||
serialized_message->buffer_length = data_length; | ||
serialized_message->buffer_capacity = data_length; | ||
_delete_typesupport(tss, ts->typesupport_identifier); | ||
return ret == true ? RMW_RET_OK : RMW_RET_ERROR; | ||
} | ||
|
||
rmw_ret_t | ||
rmw_deserialize( | ||
const rmw_serialized_message_t * serialized_message, | ||
const rosidl_message_type_support_t * type_support, | ||
void * ros_message) | ||
{ | ||
const rosidl_message_type_support_t * ts = get_message_typesupport_handle( | ||
type_support, rosidl_typesupport_introspection_c__identifier); | ||
if (!ts) { | ||
ts = get_message_typesupport_handle( | ||
type_support, rosidl_typesupport_introspection_cpp::typesupport_identifier); | ||
if (!ts) { | ||
RMW_SET_ERROR_MSG("type support not from this implementation"); | ||
return RMW_RET_ERROR; | ||
} | ||
} | ||
|
||
auto tss = _create_message_type_support(ts->data, ts->typesupport_identifier); | ||
eprosima::fastcdr::FastBuffer buffer( | ||
serialized_message->buffer, serialized_message->buffer_length); | ||
eprosima::fastcdr::Cdr deser(buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, | ||
eprosima::fastcdr::Cdr::DDS_CDR); | ||
|
||
auto ret = _deserialize_ros_message(deser, ros_message, tss, ts->typesupport_identifier); | ||
_delete_typesupport(tss, ts->typesupport_identifier); | ||
return ret == true ? RMW_RET_OK : RMW_RET_ERROR; | ||
} | ||
} // extern "C" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.