void decodeByteBuffer( RCF::ByteBuffer & value, const RCF::ByteBuffer & byteBuffer, std::size_t & pos) { int len_ = 0; decodeInt(len_, byteBuffer, pos); std::size_t len = static_cast<unsigned int>(len_); RCF_VERIFY( pos+len <= byteBuffer.getLength(), RCF::Exception(RCF::_RcfError_Decoding())); if (len == 0) { value = RCF::ByteBuffer(value, 0, 0); } else { if (value.getLength() < len) { value = RCF::ByteBuffer(len); } value = RCF::ByteBuffer(value, 0, len); memcpy(value.getPtr(), byteBuffer.getPtr()+pos, len); } pos += len; }
void decodeInt(int &value, const RCF::ByteBuffer &byteBuffer, std::size_t &pos) { RCF_VERIFY( pos+1 <= byteBuffer.getLength(), RCF::Exception(RCF::_RcfError_Decoding())); unsigned char ch = byteBuffer.getPtr()[pos]; pos += 1; if (ch < 255) { value = ch; } else { RCF_VERIFY( pos+4 <= byteBuffer.getLength(), RCF::Exception(RCF::_RcfError_Decoding())); BOOST_STATIC_ASSERT(sizeof(int) == 4); memcpy(&value, byteBuffer.getPtr()+pos, 4); RCF::networkToMachineOrder(&value, 4, 1); pos += 4; } }
void RcfProtoServer::ProtoRpcBeginCpp( RcfProtoSession & rcfProtoSession, const std::string & serviceName, int methodId) { RcfProtoControllerPtr controller( new RcfProtoController(rcfProtoSession) ); Service * pService = NULL; ProtobufServices::iterator iter = mProtobufServices.find(serviceName); if (iter != mProtobufServices.end()) { pService = iter->second; } if (!pService) { std::string errorMsg = "The requested service does not exist on this server. Service name: " + serviceName; controller->SetFailed(errorMsg); return; } const ServiceDescriptor * sd = pService->GetDescriptor(); const MethodDescriptor * md = sd->method(methodId); MessagePtr requestPtr( pService->GetRequestPrototype(md).New() ); MessagePtr responsePtr( pService->GetResponsePrototype(md).New() ); RCF::ByteBuffer requestBuffer = controller->mpRcfSession->mRequestBuffer; requestPtr->ParseFromArray(requestBuffer.getPtr(), (int) requestBuffer.getLength()); std::pair<MessagePtr, MessagePtr> requestResponsePair(requestPtr, responsePtr); Closure * done = NewCallback(this, &RcfProtoServer::ProtoRpcEndCpp, requestResponsePair, controller); pService->CallMethod(md, controller.get(), requestPtr.get(), responsePtr.get(), done); }
void encodeBool(bool value, const RCF::ByteBuffer &byteBuffer, std::size_t &pos) { RCF_ASSERT_LTEQ(pos+1 , byteBuffer.getLength()); value ? byteBuffer.getPtr()[pos] = 1 : byteBuffer.getPtr()[pos] = 0; pos += 1; }
void encodeInt(int value, const RCF::ByteBuffer &byteBuffer, std::size_t &pos) { if (0 <= value && value < 255) { RCF_ASSERT_LTEQ(pos+1 , byteBuffer.getLength()); byteBuffer.getPtr()[pos] = static_cast<char>(value); pos += 1; } else { RCF_ASSERT_LTEQ(pos+1 , byteBuffer.getLength()); byteBuffer.getPtr()[pos] = (unsigned char)(255); pos += 1; RCF_ASSERT_LTEQ(pos+4 , byteBuffer.getLength()); BOOST_STATIC_ASSERT(sizeof(int) == 4); RCF::machineToNetworkOrder(&value, 4, 1); memcpy(&byteBuffer.getPtr()[pos], &value, 4); pos += 4; } }
void Win32Certificate::exportToPfx(const std::string & pfxFilePath) { RCF::ByteBuffer pfxBuffer = exportToPfx(); // Write the data to file. FILE * fp = fopen(pfxFilePath.c_str(), "wb"); if (!fp) { RCF_THROW( Exception(_RcfError_FileOpenWrite(pfxFilePath)) ); } fwrite(pfxBuffer.getPtr(), sizeof(char), pfxBuffer.getLength(), fp); fclose(fp); }
void decodeBool(bool &value, const RCF::ByteBuffer &byteBuffer, std::size_t &pos) { RCF_VERIFY( pos+1 <= byteBuffer.getLength(), RCF::Exception(RCF::_RcfError_Decoding())); char ch = byteBuffer.getPtr()[pos]; RCF_VERIFY( ch == 0 || ch == 1, RCF::Exception(RCF::_RcfError_Decoding())); pos += 1; value = ch ? true : false; }
void encodeByteBuffer( RCF::ByteBuffer value, std::vector<char> & vec, std::size_t & pos) { int len = static_cast<int>(value.getLength()); SF::encodeInt(len, vec, pos); RCF_ASSERT_LTEQ(pos , vec.size()); if (pos + len > vec.size()) { vec.resize(vec.size()+len); } memcpy(&vec[pos], value.getPtr(), len); pos += len; }
void decodeString( std::string &value, const RCF::ByteBuffer &byteBuffer, std::size_t &pos) { int len_ = 0; decodeInt(len_, byteBuffer, pos); std::size_t len = static_cast<unsigned int>(len_); RCF_VERIFY( pos+len <= byteBuffer.getLength(), RCF::Exception(RCF::_RcfError_Decoding())); value.assign(byteBuffer.getPtr()+pos, len); pos += len; }
void FileIoRequest::write(boost::shared_ptr<std::ofstream> foutPtr, RCF::ByteBuffer buffer) { RCF_LOG_4()(foutPtr.get())((void*)buffer.getPtr())(buffer.getLength()) << "FileIoRequest::write()"; mFinPtr.reset(); mFoutPtr = foutPtr; mBuffer = buffer; mBytesTransferred = 0; mInitiated = true; mCompleted = false; mFts.registerOp( shared_from_this() ); // For debugging purposes, we can wait in this function until the file I/O is completed. if (mFts.mSerializeFileIo) { RCF::Lock lock(mFts.mCompletionMutex); while (!mCompleted) { mFts.mCompletionCondition.wait(lock); } } }
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); } } }
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); } } }