.. _typesupport: Typesupport =========== The TypeSupport is a crucial component in DDS which provides an interface for handling data types in a standardized way. It is responsible for managing the serialization, deserialization, and type-specific operations for user-defined data types in a DDS system. In this sense, the TypeSupport ensures the seamless exchange of data between :ref:`dds_layers_subscription_datareader` and :ref:`dds_layers_publication_datawriter` by providing a common data representation. A **Safe DDS type support** is any class that implements `dds::TypeSupport <../doxygen/classeprosima_1_1safedds_1_1dds_1_1_type_support.html>`__, that allows registering the type support within the DDS system and handle the type key identifier. .. _typesupport_data_representation: Data representation ------------------- For the purpose of achieving interoperability with other DDS vendors, it is necessary that the implementation of any Safe DDS TypeSupport adheres to a commonly accepted serialization and deserialization format known as CDR (Common Data Representation). To facilitate CDR-compliant serialization and deserialization functionality, the following classes are provided: - `serialization::cdr::Serializer <../doxygen/classeprosima_1_1safedds_1_1serialization_1_1cdr_1_1_serializer.html>`__ - `serialization::cdr::Deserializer <../doxygen/classeprosima_1_1safedds_1_1serialization_1_1cdr_1_1_deserializer.html>`__ To set and decode the type of data representation used, the following structure is provided: - `serialization::RepresentationHeader <../doxygen/structeprosima_1_1safedds_1_1serialization_1_1_representation_header.html>`__ By leveraging these classes, the Safe DDS TypeSupport implementation ensures compatibility with other DDS vendors, promoting effective communication and data exchange across various DDS systems. .. _typesupport_register_type: Registering a type ------------------ For a DDS TypeSupport to be utilized effectively, it is necessary to register it within a the application :ref:`dds_layers_domain_participant`. Once this registration process is completed, it is possible to leverage the safety-typed APIs offered by :ref:`TypedDataReader ` and :ref:`TypedDataWriter `. In order to register a ``dds::TypeSupport`` interface into a ``dds::DomainParticipant``, the ``TypeSupport::register_type`` method shall be used. .. literalinclude:: ../code/entity_creation/main.cpp :language: c++ :start-after: // DDS_TYPESUPPORT_REGISTRATION :end-before: //! DDS_TYPESUPPORT_REGISTRATION :dedent: 4 .. _typesupport_safeddsgen_intro: Safe DDS Gen ------------ .. include:: ../safety_manual/rules/RULE_SAFEDDSGEN.inc *Safe DDS Gen* is a Java application that generates application code to support type handling when using *Safe DDS* from data types defined in an IDL (Interface Definition Language) file. It does so by generating code which leverages *Safe DDS* APIs. This generated source code can be used in any *Safe DDS* application in order to define the data type of a topic, which will later be used to publish or subscribe. Please refer to :ref:`typesupport` for more information on data types. To declare the structured data, the IDL format must be used. IDL is a specification language, made by `OMG `_ (Object Management Group), which describes an interface in a language independent manner, allowing communication between software components that do not share the same language. The *Safe DDS Gen* tool reads the IDL files and parses a subset of the `OMG IDL specification `_ to generate source code for data serialization, this subset is detailed in the :ref:`safeddsgen_supported_types` section. *Safe DDS Gen* generated source code uses provided CDR serialization implementations detailed on :ref:`typesupport_data_representation`. Therefore, as stated in the `RTPS standard `_, when the data are sent, the serialization is performed using the corresponding Common Data Representation (CDR). The main feature of *Safe DDS Gen* is to facilitate the implementation of DDS applications without the knowledge of serialization or deserialization mechanisms. For installing *Safe DDS Gen*, please refer to :ref:`safeddsgen_install_linux`. .. toctree:: :maxdepth: 1 :hidden: ./safeddsgen/installation ./safeddsgen/usage ./safeddsgen/defining_types .. _typesupport_hello_world_typesupport: HelloWorld TypeSupport ---------------------- For reference, this documentation provides a simple example of a TypeSupport implementation for the HelloWorld data type used in the :ref:`getting started section `: .. literalinclude:: ../code/getting_started/include/HelloWorldTypeSupport.hpp :language: c++ :start-after: // GETTING_STARTED_TYPE_SUPPORT :end-before: //! GETTING_STARTED_TYPE_SUPPORT