void encode_messages(confluent::codec& codec, const std::vector<std::pair<sample::contact_info_key, sample::contact_info>>& src, int32_t key_id, int32_t value_id, std::vector<std::shared_ptr<csi::kafka::basic_message>>& dst) { dst.reserve(src.size()); for (std::vector<std::pair<sample::contact_info_key, sample::contact_info>>::const_iterator i = src.begin(); i != src.end(); ++i) { std::shared_ptr<csi::kafka::basic_message> msg(new csi::kafka::basic_message()); //encode key { auto os = codec.encode_nonblock(key_id, i->first); size_t sz = os->byteCount(); auto is = avro::memoryInputStream(*os); avro::StreamReader stream_reader(*is); msg->key.set_null(false); msg->key.resize(sz); stream_reader.readBytes(msg->key.data(), sz); } //encode value { auto os = codec.encode_nonblock(value_id, i->second); size_t sz = os->byteCount(); auto is = avro::memoryInputStream(*os); avro::StreamReader stream_reader(*is); msg->value.set_null(false); msg->value.resize(sz); stream_reader.readBytes(msg->value.data(), sz); } dst.push_back(msg); } }
Level * FileWorker::readLevelFromFile(const QString &fileName) { QFile level(fileName); if (level.open(QFile::ReadOnly | QFile::Text) == false) { level.close(); return 0; } QTextStream stream_reader(&level); QString all_file = stream_reader.readAll(); level.close(); QList<QString> string_list = all_file.split(QRegExp("[\r\n, ]+")); if (string_list.isEmpty()) return 0; if (string_list.last().isEmpty()) string_list.removeLast(); if (string_list.count() < 2) return 0; int w = string_list[0].toInt(); int h = string_list[1].toInt(); if (string_list.size()<(w * h + 7)) return 0; int xPort = string_list[w * h + 4].toInt(); int yPort = string_list[w * h + 5].toInt(); int c = 1; int i = 2; Field levelField(Size(w, h)); while (c <= h) { while (i < c * w + 2) { if(string_list[i].toInt() == 0) levelField.setCell(new Field_cell(Position((i-2)-(c-1)*w,c-1))); else if(string_list[i].toInt() == 1) levelField.setCell(new Port_cell(Position((i-2)-(c-1)*w,c-1))); else if(string_list[i].toInt() == 2) levelField.setCell(new Wall_cell(Position((i-2)-(c-1)*w,c-1))); i++; } c++; } Snake snake; snake.setDirection(convStringDir(string_list[w * h + 6]), levelField.getSize()); snake.setInitialSnakeLength(string_list[w * h + 2 ].toInt()); int Beetle_num = string_list[w * h + 3].toInt(); return new Level(levelField, snake, QList<Beetle_cell>(), Port_cell(Position(xPort, yPort)), Beetle_num); return 0; }
bool GLInjectInput::SwitchStream(SharedData* lock, const SSRVideoStream& stream) { try { // create the stream reader std::unique_ptr<SSRVideoStreamReader> stream_reader(new SSRVideoStreamReader(m_channel.toStdString(), stream)); // initialize the stream stream_reader->ChangeCaptureParameters(m_flags | ((lock->m_capturing)? GLINJECT_FLAG_CAPTURE_ENABLED : 0), m_target_fps); stream_reader->Clear(); // if everything is okay, use the new stream reader lock->m_stream_reader = std::move(stream_reader); } catch(...) { Logger::LogError("[GLInjectInput::SwitchStream] " + Logger::tr("Error: Could not read stream, this usually means that the stream was already gone.")); return false; } return true; }
//========================================================================== void readfile(std::string filename, std::string outfile) { int num_events(0); int num_badevents(0); int num_baduncompress(0); int num_badchksum(0); int num_goodevents(0); int num_duplevents(0); uint32 hltcount(0); std::vector<uint32> hltStats(0); std::vector<unsigned char> compress_buffer(7000000); std::map<uint32, uint32> seenEventMap; bool output(false); if(outfile != "/dev/null") { output = true; } StreamerOutputFile stream_output(outfile); try{ // ----------- init edm::StreamerInputFile stream_reader(filename); //if(output) StreamerOutputFile stream_output(outfile); std::cout << "Trying to Read The Init message from Streamer File: " << std::endl << filename << std::endl; InitMsgView const* init = stream_reader.startMessage(); std::cout << "\n\n-------------INIT Message---------------------" << std::endl; std::cout << "Dump the Init Message from Streamer:-" << std::endl; dumpInitView(init); if(output) { stream_output.write(*init); hltcount = init->get_hlt_bit_cnt(); //Initialize the HLT Stat vector with all ZEROs for(uint32 i = 0; i != hltcount; ++i) hltStats.push_back(0); } // ------- event std::cout << "\n\n-------------EVENT Messages-------------------" << std::endl; bool first_event(true); std::auto_ptr<EventMsgView> firstEvtView(0); std::vector<unsigned char> savebuf(0); EventMsgView const* eview(0); seenEventMap.clear(); while(stream_reader.next()) { eview = stream_reader.currentRecord(); ++num_events; bool good_event(true); if(seenEventMap.find(eview->event()) == seenEventMap.end()) { seenEventMap.insert(std::make_pair(eview->event(), 1)); } else { ++seenEventMap[eview->event()]; ++num_duplevents; std::cout << "??????? duplicate event Id for count " << num_events << " event number " << eview->event() << " seen " << seenEventMap[eview->event()] << " times" << std::endl; } if(first_event) { std::cout << "----------dumping first EVENT-----------" << std::endl; dumpEventView(eview); first_event = false; unsigned char* src = (unsigned char*)eview->startAddress(); unsigned int srcSize = eview->size(); savebuf.resize(srcSize); std::copy(src, src+srcSize, &(savebuf)[0]); firstEvtView.reset(new EventMsgView(&(savebuf)[0])); //firstEvtView, reset(new EventMsgView((void*)eview->startAddress())); if(!test_chksum(firstEvtView.get())) { std::cout << "checksum error for count " << num_events << " event number " << eview->event() << " from host name " << eview->hostName() << std::endl; ++num_badchksum; std::cout << "----------dumping bad checksum EVENT-----------" << std::endl; dumpEventView(eview); good_event = false; } if(!test_uncompress(firstEvtView.get(), compress_buffer)) { std::cout << "uncompress error for count " << num_events << " event number " << firstEvtView->event() << std::endl; ++num_baduncompress; std::cout << "----------dumping bad uncompress EVENT-----------" << std::endl; dumpEventView(firstEvtView.get()); good_event = false; } } else { if(compares_bad(firstEvtView.get(), eview)) { std::cout << "Bad event at count " << num_events << " dumping event " << std::endl << "----------dumping bad EVENT-----------" << std::endl; dumpEventView(eview); ++num_badevents; good_event = false; } if(!test_chksum(eview)) { std::cout << "checksum error for count " << num_events << " event number " << eview->event() << " from host name " << eview->hostName() << std::endl; ++num_badchksum; std::cout << "----------dumping bad checksum EVENT-----------" << std::endl; dumpEventView(eview); good_event = false; } if(!test_uncompress(eview, compress_buffer)) { std::cout << "uncompress error for count " << num_events << " event number " << eview->event() << std::endl; ++num_baduncompress; std::cout << "----------dumping bad uncompress EVENT-----------" << std::endl; dumpEventView(eview); good_event = false; } } if(output && good_event) { ++num_goodevents; stream_output.write(*eview); //get the HLT Packed bytes std::vector<uint8> packedHlt; uint32 hlt_sz = 0; if(hltcount != 0) hlt_sz = 1 + ((hltcount - 1)/4); packedHlt.resize(hlt_sz); firstEvtView->hltTriggerBits(&packedHlt[0]); updateHLTStats(packedHlt, hltcount, hltStats); } if((num_events % 50) == 0) { std::cout << "Read " << num_events << " events, and " << num_badevents << " events with bad headers, and " << num_badchksum << " events with bad check sum, and " << num_baduncompress << " events with bad uncompress" << std::endl; if(output) std::cout << "Wrote " << num_goodevents << " good events " << std::endl; } } std::cout << std::endl << "------------END--------------" << std::endl << "read " << num_events << " events" << std::endl << "and " << num_badevents << " events with bad headers" << std::endl << "and " << num_badchksum << " events with bad check sum" << std::endl << "and " << num_baduncompress << " events with bad uncompress" << std::endl << "and " << num_duplevents << " duplicated event Id" << std::endl; if(output) { uint32 dummyStatusCode = 1234; stream_output.writeEOF(dummyStatusCode, hltStats); std::cout << "Wrote " << num_goodevents << " good events " << std::endl; } }catch(cms::Exception& e){ std::cerr << "Exception caught: " << e.what() << std::endl << "After reading " << num_events << " events, and " << num_badevents << " events with bad headers" << std::endl << "and " << num_badchksum << " events with bad check sum" << std::endl << "and " << num_baduncompress << " events with bad uncompress" << std::endl << "and " << num_duplevents << " duplicated event Id" << std::endl; } }
bool ZeroCopyStreamToJson(BUTIL_RAPIDJSON_NAMESPACE::Document *dest, google::protobuf::io::ZeroCopyInputStream *stream) { ZeroCopyStreamReader stream_reader(stream); dest->ParseStream<0, BUTIL_RAPIDJSON_NAMESPACE::UTF8<> >(stream_reader); return !dest->HasParseError(); }