Exemple #1
0
    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;
        }
    }
Exemple #2
0
    void serialize_vc6(SF::Archive & ar, boost::array<T, N> & a, const unsigned int)
    {
        if (ar.isRead())
        {
            unsigned int count = 0;
            ar & count;

            RCF_VERIFY(
                count == a.size(), 
                RCF::Exception(RCF::_RcfError_RcfError_ArraySizeMismatch(a.size(), count)));

            for (std::size_t i=0; i<a.size(); ++i)
            {
                ar & a[i];
            }
        }
        else if (ar.isWrite())
        {
            unsigned int count = a.size();
            ar & count;

            for (std::size_t i=0; i<a.size(); ++i)
            {
                ar & a[i];
            }
        }
    }
Exemple #3
0
    void serialize_vc6(
        SF::Archive &                                       ar, 
        boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) > &    v,
        const unsigned int)
    {
        if (ar.isWrite())
        {
            ar & int(v.which());
            VariantSerializer variantSerializer(ar);
            v.apply_visitor(variantSerializer);
        }
        else
        {
            int which = 0;
            ar & which;
            
            typedef BOOST_DEDUCED_TYPENAME 
                boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types types;

            if(which >=  boost::mpl::size<types>::value)
            {
                RCF::Exception e( 
                    RCF::_RcfError_VariantDeserialization(
                        which, 
                        boost::mpl::size<types>::value), 
                    "boost::variant mismatch");

                RCF_THROW(e);
            }

            VariantDeserializer<types>::load(ar, which, v);
        }
    }
Exemple #4
0
    inline void serializeString(SF::Archive & ar, std::basic_string<C,T,A> & s)
    {
        if (ar.isRead())
        {
            boost::uint32_t count = 0;
            ar & count;

            SF::IStream &is = *ar.getIstream();

            s.resize(0);

            std::size_t minSerializedLength = sizeof(C);
            if (ar.verifyAgainstArchiveSize(count*minSerializedLength))
            {
                if (count > s.capacity())
                {
                    s.reserve(count);
                }
            }

            boost::uint32_t charsRemaining = count;
            const boost::uint32_t BufferSize = 512;
            C buffer[BufferSize];
            while (charsRemaining)
            {
                boost::uint32_t charsToRead = RCF_MIN(BufferSize, charsRemaining);
                boost::uint32_t bytesToRead = charsToRead*sizeof(C);

                RCF_VERIFY(
                    is.read( (char *) buffer, bytesToRead) == bytesToRead,
                    RCF::Exception(RCF::_SfError_ReadFailure()))
                    (bytesToRead)(BufferSize)(count);

                s.append(buffer, charsToRead);
                charsRemaining -= charsToRead;
            }
        }
        else if (ar.isWrite())
        {
            boost::uint32_t count = static_cast<boost::uint32_t >(s.length());
            ar & count;
            ar.getOstream()->writeRaw(
                (char *) s.c_str(),
                count*sizeof(C));
        }

    }
Exemple #5
0
 inline void serialize(SF::Archive &ar, std::basic_string<C,T,A> &t, const unsigned int)
 {
     if (ar.isRead()) 
     {
         C *pch = NULL;
         UInt32 length = 0;
         ar & SF::Archive::Flag( SF::Archive::NO_BEGIN_END ) & dynamicArray(pch, length);
         t.assign(pch, length);
         delete [] pch;
     }
     else if (ar.isWrite()) 
     {
         C *pch = const_cast<C *>(t.c_str());
         UInt32 length = static_cast<UInt32>(t.length());
         ar & SF::Archive::Flag( SF::Archive::NO_BEGIN_END ) & dynamicArray(pch, length);
     }
 }
    inline void serializeRefCountedSmartPtr(SmartPtrT **ppt, SF::Archive &ar)
    {
        if (ar.isRead())
        {
            if (ar.isFlagSet(Archive::POINTER))
            {
                *ppt = new SmartPtrT;
            }
            T *pt = NULL;
            ar & pt;

            ContextRead &ctx = ar.getIstream()->getTrackingContext();
            if (!ctx.getEnabled())
            {
                // No pointer tracking.
                **ppt = SmartPtrT(pt);
            }
            else
            {
                // Pointer tracking enabled, so some extra gymnastics involved.
                void *pv = NULL;
                if (pt && ctx.getEnabled() && ctx.query((void *)pt, typeid(SmartPtrT), pv))
                {
                    SmartPtrT *ps_prev = reinterpret_cast<SmartPtrT *>(pv);
                    **ppt = *ps_prev;
                }
                else if (pt)
                {
                    if (ctx.getEnabled())
                    {
                        ctx.add((void *)pt, typeid(SmartPtrT), *ppt);
                    }
                    **ppt = SmartPtrT(pt);
                }
            }
        }
        else /*if (ar.isWrite())*/
        {
            T *pt = NULL;
            if (*ppt)
            {
                pt = (**ppt).get();
            }
            ar & pt;
        }
    }
Exemple #7
0
 void serialize(SF::Archive &ar)
 {
     RCF_ASSERT(ar.isRead() || ar.isWrite());
     switch (mWhich)
     {
     case 0:
         ar & a1 & a2;
         break;
     case 1:
         ar & a1 & a2;
         throw MyException();
         ar & a3;
         break;
     case 2:
         ar & a3;
         break;
     default:
         RCF_ASSERT(0);
     }
 }
    inline void serializeFundamental(
        SF::Archive &ar, 
        T &t,
        unsigned int count = 1)
    {
        typedef typename RCF::RemoveCv<T>::type U;
        BOOST_STATIC_ASSERT( RCF::IsFundamental<U>::value );
        U * pt = const_cast<U *>(&t);

        if (ar.isRead())
        {
            I_Encoding &encoding = ar.getIstream()->getEncoding();
            DataPtr data;
            ar.getIstream()->get(data);
            if (count > 1 && count != encoding.getCount(data, pt) )
            {
                // static array size mismatch
                RCF::Exception e(RCF::_SfError_DataFormat());
                RCF_THROW(e)(typeid(U).name())(count)(encoding.getCount(data, pt));
            }
            encoding.toObject(data, pt, count);
        }
        else if (ar.isWrite())
        {
            I_Encoding &encoding = ar.getOstream()->getEncoding();
            DataPtr data;
            encoding.toData(data, pt, count );
            ar.getOstream()->put(data);
        }
    }
Exemple #9
0
    inline void serializeFundamental(SF::Archive &ar, T &t, const unsigned int, unsigned int count = 1)
    {
        typedef typename boost::remove_const<T>::type U;
        BOOST_STATIC_ASSERT( boost::is_fundamental<U>::value );
        U *pu = const_cast<U *>(&t);
        void *pvt = pu;

        if (ar.isRead()) 
        {
            I_Encoding &encoding = dynamic_cast<I_WithEncoding *>(ar.getStream())->getEncoding();
            DataPtr data;
            dynamic_cast<WithFormatRead *>(ar.getStream())->get(data);
            if (count > 1 && count != encoding.getCount(data,typeid(U)) )
            {
                SF_THROW(SF::Exception, "Static array size mismatch" )(typeid(U).name())(count)(encoding.getCount(data,typeid(T)));
            }
            encoding.toObject(data, pvt, typeid(T), count );
        }
        else if (ar.isWrite()) 
        {
            I_Encoding &encoding = dynamic_cast<I_WithEncoding *>(ar.getStream())->getEncoding();
            DataPtr data;
            encoding.toData(data, pvt, typeid(U), count );
            dynamic_cast<WithFormatWrite *>(ar.getStream())->put(data);
        }
    }
 void SerializerAny<T>::serialize(SF::Archive &ar, boost::any &a)
 {
     if (ar.isWrite())
     {
         ar & boost::any_cast<T>(a);
     }
     else
     {
         T t;
         ar & t;
         a = t;
     }
 }
 inline void serializeSimpleSmartPtr(SmartPtrT **ppt, SF::Archive &ar)
 {
     if (ar.isRead())
     {
         if (ar.isFlagSet(Archive::POINTER))
         {
             *ppt = new SmartPtrT();
         }
         T *pt = NULL;
         ar & pt;
         (**ppt).reset(pt);
     }
     else if (ar.isWrite())
     {
         T *pt = NULL;
         if (*ppt && (**ppt).get())
         {
             pt = (**ppt).operator->();
         }
         ar & pt;
     }
 }
Exemple #12
0
    void serialize_vc6(SF::Archive & ar, std::tr1::array<T, N> & a, const unsigned int)
    {
        if (ar.isRead())
        {
            unsigned int count = 0;
            ar & count;
            RCF_VERIFY(count == a.size(), RCF::Exception());

            for (std::size_t i=0; i<a.size(); ++i)
            {
                ar & a[i];
            }
        }
        else if (ar.isWrite())
        {
            unsigned int count = a.size();
            ar & count;

            for (std::size_t i=0; i<a.size(); ++i)
            {
                ar & a[i];
            }
        }
    }
    // serialization for boost::any
    void serialize(SF::Archive &ar, boost::any &a)
    {
        if (ar.isWrite())
        {
            std::string which = 
                SF::Registry::getSingleton().getTypeName(a.type());

            if (which.empty() && !a.empty())
            {
                RCF_THROW(RCF::Exception(RCF::_RcfError_AnyTypeNotRegistered(a.type().name())));
            }

            ar & which;

            if (!a.empty())
            {
                RCF_ASSERT(which.size() > 0);

                SF::Registry::getSingleton().getAnySerializer(which)
                    .serialize(ar, a);
            }
        }
        else
        {
            std::string which;
            ar & which;
            if (which.empty())
            {
                a = boost::any();
            }
            else
            {
                SF::Registry::getSingleton().getAnySerializer(which)
                    .serialize(ar, a);
            }
        }
    }
Exemple #14
0
    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;
                    }
                }
            }
        }
    }
Exemple #15
0
    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);
            }
        }
    }
Exemple #16
0
    void serialize(SF::Archive &ar, RCF::ByteBuffer &byteBuffer)
    {
        if (ar.isRead())
        {
            boost::uint32_t len = 0;
            ar & len;

            byteBuffer.clear();

            // See if we have a remote call context.
            RCF::SerializationProtocolIn *pIn = 
                ar.getIstream()->getRemoteCallContext();

            if (pIn && len)
            {
                pIn->extractSlice(byteBuffer, len);
            }
            else if (len)
            {
                if (byteBuffer.getLength() >= len)
                {
                    byteBuffer = RCF::ByteBuffer(byteBuffer, 0, len);
                }
                else
                {
                    byteBuffer = RCF::ByteBuffer(len);
                }

                SF::IStream &is = *ar.getIstream();

                boost::uint32_t bytesToRead = len;
                boost::uint32_t bytesRead = is.read( (SF::Byte8 *) byteBuffer.getPtr(), bytesToRead);

                RCF_VERIFY(
                    bytesRead == bytesToRead,
                    RCF::Exception(RCF::_SfError_ReadFailure()))
                    (bytesToRead)(bytesRead);
            }
        }
        else if (ar.isWrite())
        {
            boost::uint32_t len = static_cast<boost::uint32_t>(byteBuffer.getLength());
            ar & len;

            // See if we have a remote call context.
            RCF::SerializationProtocolOut *pOut = 
                ar.getOstream()->getRemoteCallContext();

            if (pOut && len)
            {
                pOut->insert(byteBuffer);
            }
            else if (len)
            {
                boost::uint32_t bytesToWrite = len;
                ar.getOstream()->writeRaw(
                    (SF::Byte8 *) byteBuffer.getPtr(),
                    bytesToWrite);
            }
        }
    }
Exemple #17
0
    void serialize(SF::Archive &ar, RCF::ByteBuffer &byteBuffer)
    {
        RCF::SerializationProtocolIn *pIn = NULL;
        RCF::SerializationProtocolOut *pOut = NULL;

        RCF::ClientStub * pClientStub = RCF::getCurrentClientStubPtr();
        RCF::RcfSession * pRcfSession = RCF::getCurrentRcfSessionPtr();
        if (pClientStub)
        {
            pIn = &pClientStub->getSpIn();
            pOut = &pClientStub->getSpOut();
        }
        else if (pRcfSession)
        {
            pIn = &pRcfSession->getSpIn();
            pOut = &pRcfSession->getSpOut();
        }

        if (ar.isRead())
        {
            boost::uint32_t len = 0;
            ar & len;

            byteBuffer.clear();

            RCF::SerializationProtocolIn *pIn = 
                RCF::getCurrentSerializationProtocolIn();

            if (pIn && len)
            {
                pIn->extractSlice(byteBuffer, len);
            }
            else if (len)
            {
                byteBuffer = RCF::ByteBuffer(len);

                SF::IStream &is = *ar.getIstream();

                boost::uint32_t bytesToRead = len;
                boost::uint32_t bytesRead = is.read( (SF::Byte8 *) byteBuffer.getPtr(), bytesToRead);

                RCF_VERIFY(
                    bytesRead == bytesToRead,
                    RCF::Exception(RCF::_SfError_ReadFailure()))
                    (bytesToRead)(bytesRead);
            }
        }
        else if (ar.isWrite())
        {
            boost::uint32_t len = static_cast<boost::uint32_t>(byteBuffer.getLength());
            ar & len;

            RCF::SerializationProtocolOut *pOut = 
                RCF::getCurrentSerializationProtocolOut();

            if (pOut && len)
            {
                pOut->insert(byteBuffer);
            }
            else if (len)
            {
                boost::uint32_t bytesToWrite = len;
                ar.getOstream()->writeRaw(
                    (SF::Byte8 *) byteBuffer.getPtr(),
                    bytesToWrite);
            }
        }
    }