Skip to content

Commit

Permalink
Revert changes on type support.
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <[email protected]>
  • Loading branch information
MiguelCompany committed Jun 26, 2024
1 parent ea52b14 commit 90bbeb8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 189 deletions.
92 changes: 24 additions & 68 deletions test/profiling/MemoryTestTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,96 +22,62 @@
using namespace eprosima::fastrtps;
using namespace eprosima::fastrtps::rtps;

bool MemoryDataType::serialize(
void* data,
SerializedPayload_t* payload)
bool MemoryDataType::serialize(void*data,SerializedPayload_t* payload)
{
MemoryType* lt = (MemoryType*)data;


*(uint32_t*)payload->data = lt->seqnum;
*(uint32_t*)(payload->data + 4) = (uint32_t)lt->data.size();
*(uint32_t*)(payload->data+4) = (uint32_t)lt->data.size();

//std::copy(lt->data.begin(),lt->data.end(),payload->data+8);
memcpy(payload->data + 8, lt->data.data(), lt->data.size());
payload->length = (uint32_t)(8 + lt->data.size());
payload->length = (uint32_t)(8+lt->data.size());
return true;
}

bool MemoryDataType::serialize(
void* data,
eprosima::fastrtps::rtps::SerializedPayload_t* payload,
eprosima::fastdds::dds::DataRepresentationId_t)
{
return serialize(data, payload);
}

bool MemoryDataType::deserialize(
SerializedPayload_t* payload,
void* data)
bool MemoryDataType::deserialize(SerializedPayload_t* payload,void * data)
{
MemoryType* lt = (MemoryType*)data;
lt->seqnum = *(uint32_t*)payload->data;
uint32_t siz = *(uint32_t*)(payload->data + 4);
std::copy(payload->data + 8, payload->data + 8 + siz, lt->data.begin());
uint32_t siz = *(uint32_t*)(payload->data+4);
std::copy(payload->data+8,payload->data+8+siz,lt->data.begin());
return true;
}

std::function<uint32_t()> MemoryDataType::getSerializedSizeProvider(
void* data)
std::function<uint32_t()> MemoryDataType::getSerializedSizeProvider(void* data)
{
return [data]() -> uint32_t
{
MemoryType* tdata = static_cast<MemoryType*>(data);
uint32_t size = 0;

size = (uint32_t)(sizeof(uint32_t) + sizeof(uint32_t) + tdata->data.size());
{
MemoryType *tdata = static_cast<MemoryType*>(data);
uint32_t size = 0;

return size;
};
}
size = (uint32_t)(sizeof(uint32_t) + sizeof(uint32_t) + tdata->data.size());

std::function<uint32_t()> MemoryDataType::getSerializedSizeProvider(
void* data,
eprosima::fastdds::dds::DataRepresentationId_t)
{
return getSerializedSizeProvider(data);
return size;
};
}

void* MemoryDataType::createData()
{

return (void*)new MemoryType();
}

void MemoryDataType::deleteData(
void* data)
void MemoryDataType::deleteData(void* data)
{

delete((MemoryType*)data);
}

bool TestCommandDataType::serialize(
void* data,
SerializedPayload_t* payload)

bool TestCommandDataType::serialize(void*data,SerializedPayload_t* payload)
{
TestCommandType* t = (TestCommandType*)data;
*(TESTCOMMAND*)payload->data = t->m_command;
payload->length = 4;
return true;
}

bool TestCommandDataType::serialize(
void* data,
eprosima::fastrtps::rtps::SerializedPayload_t* payload,
eprosima::fastdds::dds::DataRepresentationId_t)
{
return serialize(data, payload);
}

bool TestCommandDataType::deserialize(
SerializedPayload_t* payload,
void* data)
bool TestCommandDataType::deserialize(SerializedPayload_t* payload,void * data)
{
TestCommandType* t = (TestCommandType*)data;
// cout << "PAYLOAD LENGTH: "<<payload->length << endl;
Expand All @@ -121,34 +87,24 @@ bool TestCommandDataType::deserialize(
return true;
}

std::function<uint32_t()> TestCommandDataType::getSerializedSizeProvider(
void*)
std::function<uint32_t()> TestCommandDataType::getSerializedSizeProvider(void*)
{
return []() -> uint32_t
{
uint32_t size = 0;
{
uint32_t size = 0;

size = (uint32_t)sizeof(uint32_t);
size = (uint32_t)sizeof(uint32_t);

return size;
};
}

std::function<uint32_t()> TestCommandDataType::getSerializedSizeProvider(
void* data,
eprosima::fastdds::dds::DataRepresentationId_t)
{
return getSerializedSizeProvider(data);
return size;
};
}

void* TestCommandDataType::createData()
{

return (void*)new TestCommandType();
}

void TestCommandDataType::deleteData(
void* data)
void TestCommandDataType::deleteData(void* data)
{

delete((TestCommandType*)data);
Expand Down
170 changes: 49 additions & 121 deletions test/profiling/MemoryTestTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,98 +24,56 @@

class MemoryType
{
public:
public:

uint32_t seqnum;
std::vector<uint8_t> data;
uint32_t seqnum;
std::vector<uint8_t> data;

MemoryType()
: seqnum(0)
{
}
MemoryType(): seqnum(0) {}

MemoryType(
uint32_t number)
: seqnum(0)
, data(number, 0)
{
}

~MemoryType()
{
}
MemoryType(uint32_t number) :
seqnum(0), data(number,0) {}

~MemoryType() {}
};


inline bool operator ==(
const MemoryType& lt1,
const MemoryType& lt2)
inline bool operator==(const MemoryType& lt1, const MemoryType& lt2)
{
if (lt1.seqnum != lt2.seqnum)
{
if(lt1.seqnum!=lt2.seqnum)
return false;
}
if (lt1.data.size() != lt2.data.size())
{
if(lt1.data.size()!=lt2.data.size())
return false;
}
for (size_t i = 0; i < lt1.data.size(); ++i)
for(size_t i = 0;i<lt1.data.size();++i)
{
if (lt1.data.at(i) != lt2.data.at(i))
{
if(lt1.data.at(i) != lt2.data.at(i))
return false;
}
}
return true;
}

class MemoryDataType : public eprosima::fastrtps::TopicDataType
{
public:

MemoryDataType()
{
setName("MemoryType");
m_typeSize = 17000;
m_isGetKeyDefined = false;
}

~MemoryDataType()
{
}

bool serialize(
void* data,
eprosima::fastrtps::rtps::SerializedPayload_t* payload) override;
bool serialize(
void* data,
eprosima::fastrtps::rtps::SerializedPayload_t* payload,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
bool deserialize(
eprosima::fastrtps::rtps::SerializedPayload_t* payload,
void* data) override;
std::function<uint32_t()> getSerializedSizeProvider(
void* data) override;
std::function<uint32_t()> getSerializedSizeProvider(
void* data,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
void* createData() override;
void deleteData(
void* data) override;
bool getKey(
void* /*data*/,
eprosima::fastrtps::rtps::InstanceHandle_t* /*ihandle*/,
bool force_md5 = false) override
{
(void)force_md5;
return false;
}

public:
MemoryDataType()
{
setName("MemoryType");
m_typeSize = 17000;
m_isGetKeyDefined = false;
};
~MemoryDataType(){};
bool serialize(void*data, eprosima::fastrtps::rtps::SerializedPayload_t* payload);
bool deserialize(eprosima::fastrtps::rtps::SerializedPayload_t* payload,void * data);
std::function<uint32_t()> getSerializedSizeProvider(void* data);
void* createData();
void deleteData(void* data);
bool getKey(void* /*data*/, eprosima::fastrtps::rtps::InstanceHandle_t* /*ihandle*/, bool force_md5 = false) override {
(void)force_md5;
return false;
}
};

enum TESTCOMMAND : uint32_t
{
enum TESTCOMMAND:uint32_t{
DEFAULT,
READY,
BEGIN,
Expand All @@ -126,61 +84,31 @@ enum TESTCOMMAND : uint32_t
typedef struct TestCommandType
{
TESTCOMMAND m_command;
TestCommandType()
{
TestCommandType(){
m_command = DEFAULT;
}

TestCommandType(
TESTCOMMAND com)
: m_command(com)
{
}

TestCommandType(TESTCOMMAND com):m_command(com){}
}TestCommandType;

class TestCommandDataType : public eprosima::fastrtps::TopicDataType
{
public:

TestCommandDataType()
{
setName("TestCommandType");
m_typeSize = 4;
m_isGetKeyDefined = false;
}

~TestCommandDataType()
{
}

bool serialize(
void* data,
eprosima::fastrtps::rtps::SerializedPayload_t* payload) override;
bool serialize(
void* data,
eprosima::fastrtps::rtps::SerializedPayload_t* payload,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
bool deserialize(
eprosima::fastrtps::rtps::SerializedPayload_t* payload,
void* data) override;
std::function<uint32_t()> getSerializedSizeProvider(
void* data) override;
std::function<uint32_t()> getSerializedSizeProvider(
void* data,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
void* createData() override;
void deleteData(
void* data) override;
bool getKey(
void* /*data*/,
eprosima::fastrtps::rtps::InstanceHandle_t* /*ihandle*/,
bool force_md5 = false) override
{
(void)force_md5;
return false;
}

public:
TestCommandDataType()
{
setName("TestCommandType");
m_typeSize = 4;
m_isGetKeyDefined = false;
};
~TestCommandDataType(){};
bool serialize(void*data,eprosima::fastrtps::rtps::SerializedPayload_t* payload);
bool deserialize(eprosima::fastrtps::rtps::SerializedPayload_t* payload,void * data);
std::function<uint32_t()> getSerializedSizeProvider(void* data);
void* createData();
void deleteData(void* data);
bool getKey(void* /*data*/, eprosima::fastrtps::rtps::InstanceHandle_t* /*ihandle*/, bool force_md5 = false) override {
(void)force_md5;
return false;
}
};


Expand Down

0 comments on commit 90bbeb8

Please sign in to comment.