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

Fix wrong size calculation [11963] #2049

Merged
merged 7 commits into from
Jul 7, 2021
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
24 changes: 17 additions & 7 deletions test/performance/latency/LatencyTestTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
using namespace eprosima::fastrtps;
using namespace eprosima::fastrtps::rtps;

const size_t LatencyType::overhead = offsetof(LatencyType, data);
const size_t LatencyType::overhead = offsetof(LatencyType, data) +
SerializedPayload_t::representation_header_size;
const std::string LatencyDataType::type_name_ = "LatencyType";

bool LatencyDataType::compare_data(
Expand Down Expand Up @@ -56,11 +57,17 @@ bool LatencyDataType::serialize(
void* data,
SerializedPayload_t* payload)
{
static uint8_t encapsulation[4] = { 0x0, 0x1, 0x0, 0x0 };
LatencyType* lt = (LatencyType*)data;

memcpy(payload->data, &lt->seqnum, sizeof(lt->seqnum));
memcpy(payload->data + 4, &lt->bounce, sizeof(lt->bounce));
memcpy(payload->data + 8, lt->data, buffer_size_);
auto ser_data = payload->data;
memcpy(ser_data, encapsulation, SerializedPayload_t::representation_header_size);
ser_data += SerializedPayload_t::representation_header_size;
memcpy(ser_data, &lt->seqnum, sizeof(lt->seqnum));
ser_data += sizeof(lt->seqnum);
memcpy(ser_data, &lt->bounce, sizeof(lt->bounce));
ser_data += sizeof(lt->bounce);
memcpy(ser_data, lt->data, buffer_size_);
payload->length = m_typeSize;
return true;
}
Expand All @@ -71,9 +78,12 @@ bool LatencyDataType::deserialize(
{
// Payload members endianness matches local machine
LatencyType* lt = (LatencyType*)data;
lt->seqnum = *reinterpret_cast<uint32_t*>(payload->data);
lt->bounce = *reinterpret_cast<uint32_t*>(payload->data + 4);
std::copy(payload->data + 8, payload->data + 8 + buffer_size_, lt->data);
auto ser_data = payload->data + SerializedPayload_t::representation_header_size;
lt->seqnum = *reinterpret_cast<uint32_t*>(ser_data);
ser_data += sizeof(lt->seqnum);
lt->bounce = *reinterpret_cast<uint32_t*>(ser_data);
ser_data += sizeof(lt->bounce);
std::copy(ser_data, ser_data + buffer_size_, lt->data);
return true;
}

Expand Down
5 changes: 4 additions & 1 deletion test/performance/latency/LatencyTestTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ class LatencyDataType : public eprosima::fastdds::dds::TopicDataType
: buffer_size_(size)
{
setName("LatencyType");
m_typeSize = 8 + ((size + 3) & ~3);
m_typeSize = sizeof(decltype(LatencyType::seqnum)) +
sizeof(decltype(LatencyType::bounce)) +
((size + 3) & ~3) +
eprosima::fastrtps::rtps::SerializedPayload_t::representation_header_size;
m_isGetKeyDefined = false;
}

Expand Down
16 changes: 12 additions & 4 deletions test/performance/throughput/ThroughputTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ bool ThroughputDataType::serialize(
void* data,
SerializedPayload_t* payload)
{
static uint8_t encapsulation[4] = { 0x0, 0x1, 0x0, 0x0 };
ThroughputType* lt = (ThroughputType*)data;
memcpy(payload->data, &lt->seqnum, sizeof(lt->seqnum));
memcpy(payload->data + 4, lt->data, buffer_size_);

auto ser_data = payload->data;
memcpy(ser_data, encapsulation, SerializedPayload_t::representation_header_size);
ser_data += SerializedPayload_t::representation_header_size;
memcpy(ser_data, &lt->seqnum, sizeof(lt->seqnum));
ser_data += sizeof(lt->seqnum);
memcpy(ser_data, lt->data, buffer_size_);
payload->length = m_typeSize;
return true;
}
Expand All @@ -60,8 +66,10 @@ bool ThroughputDataType::deserialize(
{
// payload members endiannes matches local machine
ThroughputType* lt = (ThroughputType*)data;
lt->seqnum = *reinterpret_cast<uint32_t*>(payload->data);
std::copy(payload->data + 4, payload->data + 4 + buffer_size_, lt->data);
auto ser_data = payload->data + SerializedPayload_t::representation_header_size;
lt->seqnum = *reinterpret_cast<uint32_t*>(ser_data);
ser_data += sizeof(lt->seqnum);
std::copy(ser_data, ser_data + buffer_size_, lt->data);
}
return true;
}
Expand Down
4 changes: 3 additions & 1 deletion test/performance/throughput/ThroughputTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ class ThroughputDataType : public eprosima::fastrtps::TopicDataType
: buffer_size_(size)
{
setName(type_name_.c_str());
m_typeSize = 4 + ((size + 3) & ~3);
m_typeSize = sizeof(decltype(ThroughputType::seqnum)) +
((size + 3) & ~3) +
eprosima::fastrtps::rtps::SerializedPayload_t::representation_header_size;
m_isGetKeyDefined = false;
}

Expand Down