Error sending the sample when using XCDR2
Is there an already existing issue for this?
- [X] I have searched the existing issues
Expected behavior
The sample is successfully sent regardless of its size.
Current behavior
Depending on the size of the sample, the write() method returns an error code.
Steps to reproduce
This error can be reproduced by modifying HelloWorldExample as follows:
diff --git a/examples/cpp/dds/HelloWorldExample/HelloWorldPublisher.cpp b/examples/cpp/dds/HelloWorldExample/HelloWorldPublisher.cpp
index 86f3e0009..aeaa239d6 100644
--- a/examples/cpp/dds/HelloWorldExample/HelloWorldPublisher.cpp
+++ b/examples/cpp/dds/HelloWorldExample/HelloWorldPublisher.cpp
@@ -43,7 +43,7 @@ bool HelloWorldPublisher::init(
bool use_env)
{
hello_.index(0);
- hello_.message("HelloWorld");
+ hello_.message().resize(256, 'A');
DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT;
pqos.name("Participant_pub");
auto factory = DomainParticipantFactory::get_instance();
@@ -106,6 +106,7 @@ bool HelloWorldPublisher::init(
{
publisher_->get_default_datawriter_qos(wqos);
}
+ wqos.representation().m_value.push_back(XCDR2_DATA_REPRESENTATION);
writer_ = publisher_->create_datawriter(
topic_,
@@ -218,7 +219,9 @@ bool HelloWorldPublisher::publish(
if (listener_.firstConnected_ || !waitForListener || listener_.matched_ > 0)
{
hello_.index(hello_.index() + 1);
- writer_->write(&hello_);
+ if (!writer_->write(&hello_)) {
+ printf("ERROR WRITE SAMPLE!!!\n");
+ }
return true;
}
return false;
diff --git a/examples/cpp/dds/HelloWorldExample/HelloWorldSubscriber.cpp b/examples/cpp/dds/HelloWorldExample/HelloWorldSubscriber.cpp
index 6823a32f4..145ba4d9f 100644
--- a/examples/cpp/dds/HelloWorldExample/HelloWorldSubscriber.cpp
+++ b/examples/cpp/dds/HelloWorldExample/HelloWorldSubscriber.cpp
@@ -106,6 +106,8 @@ bool HelloWorldSubscriber::init(
subscriber_->get_default_datareader_qos(rqos);
}
+ rqos.type_consistency().representation.m_value.push_back(XCDR2_DATA_REPRESENTATION);
+
reader_ = subscriber_->create_datareader(topic_, rqos, &listener_);
if (reader_ == nullptr)
diff --git a/examples/cpp/dds/HelloWorldExample/HelloWorld_main.cpp b/examples/cpp/dds/HelloWorldExample/HelloWorld_main.cpp
index 35870eb67..bcaebd3cd 100644
--- a/examples/cpp/dds/HelloWorldExample/HelloWorld_main.cpp
+++ b/examples/cpp/dds/HelloWorldExample/HelloWorld_main.cpp
@@ -291,6 +291,8 @@ int main(
}
}
+ Log::SetVerbosity(Log::Kind::Warning);
+
switch (type)
{
case 1:
Fast DDS version/commit
v2.14.1
Platform/Architecture
Ubuntu Focal 20.04 amd64
Transport layer
Default configuration, UDPv4 & SHM
Additional context
No response
XML configuration file
No response
Relevant log output
2024-06-12 20:47:00.881 [DATA_WRITER Warning] Data serialization returned false -> Function perform_create_new_change
ERROR WRITE SAMPLE!!!
Message: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA with index: 4 SENT
Network traffic capture
No response
Hi @i-and, Thank you for using Fast DDS.
There might be an issue with the data serialization in case the message size is greater than 255 and the extensibility of the message type defined in the .idl is APPENDABLE, which is by default. I will label it as bug. In the meanwhile, you can still accomplish what you are trying to do, setting the extensibility to FINAL in the HelloWorld.idl file as follow:
@final
struct HelloWorld
{
unsigned long index;
string message;
};
and regenerate the types with Fast DDS-GEN. If you haven't installed it yet, you can follow the installation instructions and then the usage guide to regenerate types adding the -replace argument.
As the Dynamic Types refactor has been already introduced in the latest Fast DDS v3.0.0, we internally agreed to close all Dynamic-Types related issues. We elaborated a Migration guide to help with the upgrade process to this new major release.
Please, feel free to reopen it if the issue persists.