Skip to content

Commit

Permalink
Cherry pick sros2 update for Fast-RTPS master support (#101)
Browse files Browse the repository at this point in the history
* Added CDR encapsulation

* uncrustify fixup
  • Loading branch information
nuclearsandwich authored Apr 11, 2017
1 parent 1812656 commit 63742a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
15 changes: 13 additions & 2 deletions rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,9 @@ size_t TypeSupport<MembersType>::calculateMaxSerializedSize(

size_t initial_alignment = current_alignment;

// Encapsulation
current_alignment += 4;

for (uint32_t i = 0; i < members->member_count_; ++i) {
const auto * member = members->members_ + i;

Expand Down Expand Up @@ -891,6 +894,9 @@ bool TypeSupport<MembersType>::serializeROSmessage(
{
assert(ros_message);

// Serialize encapsulation
ser.serialize_encapsulation();

if (members_->member_count_ != 0) {
TypeSupport::serializeROSmessage(ser, members_, ros_message);
} else {
Expand All @@ -907,7 +913,11 @@ bool TypeSupport<MembersType>::deserializeROSmessage(
assert(buffer);
assert(ros_message);

eprosima::fastcdr::Cdr deser(*buffer);
eprosima::fastcdr::Cdr deser(*buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);

// Deserialize encapsulation.
deser.read_encapsulation();

if (members_->member_count_ != 0) {
TypeSupport::deserializeROSmessage(deser, members_, ros_message, false);
Expand Down Expand Up @@ -936,7 +946,8 @@ bool TypeSupport<MembersType>::serialize(
eprosima::fastcdr::Cdr * ser = static_cast<eprosima::fastcdr::Cdr *>(data);
if (payload->max_size >= ser->getSerializedDataLength()) {
payload->length = static_cast<uint32_t>(ser->getSerializedDataLength());
payload->encapsulation = CDR_LE;
payload->encapsulation = ser->endianness() ==
eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
memcpy(payload->data, ser->getBufferPointer(), ser->getSerializedDataLength());
return true;
}
Expand Down
9 changes: 6 additions & 3 deletions rmw_fastrtps_cpp/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,8 @@ rmw_ret_t rmw_publish(const rmw_publisher_t * publisher, const void * ros_messag
assert(info);

eprosima::fastcdr::FastBuffer buffer;
eprosima::fastcdr::Cdr ser(buffer);
eprosima::fastcdr::Cdr ser(buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);

if (_serialize_ros_message(ros_message, ser, info->type_support_,
info->typesupport_identifier_))
Expand Down Expand Up @@ -1699,7 +1700,8 @@ rmw_ret_t rmw_send_request(const rmw_client_t * client,
assert(info);

eprosima::fastcdr::FastBuffer buffer;
eprosima::fastcdr::Cdr ser(buffer);
eprosima::fastcdr::Cdr ser(buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);

if (_serialize_ros_message(ros_request, ser, info->request_type_support_,
info->typesupport_identifier_))
Expand Down Expand Up @@ -1816,7 +1818,8 @@ rmw_ret_t rmw_send_response(const rmw_service_t * service,
assert(info);

eprosima::fastcdr::FastBuffer buffer;
eprosima::fastcdr::Cdr ser(buffer);
eprosima::fastcdr::Cdr ser(buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);

_serialize_ros_message(ros_response, ser, info->response_type_support_,
info->typesupport_identifier_);
Expand Down

0 comments on commit 63742a4

Please sign in to comment.