Пример #1
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);
            }
        }
    }
Пример #2
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);
            }
        }
    }