Skip to content

Commit

Permalink
Refs #3043. Max bounded size support.
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelCompany committed Jun 18, 2018
1 parent 74a6164 commit 9897857
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ MessageTypeSupport<MembersType>::MessageTypeSupport(const MembersType * members)
members->message_name_ + "_";
this->setName(name.c_str());

// TODO(wjwwood): this could be more intelligent, setting m_typeSize to the
// maximum serialized size of the message, when the message is a bounded one.
if (members->member_count_ != 0) {
this->m_typeSize = static_cast<uint32_t>(this->calculateMaxSerializedSize(members, 0));
// Fully bound by default
this->max_size_bound_ = true;
// Encapsulation size
this->m_typeSize = 4;
if (this->members_->member_count_ != 0) {
this->m_typeSize += static_cast<uint32_t>(this->calculateMaxSerializedSize(members, 4));
} else {
this->m_typeSize = 5;
this->m_typeSize++;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ RequestTypeSupport<ServiceMembersType, MessageMembersType>::RequestTypeSupport(
members->service_name_ + "_Request_";
this->setName(name.c_str());

// TODO(wjwwood): this could be more intelligent, setting m_typeSize to the
// maximum serialized size of the message, when the message is a bounded one.
// Fully bound by default
this->max_size_bound_ = true;
// Encapsulation size
this->m_typeSize = 4;
if (this->members_->member_count_ != 0) {
this->m_typeSize = static_cast<uint32_t>(this->calculateMaxSerializedSize(this->members_, 0));
this->m_typeSize += static_cast<uint32_t>(this->calculateMaxSerializedSize(this->members_, 4));
} else {
this->m_typeSize = 5;
this->m_typeSize++;
}
}

Expand All @@ -62,12 +64,14 @@ ResponseTypeSupport<ServiceMembersType, MessageMembersType>::ResponseTypeSupport
members->service_name_ + "_Response_";
this->setName(name.c_str());

// TODO(wjwwood): this could be more intelligent, setting m_typeSize to the
// maximum serialized size of the message, when the message is a bounded one.
// Fully bound by default
this->max_size_bound_ = true;
// Encapsulation size
this->m_typeSize = 4;
if (this->members_->member_count_ != 0) {
this->m_typeSize = static_cast<uint32_t>(this->calculateMaxSerializedSize(this->members_, 0));
this->m_typeSize += static_cast<uint32_t>(this->calculateMaxSerializedSize(this->members_, 4));
} else {
this->m_typeSize = 5;
this->m_typeSize++;
}
}

Expand Down
1 change: 1 addition & 0 deletions rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class TypeSupport : public eprosima::fastrtps::TopicDataType
size_t calculateMaxSerializedSize(const MembersType * members, size_t current_alignment);

const MembersType * members_;
bool max_size_bound_;

private:
size_t getEstimatedSerializedSize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ template<typename MembersType>
TypeSupport<MembersType>::TypeSupport()
{
m_isGetKeyDefined = false;
max_size_bound_ = false;
}

template<typename MembersType>
Expand Down Expand Up @@ -853,9 +854,7 @@ size_t TypeSupport<MembersType>::calculateMaxSerializedSize(

size_t initial_alignment = current_alignment;

// Encapsulation
const size_t padding = 4;
current_alignment += padding;

for (uint32_t i = 0; i < members->member_count_; ++i) {
const auto * member = members->members_ + i;
Expand All @@ -865,6 +864,7 @@ size_t TypeSupport<MembersType>::calculateMaxSerializedSize(
array_size = member->array_size_;
// Whether it is a sequence.
if (0 == array_size || member->is_upper_bound_) {
this->max_size_bound_ = false;
current_alignment += padding +
eprosima::fastcdr::Cdr::alignment(current_alignment, padding);
}
Expand Down Expand Up @@ -897,6 +897,7 @@ size_t TypeSupport<MembersType>::calculateMaxSerializedSize(
break;
case ::rosidl_typesupport_introspection_cpp::ROS_TYPE_STRING:
{
this->max_size_bound_ = false;
for (size_t index = 0; index < array_size; ++index) {
current_alignment += padding +
eprosima::fastcdr::Cdr::alignment(current_alignment, padding) +
Expand Down Expand Up @@ -924,6 +925,10 @@ template<typename MembersType>
size_t TypeSupport<MembersType>::getEstimatedSerializedSize(
const void * ros_message)
{
if (max_size_bound_) {
return m_typeSize;
}

assert(ros_message);

// Encapsulation size
Expand Down

0 comments on commit 9897857

Please sign in to comment.