[RESOLVED] Cannot deserialize successfully

5 posts / 0 new
Last post
Offline
Last seen: 10 years 8 months ago
Joined: 01/23/2014
Posts: 3
[RESOLVED] Cannot deserialize successfully

I have been working with some examples to serialize and then deserialize an object created via: ::create_data()

Following the exmples found here, I am able to successfully serialize using the something like the code below:    instance = CSA_SecOpEnvServer_ServerComponentMgmt_AppControls_StopComponentCommandTypeTypeSupport::create_data();

    int buffSz;
    char *buffer;
    struct RTICdrStream mystrm;
    PRESTypePluginEndpointData endpoint_data;
   
    instance->processID = 1234;
    instance->timestamp = (RTICdrDouble)100.52;
    instance->description = "first time to go";
    instance->elementID = "1234";

    buffSz = CSA_SecOpEnvServer_ServerComponentMgmt_AppControls_StopComponentCommandTypePlugin_get_serialized_sample_size(
        endpoint_data,
        RTI_FALSE,
        RTI_CDR_ENCAPSULATION_ID_CDR_NATIVE,  // from cdr_encapsulation.h
        0,  //current alignment (start of buffer = 0)
        instance);
    buffer = (char *)malloc(buffSz);
    RTICdrStream_init(&mystrm);
    RTICdrStream_set( &mystrm, buffer, buffSz ) ;

    if (!CSA_SecOpEnvServer_ServerComponentMgmt_AppControls_StopComponentCommandTypePlugin_serialize(
        endpoint_data, //PRESTypePluginEndpointData endpoint_data,
        instance,      //const CSA_SecOpEnvServer_ServerComponentMgmt_AppControls_StopComponentCommandType *sample,
        &mystrm,       //struct RTICdrStream *stream,
        RTI_FALSE,      //RTIBool serialize_encapsulation,
        RTI_CDR_ENCAPSULATION_ID_CDR_NATIVE,  // from cdr_encapsulation.h
        RTI_TRUE,      //RTIBool serialize_sample,
        NULL)) {       //void *endpoint_plugin_qos
           printf("Serialize CSA_SecOpEnvServer_ServerComponentMgmt_AppControls_StopComponentCommandType, FAILED\n");
    }  

But I get complete failure when I try to deserialize the stream with:

        if (!CSA_SecOpEnvServer_ServerComponentMgmt_AppControls_StopComponentCommandTypePlugin_deserialize_sample(
            endpoint_data, //PRESTypePluginEndpointData endpoint_data,
            instance1alt,     // deserialize into this data packet
            &mystrm,       // struct RTICdrStream *stream,
            RTI_FALSE,      // deserialize encapsulation
            RTI_TRUE,      // deserialize sample
            NULL)) {         // endpoint_plugin_qos
               printf("DeSerialize CSA_SecOpEnvServer_ServerComponentMgmt_AppControls_StopComponentCommandType, FAILED\n");
        }

This failes for the first entity in the structure.

I am not sure, as there is little informatin regarding serialization, if there are other actions I must take

Thanks for any help given.

rose's picture
Offline
Last seen: 3 years 3 months ago
Joined: 08/22/2011
Posts: 148

Hello Mark, 

It is unusual to serialize or deserialize data directly – can I ask what your use case is?  I might be able to suggest an easier way to do what you need.

Thank you!

Rose

Offline
Last seen: 10 years 8 months ago
Joined: 01/23/2014
Posts: 3

Thank you Rose for answering.

Yes, I have a need to serialize the received data for long term storage, which is under the control of an existing product. This will be later analyzised for debugging purposes at a remote location or reinjected into the system, again for debugging, integration of system wide analysis.

The serialized data will be stored to the same content storage device as that from many other transport mechanisms, such as UDP, TCP, CORBA, etc.

What I need is the abiltiy to opaquely grab the payload, do a quick filter based on my recording needs, and then suffle that payload, wrapped in a new metadata packet, to the recording service. It is very likely, that all this data will be, at some time fed back into another system or decoded for content and timing.

Mark

Offline
Last seen: 10 years 8 months ago
Joined: 01/23/2014
Posts: 3

Rose,

Thank you for your help. I found my issue. Just like a newbee might do, I used the same stream for serializing and deserializing. The problem occured becauase I forgot to reset the _currentPosition counter. When I performed the deserialize, it was grabbing from the wrong posistion in the buffer.

Seems to work now,

PEBKAC

Mark

rose's picture
Offline
Last seen: 3 years 3 months ago
Joined: 08/22/2011
Posts: 148

Hello Mark,

That is great to hear – thank you for the update!

Rose