It is often the case that you want to send a container such as Vector through C++ message class. Unlike Java or .NET that has container implementing serializable interface, you need to manually serialize your container in onSerialize and onDeserialize methods of your message class.
Here is the sample snippet of code.
Make sure you write the size of you container to the output stream. Also, make sure you write each element of the container one by one to the output stream. In the same way, read the size and each element of your container from the input stream.Code:void MyMessage::onSerialize(OutputStreamPtr &stream) throw (SoamException) { stream->write(m_int); stream->write(m_isSync); stream->write(m_vectorSize); for (int i=0; i<m_vectorSize; i++) { stream->write(m_inputVector.at(i)); } } void MyMessage::onDeserialize(InputStreamPtr &stream) throw (SoamException) { stream->read(m_int); stream->read(m_isSync); stream->read(m_vectorSize); for (int i=0; i<m_vectorSize; i++) { std::string f; stream->read(f); m_inputVector.push_back(f); } }
If you fail to serialize and deserialize the size of your container, it will result in core dump.


LinkBack URL
About LinkBacks
Reply With Quote
