I'm using the RTI Connext 5.2 Modern C++ API and I'm trying to replicate the functionality that is described within this HOWTO (specifically, "typecode serialization" that's referenced in the link within the uploaded files):
https://community.rti.com/howto/dynamicdata-serialization
Unfortunately, I can't seem to find any analogous functionality to the RTICdrTypeCode_serialize functionality within the Moden C++ API. Has anyone had success with serializing DynamicTypes in the new API? Thanks in advance.
That article seems outdated. It's actually simpler than that. All you need is to call rti::core::xtypes::to_cdr_buffer. That will serialize a DynamicData object into a std::vector.
Thanks for the input Alejandro. I understand how to serialize a DynamicData object, the question is how do I serialize (and subsequently deserialize) the DynamicType? This is referred to as the type_code information under the classic interface but I can't find anything analogous to it in the Modern API.
Hi Alejandro and David,
That's my question too. I would be very grateful if anyone can help me.
Bonjefir
To serialize the type code—in the modern C++ API it's called DynamicType, as the OMG standard now indicates—you can use the exact same C code you have. You just need to obtain the C "view" of the C++ DynamicType:
Please keep in mind that
RTICdrTypeCode_serialize
andDynamicType::native()
are not part of the public API and therefore not officially supported and subject to change.Alex
Dear Alex,
Thanks a lot for your answer. That was a big help for me. Now I am able to serialize and deserialize typeCode but I cannot convert the returned "DDS_TypeCode" to "dds::core::xtype::DynamicType".
I tried the following code:
dds::core::xtypes::DynamicType *x;
x->native(*(reconstructedTypeCode));
But I have a run-time error (segmentation fault) in
void native(const native_type& value){ adapter_type::copy(native(), value);}
which is a function in NativeValueType.hpp.
I would be very grateful if you can help me about this problem. A working example will be wonderful.
Thanks in advance for your help.
Bonjefir
Try making
x
a stack variable:Alex
I just realized that the default constructor of DynamicType is protected, because it shouldn't be instantiated directly. You should pick a subclass. If your type is a struct, use StructType:
Dear Alex,
Thanks a lot for your nice and prompt response. That was a very very big help :) . But I'm afraid of cases in which we don't know the original type. Is there any way to get the type first and then decide which kind of type we need. As you know we have serveral dynamic type including dds::core::xtype::EnumType, dds::core::xtype::UnionType and so on. What should we do in that case?
Best Regards,
Bonjefir
In fact, because the classes derived from
DynamicType
don't add any additional state it is safe to useStructType
and then cast, even if the type is not a struct:Another option (probably safer in the long run) is to first get the type kind from
reconstructedTypeCode
:DDS_TCKind kind = DDS_TypeCode_kind(reconstructedTypeCode);
And depending on the kind, choose the right subclass of
DynamicType
.Hi Alex,
Thanks again for your helps. I tried the following code and it's working;
DDS_ExceptionCode_t *ex;
DDS_TCKind kind = DDS_TypeCode_kind(reconstructedTypeCode,ex);
Best Regards,
Bonjefir