void RemoteException::serialize(SF::Archive &ar) { if (ar.getRuntimeVersion() <= 5) { int errorId = mError.getErrorId(); ar & mWhat & mContext & errorId & mSubSystemError & mSubSystem & mRemoteExceptionType; if (ar.isRead()) { mError.setErrorId(errorId); } } else { ar & mWhat & mContext & mError & mSubSystemError & mSubSystem & mRemoteExceptionType; } }
void serializeVectorFastImpl( SF::Archive & ar, I_VecWrapper & vec) { if (ar.isRead()) { boost::uint32_t count = 0; ar & count; if (count) { SF::IStream &is = *ar.getIstream(); vec.resize(0); std::size_t minSerializedLength = vec.sizeofElement(); if (ar.verifyAgainstArchiveSize(count*minSerializedLength)) { // Size field is verified, so read everything in one go. vec.resize(count); boost::uint32_t bytesToRead = count * vec.sizeofElement(); boost::uint32_t bytesActuallyRead = is.read( vec.addressOfElement(0), bytesToRead); RCF_VERIFY( bytesActuallyRead == bytesToRead, RCF::Exception(RCF::_SfError_ReadFailure())) (bytesActuallyRead)(bytesToRead)(count); // Byte ordering. if (ar.getRuntimeVersion() >= 8) { RCF::networkToMachineOrder( vec.addressOfElement(0), static_cast<int>(vec.sizeofElement()), static_cast<int>(vec.size())); } } else { // Size field not verified, so read in chunks. boost::uint32_t elementsRemaining = count; while (elementsRemaining) { const boost::uint32_t ElementsMax = 50*1024; boost::uint32_t elementsRead = count - elementsRemaining; boost::uint32_t elementsToRead = RCF_MIN(ElementsMax, elementsRemaining); boost::uint32_t bytesToRead = elementsToRead*vec.sizeofElement(); vec.resize( vec.size() + elementsToRead); boost::uint32_t bytesRead = is.read( vec.addressOfElement(elementsRead), bytesToRead); RCF_VERIFY( bytesRead == bytesToRead, RCF::Exception(RCF::_SfError_ReadFailure())) (bytesRead)(bytesToRead)(ElementsMax)(count); elementsRemaining -= elementsToRead; } // Byte ordering. if (ar.getRuntimeVersion() >= 8) { RCF::networkToMachineOrder( vec.addressOfElement(0), static_cast<int>(vec.sizeofElement()), static_cast<int>(vec.size())); } } } } else if (ar.isWrite()) { boost::uint32_t count = static_cast<boost::uint32_t>(vec.size()); ar & count; if (count) { boost::uint32_t bytesToWrite = count * vec.sizeofElement(); if (RCF::machineOrderEqualsNetworkOrder()) { // Don't need reordering, so write everything in one go. ar.getOstream()->writeRaw( vec.addressOfElement(0), bytesToWrite); } else if (ar.getRuntimeVersion() < 8) { // Don't need reordering, so write everything in one go. ar.getOstream()->writeRaw( vec.addressOfElement(0), bytesToWrite); } else { // Reordering needed, so we go through a temporary buffer. boost::uint32_t elementsRemaining = count; const boost::uint32_t BufferSize = 100*1024; const boost::uint32_t ElementsMax = BufferSize / vec.sizeofElement(); char Buffer[BufferSize]; while (elementsRemaining) { boost::uint32_t elementsWritten = count - elementsRemaining; boost::uint32_t elementsToWrite = RCF_MIN(ElementsMax, elementsRemaining); boost::uint32_t bytesToWrite = elementsToWrite*vec.sizeofElement(); memcpy( (char *) &Buffer[0], vec.addressOfElement(elementsWritten), bytesToWrite); RCF::machineToNetworkOrder( &Buffer[0], vec.sizeofElement(), elementsToWrite); ar.getOstream()->writeRaw( (char *) &Buffer[0], bytesToWrite); elementsRemaining -= elementsToWrite; } } } } }
inline void serializeEncodedString(SF::Archive & ar, std::basic_string<C,T,A> & ws) { if (ar.getRuntimeVersion() < 8) { serializeString(ar, ws); return; } RCF_ASSERT_GTEQ(ar.getRuntimeVersion() , 8); if (ar.isRead()) { int encodingType = 0; ar & encodingType; if (encodingType == 8) { // UTF-8 serialization. std::string s; ar & s; ws = RcfBoost::boost::from_utf8(s); } else { // Native wchar_t serialization. RCF_VERIFY( encodingType == sizeof(wchar_t), RCF::Exception( RCF::_RcfError_WcharSizeMismatch(sizeof(wchar_t), encodingType))); serializeString(ar, ws); } } else if (ar.isWrite()) { bool useNativeWstringSerialization = SF::getCurrentNativeWstringSerialization(); int encodingType = sizeof(wchar_t); if (useNativeWstringSerialization) { encodingType = sizeof(wchar_t); } else { encodingType = 8; } ar & encodingType; if (encodingType == 8) { // UTF-8 serialization. std::string s = RcfBoost::boost::to_utf8(ws); ar & s; } else { // Native wchar_t serialization. RCF_VERIFY( encodingType == sizeof(wchar_t), RCF::Exception( RCF::_RcfError_WcharSizeMismatch(sizeof(wchar_t), encodingType))); serializeString(ar, ws); } } }