Dynamic deserialization problem

1 post / 0 new
Offline
Last seen: 1 year 5 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;
    RTICdrStream_init(&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_DYNAMIC_DATA_TYPE_PROPERTY_DEFAULT);
        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);
        sample->from_stream(stream);
        if (!(sample->is_valid())) {
            printf("deserialization data type problem!");
            continue;
        }
        sample->print(file, 1);
        chunks.pop();
        typeSupport->delete_data(sample);
    }
    fclose(file);
}

 


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:

        sample->from_stream(stream);
 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.
 

 

 

Organization: