void boost_floyd_warshall(std::shared_ptr<graph_generator> graph) { typedef boost::multi_array<zbp::weight, 2> array_type; array_type D(boost::extents[graph->size()][graph->size()]); boost::floyd_warshall_all_pairs_shortest_paths(*graph->boost_weighted_graph(), D); #ifdef DEBUG std::cout << " "; for (size_t k = 0; k < graph->size(); ++k) { std::cout << std::setw(5) << k; } std::cout << std::endl; for (size_t i = 0; i < graph->size(); ++i) { std::cout << std::setw(3) << i << " -> "; for (size_t j = 0; j < graph->size(); ++j) { if (D[i][j] == (std::numeric_limits<int>::max)()) { std::cout << std::setw(5) << "x"; } else { std::cout << std::setw(5) << D[i][j]; } } std::cout << std::endl; } #endif }
//----------------------------------------------------------------------------- PETScLUSolver::PETScLUSolver(MPI_Comm comm, std::shared_ptr<const PETScMatrix> A, std::string method) : _ksp(NULL), _matA(A) { // Check dimensions if (A) { if (A->size(0) != A->size(1)) { dolfin_error("PETScLUSolver.cpp", "create PETSc LU solver", "Cannot LU factorize non-square PETSc matrix"); } } // Set parameter values parameters = default_parameters(); PetscErrorCode ierr; // Create solver ierr = KSPCreate(comm, &_ksp); if (ierr != 0) petsc_error(ierr, __FILE__, "KSPCreate"); // Select solver (must come after KSPCreate, becuase we get the MPI // communicator from the KSP object) _solver_package = select_solver(comm, method); // Make solver preconditioner only ierr = KSPSetType(_ksp, KSPPREONLY); if (ierr != 0) petsc_error(ierr, __FILE__, "KSPSetType"); // Set from PETSc options KSPSetFromOptions(_ksp); }
virtual void _Send_back_history(std::shared_ptr<protocol::Invoke> invoke, std::shared_ptr<slave::InvokeHistory> $history) { std::shared_ptr<PRInvokeHistory> history = std::dynamic_pointer_cast<PRInvokeHistory>($history); if (history == nullptr) return; // REMOVE UID AND FIRST, LAST INDEXES for (size_t i = invoke->size(); i < invoke->size(); i--) { const std::string &name = invoke->at(i)->getName(); if (name == "_History_uid" || name == "_Piece_first" || name == "_Piece_last") invoke->erase(invoke->begin() + i); } // RE-SEND (DISTRIBUTE) THE PIECE TO OTHER SLAVES std::thread ( &base::ParallelSystemArrayBase::sendPieceData, (base::ParallelSystemArrayBase*)system_array_, invoke, history->getFirst(), history->getLast() ).detach(); // ERASE FROM THE PROGRESS LIST progress_list_.erase(history->getUID()); };
void Conn::onRead(const boost::system::error_code& error, std::shared_ptr< boost::asio::streambuf > rd_buf) { if( unlikely(error) ) { log_func("[iproto_conn] %s:%u read error: %s", ep.address().to_string().c_str(), ep.port(), error.message().c_str() ); dismissCallbacks(CB_ERR); if( error != boost::asio::error::operation_aborted ) { reconnect(); } return; } if( unlikely(!rd_buf) ) rd_buf.reset(new boost::asio::streambuf); if( LOG_DEBUG ) log_func("[iproto_conn] %s:%u onRead rd_buf->size=%zu", ep.address().to_string().c_str(), ep.port(), rd_buf->size()); while( rd_buf->size() >= sizeof(Header) ) { const PacketPtr *buf = boost::asio::buffer_cast< const PacketPtr * >( rd_buf->data() ); if( LOG_DEBUG ) log_func("[iproto_conn] %s:%u onRead buffer iproto packet hdr: len=%u sync=%u msg=%u", ep.address().to_string().c_str(), ep.port(), buf->hdr.len, buf->hdr.sync, buf->hdr.msg); size_t want_read = sizeof(Header)+buf->hdr.len; if( want_read <= rd_buf->size() ) { invokeCallback(buf->hdr.sync, RequestResult(CB_OK, Packet(buf)) ); rd_buf->consume( sizeof(Header) + buf->hdr.len ); }else{ size_t rd = want_read - rd_buf->size(); if( LOG_DEBUG ) log_func("[iproto_conn] %s:%u onRead want_read=%zu", ep.address().to_string().c_str(), ep.port(), rd); boost::asio::async_read(sock, *rd_buf, boost::asio::transfer_at_least(rd), boost::bind(&Conn::onRead, shared_from_this(), boost::asio::placeholders::error, rd_buf) ); return; } } if( likely(sock.is_open()) ) boost::asio::async_read(sock, *rd_buf, boost::asio::transfer_at_least(sizeof(Header)-rd_buf->size()), boost::bind(&Conn::onRead, shared_from_this(), boost::asio::placeholders::error, rd_buf) ); }
void ProcessingContextImpl::ProcessDataBlockPhase1( std::shared_ptr<DataBlock> data_block) { size_t data_size = backup_buffer_.size() + data_block->size(); if (data_size > search_text_.size() - 1) data_size -= search_text_.size() - 1; else data_size = 0; for (size_t data_index = 0; data_index < data_size; ++data_index) { bool is_equal; for (size_t text_index = 0; text_index < search_text_.size(); ++text_index) { size_t char_index = data_index + text_index; char ch; if (char_index < backup_buffer_.size()) { ch = backup_buffer_[char_index]; } else { char_index -= backup_buffer_.size(); ch = data_block->data()[char_index]; } is_equal = (ch == search_text_[text_index]); if (!is_equal) break; } if (is_equal) { found_.push_back(current_offset_ + data_index - backup_buffer_.size()); data_index += search_text_.size() - 1; } } current_offset_ += data_block->size(); if (backup_buffer_.size() < search_text_.size() - 1) backup_buffer_.resize(search_text_.size() - 1); if (backup_buffer_.size() <= data_block->size()) memcpy(backup_buffer_.data(), data_block->data() + data_block->size() - backup_buffer_.size(), backup_buffer_.size()); }
void boost_johnson(std::shared_ptr<graph_generator> graph) { graph_generator::BoostWeightedGraph g = *graph->boost_weighted_graph(); typedef boost::multi_array<zbp::weight, 2> array_type; array_type D(boost::extents[graph->size()][graph->size()]); johnson_all_pairs_shortest_paths(g, D); #ifdef DEBUG int V = num_vertices(g); std::cout << " "; for (int k = 0; k < V; ++k) std::cout << std::setw(5) << k; std::cout << std::endl; for (int i = 0; i < V; ++i) { std::cout << std::setw(3) << i << " -> "; for (int j = 0; j < V; ++j) { if (D[i][j] == (std::numeric_limits<int>::max)()) std::cout << std::setw(5) << "x"; else std::cout << std::setw(5) << D[i][j]; } std::cout << std::endl; } #endif }
void receive_hello(std::shared_ptr<tcp::socket> socket , std::shared_ptr<std::vector<std::uint8_t>> buffer , std::size_t const read_size = sizeof(ofp_header)) { auto const read_head = buffer->size(); buffer->resize(read_head + read_size); boost::asio::async_read(*socket , boost::asio::buffer(&(*buffer)[read_head], read_size) , boost::asio::transfer_exactly(read_size) , [=](boost::system::error_code const& ec, std::size_t const) { if (ec) { std::cout << "read error: " << ec.message() << std::endl; return; } auto const header = detail::read_ofp_header(boost::asio::buffer(*buffer)); if (header.type != hello::message_type) { std::cout << "not hello message" << std::endl; return; } if (header.length != buffer->size()) { receive_hello(std::move(socket), std::move(buffer), header.length - buffer->size()); return; } auto channel = std::make_shared<v10::secure_channel_impl<ControllerHandler>>( std::move(*socket), controller_handler_, *thread_pool_); auto it = buffer->begin(); channel->run(hello::decode(it, buffer->end())); }); }
//----------------------------------------------------------------------------- SLEPcEigenSolver::SLEPcEigenSolver(std::shared_ptr<const PETScMatrix> A, std::shared_ptr<const PETScMatrix> B) : _eps(nullptr) { // TODO: deprecate dolfin_assert(A); dolfin_assert(A->size(0) == A->size(1)); if (B) { dolfin_assert(B->size(0) == A->size(0)); dolfin_assert(B->size(1) == A->size(1)); } // Set up solver environment EPSCreate(A->mpi_comm(), &_eps); // Set operators dolfin_assert(_eps); if (B) EPSSetOperators(_eps, A->mat(), B->mat()); else EPSSetOperators(_eps, A->mat(), NULL); // Set default parameter values parameters = default_parameters(); }
void MeshPose::setReferencePose(std::shared_ptr<std::vector<VertexData::Attr>> &vertexData) { m_ReferencePose.resize(vertexData->size()); for ( unsigned int i = 0 ; i < vertexData->size(); i++) { m_ReferencePose[i].set(vertexData->at(i).x, vertexData->at(i).y, vertexData->at(i).z); } }
void Hand::AddToHand(std::shared_ptr<std::vector<Card>> c) { // Resize hand to size of C SetSize(c->size()); // Check needs to make sure we aren't going over hand size of the game for (unsigned int i = 0; i < c->size(); ++i) { m_vHand.at(i) = c->at(i); } }
//----------------------------------------------------------------------------- SLEPcEigenSolver::SLEPcEigenSolver(std::shared_ptr<const PETScMatrix> A) : _matA(A) { dolfin_assert(A->size(0) == A->size(1)); // Set default parameter values parameters = default_parameters(); // Set up solver environment EPSCreate(PETSC_COMM_WORLD, &_eps); }
void SeedSelector::CalculatePositionWeightMatrix(const std::shared_ptr<BarcodePool>& barcode_pool) { if (barcode_pool->size() > 0) { for (size_t i = 0; i < barcode_pool->size(); ++i) { if (barcode_pool->barcode(i).length() != _barcode_length) continue; for (size_t pos = 0; pos < _barcode_length; ++ pos) { _position_weight_matrix[pos][_dict->asc2dna(barcode_pool->barcode(i)[pos])] += 1; } } } // Go through each barcode and update the position weight matrix. }
bool utils::compare_sorted_vectors(std::shared_ptr<std::vector<int>>& v1, std::shared_ptr<std::vector<int>>& v2) { if (v1->size() != v2->size()) { return false; } for (size_t i = 0; i < v1->size(); i++) { if ((*v1)[i] != (*v2)[i]) { return false; } } return true; }
void OnMouseImg(std::shared_ptr<Utilities::Image> img) { if (!LastMouse) { _ServerNetworkDriver.SendMouse(nullptr, *img); } else { if(LastMouse->size() != img->size()) { _ServerNetworkDriver.SendMouse(nullptr, *img); } else if (memcmp(img->data(), LastMouse->data(), LastMouse->size()) != 0) { _ServerNetworkDriver.SendMouse(nullptr, *img); } } LastMouse = img; }
void CheckAndReloadFacade() { if (CURRENT_LAYOUT != data_timestamp_ptr->layout || CURRENT_DATA != data_timestamp_ptr->data || CURRENT_TIMESTAMP != data_timestamp_ptr->timestamp) { // release the previous shared memory segments SharedMemory::Remove(CURRENT_LAYOUT); SharedMemory::Remove(CURRENT_DATA); CURRENT_LAYOUT = data_timestamp_ptr->layout; CURRENT_DATA = data_timestamp_ptr->data; CURRENT_TIMESTAMP = data_timestamp_ptr->timestamp; m_layout_memory.reset(SharedMemoryFactory::Get(CURRENT_LAYOUT)); data_layout = (SharedDataLayout *)(m_layout_memory->Ptr()); m_large_memory.reset(SharedMemoryFactory::Get(CURRENT_DATA)); shared_memory = (char *)(m_large_memory->Ptr()); const char *file_index_ptr = data_layout->GetBlockPtr<char>(shared_memory, SharedDataLayout::FILE_INDEX_PATH); file_index_path = boost::filesystem::path(file_index_ptr); if (!boost::filesystem::exists(file_index_path)) { SimpleLogger().Write(logDEBUG) << "Leaf file name " << file_index_path.string(); throw osrm::exception("Could not load leaf index file." "Is any data loaded into shared memory?"); } LoadGraph(); LoadChecksum(); LoadNodeAndEdgeInformation(); LoadGeometries(); LoadTimestamp(); LoadViaNodeList(); LoadNames(); data_layout->PrintInformation(); SimpleLogger().Write() << "number of geometries: " << m_coordinate_list->size(); for (unsigned i = 0; i < m_coordinate_list->size(); ++i) { if (!GetCoordinateOfNode(i).is_valid()) { SimpleLogger().Write() << "coordinate " << i << " not valid"; } } } }
color pathtracer::cast_ray(ray r, int step, bool internal) { intersection is = find_nearest(r); if (!is.object) // No intersection return *background_color; color out = color(); for (std::shared_ptr<light> l : *lights) { color lcol = color(); if (is.object.get() == dynamic_cast<const shape *>(l.get())) out += *is.object->shade(color(1, 1, 1), *is.norm, *is.norm, -r.d, *is.local_pos, internal); else { const std::shared_ptr<std::vector<intersection>> dirs = l->get_directions(*is.pos, cam->shadow_rays); for (intersection d : *dirs) { direction light_dir = (*is.pos - *d.pos) * 0.999; if (!cast_shadow(*is.pos, -light_dir)) { //light_dir = normalise(light_dir); lcol += *is.object->shade(*l->emit(light_dir, d), -normalise(light_dir), *is.norm, -r.d, *is.local_pos, internal); } } if (dirs->size() > 0) out += lcol * (1.0f / dirs->size()); } } if (step < cam->max_bounces - 1) { std::shared_ptr<ray> sctr_ray = is.object->scatter(-r.d, *is.norm, *is.pos); if (sctr_ray) { //color sctr_col = cast_ray(*sctr_ray, step + 1, internal); color sctr_col = *is.object->shade(cast_ray(*sctr_ray, step + 1, internal), sctr_ray->d, *is.norm, -r.d, *is.local_pos, internal) * static_cast<float>(M_PI); out += sctr_col; } std::shared_ptr<ray> refl_ray = internal ? nullptr : is.object->reflect(-r.d, *is.norm, *is.pos); if (refl_ray) { color refl_col = cast_ray(*refl_ray, step + 1, internal); refl_col = refl_col * is.object->get_reflectance(); out += refl_col; } std::shared_ptr<ray> refr_ray = is.object->refract(-r.d, internal ? -*is.norm : *is.norm, *is.pos, internal); if (refr_ray) { color refr_col = color(); refr_col += cast_ray(*refr_ray, step + 1, dot(refr_ray->d, internal ? -*is.norm : *is.norm) < 0 == !internal); refr_col = refr_col * (internal ? std::exp(-(1 - is.object->get_transmittance()) * length(*is.pos - r.o)) : is.object->get_transmittance()); out += refr_col; } } return out; }
HistoryInteraction::HistoryInteraction( const std::shared_ptr<const DotVector> &dots, const std::shared_ptr<const History::HistoryArray> &history, const std::shared_ptr<GreenFunction::Dyadic> &dyadic, const int interp_order) : Interaction(dots), history(history), dyadic(dyadic), interp_order(interp_order), num_interactions(dots->size() * (dots->size() - 1) / 2), floor_delays(num_interactions), coefficients(boost::extents[num_interactions][interp_order + 1]) { build_coefficient_table(); }
size_t TemplatesCallbackUI::SelectTemplate( std::shared_ptr<std::vector<TemplateDescriptor> >templates) { promise<size_t> prom; auto res = prom.get_future(); // readdress call to main UI thread postToMainThread([&]() { // show dialog auto selectTemplateDlg = new QDialog(0, 0); Ui_TemplatesDialog selectTemplate; selectTemplate.setupUi(selectTemplateDlg); for (size_t pos = 0, last = templates->size(); pos < last; ++pos) { selectTemplate.comboBoxTemplates->insertItem(0, QString::fromStdString( (*templates)[pos].Name())); } selectTemplateDlg->exec(); prom.set_value(static_cast<size_t>(selectTemplate.comboBoxTemplates-> currentIndex())); }, _mainApp); // wait for result and return it return res.get(); }
void UdpSocket::handleSend(const boost::system::error_code &err, std::shared_ptr<Buffer> buffer, V4FirstIterator<udp> endpoints) { boost::lock_guard<boost::recursive_mutex> guard(commonMutex_); if(err && endpoints.hasNext()) { udp::endpoint endpoint; udp::socket *sock; do { endpoint = endpoints.next(); sock = getAppropriateSocket(endpoint); } while(!sock->is_open() && endpoints.hasNext()); if(sock->is_open()) { sock->async_send_to( boost::asio::const_buffers_1(buffer->getData(), buffer->size()), endpoint, boost::bind(&UdpSocket::handleSend, shared_from_this(), boost::asio::placeholders::error, buffer, endpoints)); return; } } asyncSendInProgress_ = false; if (!sendqueue_.isEmpty()) { asyncSend(); } }
/** * This constructor populates this CountDB from file, reading the set of counts from fname. */ CountDB( const std::string& fname, std::shared_ptr<std::vector<Kmer>>& kmers, uint32_t merSize ) : _kmers(kmers), _merSize( merSize ) { std::cerr << "checking that kmers are sorted . . . "; assert( std::is_sorted( kmers->begin(), kmers->end() ) ); std::cerr << "done\n"; std::ifstream counts(fname, std::ios::in | std::ios::binary ); uint32_t fileMerSize{0}; counts.read( reinterpret_cast<char*>(&fileMerSize), sizeof(fileMerSize) ); std::cerr << "checking that the mersizes are the same . . ."; assert( fileMerSize == merSize ); std::cerr << "done\n"; size_t numCounts{0}; counts.read( reinterpret_cast<char*>(&numCounts), sizeof(size_t) ); std::cerr << "checking that the counts are the same . . ."; assert( numCounts == kmers->size() ); std::cerr << "done\n"; _counts = std::vector< AtomicCount >( numCounts ); std::cerr << "reading counts from file . . ."; counts.read( reinterpret_cast<char*>(&_counts[0]), sizeof(_counts[0]) * numCounts ); std::cerr << "done\n"; counts.close(); }
void Client::ClientSession::DoWriteUDP(std::shared_ptr<std::string> data, const udp::endpoint& endpoint) { socket_udp_.async_send_to( boost::asio::buffer(data->data(), data->size()), endpoint, boost::bind(&Client::ClientSession::WriteUDP, this, boost::asio::placeholders::error)); }
void StrBlob::check(size_type i, const string &msg) const { if (i >= data->size()) { throw out_of_range(msg); } }
void ambient( const Renderer& /*renderer*/, const Grid& grid, std::shared_ptr<Value> color ) { REYES_ASSERT( color ); color->reset( TYPE_COLOR, STORAGE_VARYING, grid.size() ); color->zero(); const vector<shared_ptr<Light>>& lights = grid.lights(); for ( vector<shared_ptr<Light>>::const_iterator i = lights.begin(); i != lights.end(); ++i ) { Light* light = i->get(); REYES_ASSERT( light ); if ( light->type() == LIGHT_AMBIENT ) { const std::shared_ptr<Value>& light_color = light->color(); REYES_ASSERT( light_color ); vec3* color_values = color->vec3_values(); const vec3* light_color_values = light_color->vec3_values(); for ( unsigned int i = 0; i < color->size(); ++i ) { color_values[i] += light_color_values[min(i, light_color->size() - 1)]; } } } }
void step(DhtRunner& dht, std::atomic_uint& done, std::shared_ptr<NodeSet> all_nodes, dht::InfoHash cur_h, unsigned cur_depth) { std::cout << "step at " << cur_h << ", depth " << cur_depth << std::endl; done++; dht.get(cur_h, [all_nodes](const std::vector<std::shared_ptr<Value>>& /*values*/) { return true; }, [&,all_nodes,cur_h,cur_depth](bool, const std::vector<std::shared_ptr<Node>>& nodes) { all_nodes->insert(nodes.begin(), nodes.end()); NodeSet sbuck {nodes.begin(), nodes.end()}; if (not sbuck.empty()) { unsigned bdepth = sbuck.size()==1 ? 0u : InfoHash::commonBits((*sbuck.begin())->id, (*std::prev(sbuck.end()))->id); unsigned target_depth = std::min(159u, bdepth+3u); std::cout << cur_h << " : " << nodes.size() << " nodes; target is " << target_depth << " bits deep (cur " << cur_depth << ")" << std::endl; for (unsigned b = cur_depth ; b < target_depth; b++) { auto new_h = cur_h; new_h.setBit(b, 1); step(dht, done, all_nodes, new_h, b+1); } } done--; std::cout << done.load() << " operations left, " << all_nodes->size() << " nodes found." << std::endl; cv.notify_one(); }); }
void specularbrdf( const Renderer& /*renderer*/, const Grid& /*grid*/, std::shared_ptr<Value> result, std::shared_ptr<Value> l, std::shared_ptr<Value> n, std::shared_ptr<Value> v, std::shared_ptr<Value> roughness_value ) { REYES_ASSERT( result ); REYES_ASSERT( l ); REYES_ASSERT( n ); REYES_ASSERT( v ); REYES_ASSERT( roughness_value ); REYES_ASSERT( roughness_value->type() == TYPE_FLOAT ); REYES_ASSERT( roughness_value->storage() == STORAGE_CONSTANT || roughness_value->storage() == STORAGE_UNIFORM ); const vec3* lights = l->vec3_values(); const vec3* normals = n->vec3_values(); const vec3* views = v->vec3_values(); const float roughness = roughness_value->float_value(); const int size = l->size(); result->reset( TYPE_COLOR, STORAGE_VARYING, size ); vec3* colors = result->vec3_values(); for ( int i = 0; i < size; ++i ) { float alpha = powf( max(0.0f, dot(normals[i], normalize(lights[i] + views[i]))), 1.0f / roughness ); colors[i] = vec3( alpha, alpha, alpha ); } }
void MirBufferSGTexture::setBuffer(std::shared_ptr<mir::graphics::Buffer> buffer) { m_mirBuffer = buffer; mg::Size size = buffer->size(); m_height = size.height.as_int(); m_width = size.width.as_int(); }
void PeerComm::HandleMessagePayload(std::shared_ptr<std::vector<char>> payload_, const boost::system::error_code& error) { if (!error) { QueueReceiveMessage(); auto id = (*payload_)[0]; std::vector<char> payload; payload.reserve(payload_->size() - 1); payload.insert(payload.end(), payload_->begin() + 1, payload_->end()); std::unique_lock<std::mutex> _(m_Mutex); switch ((Peer::MessageType)id) { case Peer::MessageType::Choke: m_State = PeerCommState::Choked; m_Incoming.push_back(std::make_unique<Peer::Choke>()); break; case Peer::MessageType::Unchoke: m_State = PeerCommState::Working; m_Incoming.push_back(std::make_unique<Peer::Unchoke>()); break; case Peer::MessageType::Interested: m_Incoming.push_back(std::make_unique<Peer::Interested>()); break; case Peer::MessageType::NotInterested: m_Incoming.push_back(std::make_unique<Peer::NotInterested>()); break; case Peer::MessageType::Have: m_Incoming.push_back(std::make_unique<Peer::Have>(payload)); break; case Peer::MessageType::Bitfield: m_Incoming.push_back(std::make_unique<Peer::Bitfield>(payload)); break; case Peer::MessageType::Request: m_Incoming.push_back(std::make_unique<Peer::Request>(payload)); break; case Peer::MessageType::Piece: m_Incoming.push_back(std::make_unique<Peer::Piece>(payload)); break; case Peer::MessageType::Cancel: m_Incoming.push_back(std::make_unique<Peer::Cancel>(payload)); break; case Peer::MessageType::Port: m_Incoming.push_back(std::make_unique<Peer::Port>(payload)); break; default: std::cout << "invalid message id" << std::endl; m_State = PeerCommState::Error; return; } } else { std::unique_lock<std::mutex> _(m_Mutex); m_State = PeerCommState::Error; } }
SYMBOL_DECLSPEC char* __stdcall mGetLinkItem(int k, double *top_x, double *top_y, double *height, double *width, int *topage, int *type) { char* retstr = NULL; if (k < 0 || k > gLinkResults->size()) return false; sh_link muctx_link = gLinkResults->at(k); *top_x = muctx_link->upper_left.X; *top_y = muctx_link->upper_left.Y; *width = muctx_link->lower_right.X - muctx_link->upper_left.X; *height = muctx_link->lower_right.Y - muctx_link->upper_left.Y; *topage = muctx_link->page_num; *type = (int) muctx_link->type; if (muctx_link->type == LINK_URI) { const char* str = muctx_link->uri.get(); int len = strlen(str); if (len > 0) { /* This allocation ensures that Marshal will release in the managed code */ retstr = (char*)::CoTaskMemAlloc(len + 1); strcpy(retstr, str); } muctx_link->uri.release(); } return retstr; }
std::shared_ptr<STTx const> TransactionMaster::fetch (std::shared_ptr<SHAMapItem> const& item, SHAMapTreeNode::TNType type, bool checkDisk, std::uint32_t uCommitLedger) { std::shared_ptr<STTx const> txn; auto iTx = fetch (item->key(), false); if (!iTx) { if (type == SHAMapTreeNode::tnTRANSACTION_NM) { SerialIter sit (item->slice()); txn = std::make_shared<STTx const> (std::ref (sit)); } else if (type == SHAMapTreeNode::tnTRANSACTION_MD) { auto blob = SerialIter{item->data(), item->size()}.getVL(); txn = std::make_shared<STTx const>(SerialIter{blob.data(), blob.size()}); } } else { if (uCommitLedger) iTx->setStatus (COMMITTED, uCommitLedger); txn = iTx->getSTransaction (); } return txn; }
std::shared_ptr<RPCHeader> RPCDecoder::decodeHeader(std::shared_ptr<std::vector<char>> packet) { std::shared_ptr<RPCHeader> header(new RPCHeader()); try { if(!(packet->at(3) & 0x40) || packet->size() < 12) return header; uint32_t position = 4; uint32_t headerSize = 0; headerSize = _decoder.decodeInteger(packet, position); if(headerSize < 4) return header; uint32_t parameterCount = _decoder.decodeInteger(packet, position); for(uint32_t i = 0; i < parameterCount; i++) { std::string field = _decoder.decodeString(packet, position); HelperFunctions::toLower(field); std::string value = _decoder.decodeString(packet, position); if(field == "authorization") header->authorization = value; } } catch(const std::exception& ex) { Output::printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(Exception& ex) { Output::printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(...) { Output::printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__); } return header; }