Dynamic deserialization problem

1 post / 0 new
Last seen: 2 years 3 months ago
Joined: 05/07/2018
Posts: 1
Dynamic deserialization problem

Hi everybody, I'm writing code to deserialize data from various publish services with different idl's.

The code that I'm using to deserialize is:

void iBR::DynamicDataUtilities::deserializeChunks(
    DDSDomainParticipant* participant,
    std::queue<iBR::DataTypes::IBChunk>& chunks) 
    using namespace iB;
    INFO("DynamicDataUtilities", "chunks length: " + numToStr(chunks.size()));

    FILE* file = fopen("pruebas.dat", "a+");
    RTICdrStream stream;
    for (unsigned int i = 0; i < chunks.size(); i++) {
        // Deserializing typecode...
        iBR::DataTypes::IBChunk chunk = chunks.front();
        int typeLen = iBR::DataTypes::SERIALIZED_TYPE_MAX_LEN;

        char typeCodeBuffer[typeLen];
        chunk.type.to_array((unsigned char*)typeCodeBuffer, typeLen);
        DDS_TypeCode *typeCode = iBR::TypeCodeUtilities::
            deserialize_TypeCode(typeCodeBuffer, typeLen);

        DDSDynamicDataTypeSupport* typeSupport = 
            new DDSDynamicDataTypeSupport(typeCode, 
        DDS_DynamicData* sample= typeSupport->create_data();

        // Deserializing payload...
        int payloadLen = chunk.serialized_data_len;
        unsigned char payload[payloadLen];
        chunk.data.to_array(payload, payloadLen);

        RTICdrStream_set(&stream, (char*)payload, payloadLen);

        //fwrite(payload, sizeof(char), payloadLen, file);
        if (!(sample->is_valid())) {
            printf("deserialization data type problem!");
        sample->print(file, 1);


IBChunk is a struct containing two buffers, one of them to save types and the other one to save payload/data.

Types are deserialized in a right way, but payload deserialization is wrong, it starts right, but it seems to be broken after the first field of the payload struct, the line in cuestion is:

 I have downloaded an example from Gerardo, but he is using a line of code from rti connext internals.
Some suggestion about this issue?. Thank you in advange.