Archived

This forum has been archived. Please start a new discussion on GitHub.

Anything wrong with this streaming code?

I'm trying to use the streaming API to serialize a dictionary. The dictionary uses user defined types as the values and the slice files were compiled with the --stream option.

Here's a snippet of the code. After reading the bytes using the InputStreamPtr, I cannot access the dictionary values. The key seems to be there but I get NullHandleException when trying to access the value. Am I missing anything from the API?

Thanks
    gametypes::RecoveryTaskMap::const_iterator I;
    for (I = m_lstRecoveryTasks.begin(); I != m_lstRecoveryTasks.end(); ++I)
    {
        std::cout << "writing array: " << I->first << std::endl;
        std::cout << "writing array: " << I->second->recoveryTaskId << std::endl;
    }

    std::vector<unsigned char> lstElementData;
    Ice::OutputStreamPtr pOutputStream = Ice::createOutputStream(m_pIceComm);
    pOutputStream->write(m_lstRecoveryTasks);
    pOutputStream->finished(lstElementData);

    // Readback the data
    Ice::InputStreamPtr pInputStream = Ice::createInputStream(m_pIceComm, lstElementData);
    gametypes::RecoveryTaskMap tempMap;
    pInputStream->read(tempMap);

    for (I = tempMap.begin(); I != tempMap.end(); ++I)
    {
        std::cout << "re-reading array: " << I->first << std::endl;
        std::cout << "re-reading array: " << I->second->recoveryTaskId << std::endl;
    }

Comments

  • mes
    mes California
    Hi Budyanto,

    Are you using classes as the dictionary values? If so, you need to invoke writePendingObjects on the output stream prior to calling finished. Similarly, you need to call readPendingObjects on the input stream as the last step before you can safely use the unmarshaled values.

    If you are not using classes, please describe your Slice types.

    Regards,
    Mark
  • Hi Mark,

    Yes they are classes. And yes adding those calls does fix it.

    Thanks
    Budyanto