Fast-DDS
Fast-DDS copied to clipboard
DataWriter cannot serialize (write) DynamicData struct with inheritance [13363]
Data writer reports serialization errors while writing data with inheritance.
Expected Behavior
DataWriter (and reader as well) should be able to work with DynamicData types defined in the XML with inheritance.
Current Behavior
Data writers cannot write data type payload (e.g. struct) with inheritance.
Steps to Reproduce
- Define DynamicData struct with inheritance in the XML.
- Create a topic for appropriate type, register type for participant, create readers and writers etc.
- Try to write data using DataWriter.
System information
- Fast-RTPS version: 2.4.0
- OS: Ubuntu 20.04
Additional context
Seems that the size of parent dynamic data type is ignored while serialized size calculation. The following hotfix, seems, works for me, but unfortunately I'm not sure if it is enough or how it can affect other functionality.
diff --git a/src/cpp/dynamic-types/DynamicData.cpp b/src/cpp/dynamic-types/DynamicData.cpp
index 4536ccbbe..cfa8de39b 100644
--- a/src/cpp/dynamic-types/DynamicData.cpp
+++ b/src/cpp/dynamic-types/DynamicData.cpp
@@ -6181,6 +6181,10 @@ size_t DynamicData::getMaxCdrSerializedSize(
case TK_STRUCTURE:
case TK_BITSET:
{
+ if(auto base_type{type->get_base_type()}){
+ current_alignment += getMaxCdrSerializedSize(base_type);
+ }
+
for (auto it = type->member_by_id_.begin(); it != type->member_by_id_.end(); ++it)
{
if (!it->second->descriptor_.annotation_is_non_serialized())
Additional resources
- XML profiles file
<struct name="ParentStruct">
<member name="first" type="int32"/>
<member name="second" type="int64"/>
</struct>
<struct name="ChildStruct" baseType="ParentStruct">
<member name="third" type="int32"/>
<member name="fourth" type="int64"/>
</struct>