key field in dynamic types in XML profile [12549]
I am implementing dynamic types in the XML profile. I'd like to mark member of the struct as a key field. Adding key="true" attribute, but without success. For example:
<types>
<type>
<struct name="HelloWorld">
<member name="message" type="string"/>
<member name="index" type="uint32" key="true"/>
<member name="array" type="uint32" arrayDimensions="5,2"/>
</struct>
</type>
</types>
index member marked with key attribute.
As mentioned here
member m_isGetKeyDefined in class TopicDataType should be set to true to support key.
m_isGetKeyDefined sets in the following method DynamicPubSubType::UpdateDynamicTypeInfo():
m_isGetKeyDefined = dynamic_type_->key_annotation();
DynamicType::key_annotation() calls AnnotationDescriptor::key_annotation()
Looks like AnnotationDescriptor::key_annotation() does not check correctly if annotation key or not:
AnnotationDescriptor has name_ field which is equal ANNOTATION_KEY_ID for key annotations.
value_ map contains element with key "value" and value "true"/"false".
Suppose instead of code:
bool AnnotationDescriptor::key_annotation() const
{
auto it = value_.find(ANNOTATION_KEY_ID);
if (it == value_.end())
{
it = value_.find(ANNOTATION_EPKEY_ID); // Legacy "@Key"
}
return (it != value_.end() && it->second == CONST_TRUE);
}
it should be implemented in a similar way:
bool AnnotationDescriptor::key_annotation() const
{
if (name_ != ANNOTATION_KEY_ID || name_ != ANNOTATION_EPKEY_ID)
return false;
auto it = value_.find("value");
if (it == value_.end())
return false;
return (it->second == CONST_TRUE);
}
Does it make sense? Are there any other ways to mark members of the structs as a key in XML profile?
Hi @obrpasha
Thank you very much for your feedback and for the time you have spent in this issue. As you correctly point, the key field is not correctly set from the XML.
Your fix is valid, thank you for taking the time to do it. However, I think the error is more likely to be the values stored in the map, rather than how to read them. I have prepared the PR https://github.com/eProsima/Fast-DDS/pull/2226 in order to solve this issue.
Sadly this fix breaks some other (and bigger) stuff in DynamicTypes, and so it is not mergeable yet. My assumption so far is that the key now is correctly set, but not correctly send to the Subscriber, and so they are not able to communicate due an incompatibility in the types. I hope I get the time soon to check it closely and find the error. In the meanwhile, feel free to keep commenting about this issue. You can also contribute to the PR by commenting, suggestion or even adding commits.
Hi @obrpasha, Fast DDS v3.0.0 has been released, including a Dynamic Types refactor that may have fixed your issue. Could you check if the problem persists?
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.