14.4. Dynamic Types IDL Parsing

Fast DDS supports the implementation of Dynamic Language Binding for parsing IDL files at runtime to generate dynamic data types. The DynamicTypeBuilderFactory::create_type_w_uri API allows users to provide a URI pointing to an IDL file. Fast DDS will process the file and return the corresponding DynamicTypeBuilder, which can then be used to create a DynamicType.

This feature enables applications to dynamically load type definitions from IDL files instead of relying solely on pre-generated types or XML profiles. This enhances flexibility, as new data types can be introduced without modifying and recompiling the application.

14.4.1. Type definition

Below, the types supported by eProsima Fast DDS IDL parsing are presented. For further information about the supported Dynamic Language Binding, please, refer to Supported Types.

The following types are currently not supported by the IDL parsing feature:

14.4.2. Example

Fast DDS application can use dynamic types generated in runtime just by loading the corresponding IDL files into the DynamicTypeBuilderFactory using DynamicTypeBuilderFactory::create_type_w_uri. After getting the DynamicType, objects of DynamicPubSubType class might be instantiated and used to write/read data.

Note

The preprocessor can be manually selected using DynamicTypeBuilderFactory::set_preprocessor

The following snippet shows the previously explained steps:

// Create a DomainParticipant in the desired domain
DomainParticipant* participant =
        DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
if (nullptr == participant)
{
    // Error
    return;
}

// Optional: Set the preprocessor to be executed before parsing the IDL
DynamicTypeBuilderFactory::get_instance()->set_preprocessor("<optional_path_to_your_preprocessor_executable>");

// Load the IDL file
std::string idl_file = "<path_to_idl>.idl";
std::string type_name = "YourType";
std::vector<std::string> include_paths;
include_paths.push_back("<path/to/folder/containing/included/idl/files>");

// Retrieve the instance of the desired type
DynamicTypeBuilder::_ref_type dyn_type_builder = 
        DynamicTypeBuilderFactory::get_instance()->create_type_w_uri(idl_file, type_name, include_paths);

// Register dynamic type
TypeSupport dyn_type_support(new DynamicPubSubType(dyn_type_builder->build()));
dyn_type_support.register_type(participant, nullptr);

// Create a Topic with the registered type.
Topic* topic =
        participant->create_topic("topic_name", dyn_type_support.get_type_name(), TOPIC_QOS_DEFAULT);
if (nullptr == topic)
{
    // Error
    return;
}