Defining the classes for the PiPS type implementation

Updated: April 19, 2023
The next step is to create a C++ compilation unit that defines the PiPS type implementation as well as an instance class. Both classes are derived from base classes defined in pips/fastrtps/type-impl.h. The unit's source file (which we call DataBuffer-impl.cxx) must include this and the other Fast RTPS provider header files, and those for the Fast RTPS type definition:
// Fast RTPS PiPS includes
#include <pips/fastrtps/publication.h>
#include <pips/fastrtps/type.h>
#include <pips/fastrtps/type-impl.hxx>
 
// fastrtpsgen includes
#include <DataBuffer.h>
#include <DataBufferPubSubTypes.h>
The type implementation class is named DataBufferType and extends the TypeImpl class, while the instance class is named Instance and extends the TypeInstance class. Note that Instance is defined as a nested class. This is not strictly necessary but is convenient for avoiding name collisions. Each DataBufferType::Instance object will have a DataBuffer object associated with it:
struct DataBufferType : public TypeImpl {
public:
    class Instance : public TypeInstance {
    public:
        Instance( DataBufferPubSubType& type );
        void initSample( void* sample, const pips_guid_t* guid ) const;
        TypeInstance& operator=( const void* sample_data );
    private:
        DataBuffer m_data;
    };

    static TypeImpl* Impl();
    DataBufferType();
    Instance* createInstance();
    int encodeCSTRUCT( const TypeInstance* sample, const char* name, 
                       pips_data_t* buffer, const size_t buffer_size );
    int encodePPS( const TypeInstance* sample, const char* name, 
                   pips_data_t* buffer, const size_t buffer_size );
    int decodeCSTRUCT( const pips_data_t data, const size_t data_size, 
                       fastrtps_type_instance_t** instance, const pips_guid_t* guid = nullptr );
    int decodePPS( const pips_data_t data, const size_t data_size, 
                   fastrtps_type_instance_t** instance, const pips_guid_t* guid = nullptr );

private:
    DataBufferPubSubType    m_type;
    static DataBufferType   m_impl;
};