本文整理汇总了C++中PacketReader::parseBinaryFile方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketReader::parseBinaryFile方法的具体用法?C++ PacketReader::parseBinaryFile怎么用?C++ PacketReader::parseBinaryFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PacketReader
的用法示例。
在下文中一共展示了PacketReader::parseBinaryFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_PacketReader_parseBinaryFile_append
void test_PacketReader_parseBinaryFile_append()
{
/*
* Add our 2 packets
*/
pl->LogPacket(*mp1);
pl->LogPacket(*mp2);
pl->flush(0);
/*
* First parse, should have 2
*/
unsigned int i = p->parseBinaryFile(pl->getFile());
CPPUNIT_ASSERT( i == 2 );
/*
* Trigger append mode
*/
p->setAppend(true);
/*
* Second parse. Since no reset, should have 4
*/
i = p->parseBinaryFile(pl->getFile());
CPPUNIT_ASSERT( i = 4 );
/*
* And back again
*/
p->setAppend(false);
i = p->parseBinaryFile(pl->getFile());
CPPUNIT_ASSERT( i == 2 );
}
示例2: test_PacketReader_parseBinaryFile_empty
void test_PacketReader_parseBinaryFile_empty()
{
unsigned int i = p->parseBinaryFile("/tmp/file_does_not_exist");
/*
* Any sort of file operation that would fail, should produce
* a 'zero packets parsed' return.
*/
CPPUNIT_ASSERT( i == 0 );
}
示例3: main
//.........这里部分代码省略.........
boost::program_options::notify(vm);
/**
* Special case for help
*/
if ( vm.count("help") )
{
std::cout << desc << std::endl;
return 0;
}
std::cout << "Server : " << vm["server"].as<std::string>() << std::endl;
std::cout << "Port : " << vm["port"].as<int>() << std::endl;
std::cout << "---------------" << std::endl;
for (boost::program_options::variables_map::iterator it=vm.begin(); it!=vm.end(); ++it )
{
if ( it->second.value().type() == typeid(int) )
{
std::cout << it->first.c_str() << "=" << it->second.as<int>() << std::endl;
}
else if (it->second.value().type() == typeid(std::string) )
{
std::cout << it->first.c_str() << "=" << it->second.as<std::string>().c_str() << std::endl;
}
else if (it->second.value().type() == typeid(attribute_list) )
{
std::cout << it->first.c_str() << "=Attribute List" << std::endl;
}
}
std::cout << "-------------------------" << std::endl;
/**
* because boost query is too stupid to take port as an int
*/
std::stringstream port_str;
port_str << vm["port"].as<int>();
/**
* Wrangle the file etc options
*/
std::string file = "";
bool playOnly = false;
if( vm.count("playonly") )
{
std::string s = vm["playonly"].as<std::string>();
if ( boost::iequals(s,"true") )
{
playOnly = true;
}
}
if( vm.count("file") )
{
file = vm["file"].as<std::string>();
}
if ( file.empty() )
{
std::cout << "--file option not specified, but is required" << std::endl;
return 13;
}
/**
* Initialize reader
*/
p = new PacketReader();
int pkts = p->parseBinaryFile(file);
if( playOnly )
{
while(p->hasPacket())
{
MetaServerPacket msp = p->pop();
unsigned int i = msp.getPacketType();
std::string s = msp.getOutBound() ? ">>>>" : "<<<<";
std::cout << "Packet [";
std::cout << std::setfill('0') << std::setw(10) << msp.getSequence();
std::cout << "] " << s << " : " << NMT_PRETTY[i] << std::endl;
}
}
else
{
std::cout << "TODO: play packets to listed metaserver" << std::endl;
}
std::cout << "Packet File : " << file << std::endl;
std::cout << "Packet Count: " << pkts << std::endl;
}
catch (std::exception& e)
{
std::cerr << "Exception: " << e.what() << std::endl;
}
std::cout << "All Done!" << std::endl;
return 0;
}
示例4: test_PacketReader_parseBinaryFile
void test_PacketReader_parseBinaryFile()
{
MetaServerPacket* mp3 = new MetaServerPacket();
std::string attr_name = "foobar";
std::string attr_val = "waka waka";
mp3->setPacketType(NMT_SERVERATTR);
mp3->setSequence(3);
mp3->setTimeOffset(3);
mp3->addPacketData(attr_name.length());
mp3->addPacketData(attr_val.length());
mp3->addPacketData(attr_name);
mp3->addPacketData(attr_val);
MetaServerPacket* mp4 = new MetaServerPacket();
mp4->setPacketType(NMT_SERVERSHAKE);
mp4->addPacketData(666);
mp4->setSequence(4);
mp4->setTimeOffset(4);
pl->LogPacket(*mp1);
pl->LogPacket(*mp2);
pl->LogPacket(*mp3);
// pl->LogPacket(*mp4);
pl->flush(0);
unsigned int i = p->parseBinaryFile(pl->getFile());
CPPUNIT_ASSERT( i == 3 );
MetaServerPacket mr1 = p->pop();
MetaServerPacket mr2 = p->pop();
MetaServerPacket mr3 = p->pop();
// MetaServerPacket mr4 = p->pop();
/*
* Now we make sure that we've got a good round trip
*/
std::cout << "mr1.getPacketType(): " << mr1.getPacketType() << " / " << NMT_SERVERKEEPALIVE << std::endl;
CPPUNIT_ASSERT( mr1.getPacketType() == NMT_SERVERKEEPALIVE );
CPPUNIT_ASSERT( mr1.getSequence() == 1 );
CPPUNIT_ASSERT( mr1.getTimeOffset() == 1 );
CPPUNIT_ASSERT( mr1.getSize() == 4 );
std::cout << "mr2.getPacketType(): " << mr2.getPacketType() << " / " << NMT_SERVERSHAKE << std::endl;
CPPUNIT_ASSERT( mr2.getPacketType() == NMT_SERVERSHAKE );
CPPUNIT_ASSERT( mr2.getSequence() == 2 );
CPPUNIT_ASSERT( mr2.getTimeOffset() == 2 );
CPPUNIT_ASSERT( mr2.getSize() == 8 );
/*
* I have no idea why this doesn't work !?
*/
// unsigned int mr2data = mr2.getIntData(4);
// std::cout << "mr2.getIntData(4): " << mr2data << std::endl;
// CPPUNIT_ASSERT( mr2data == 22 );
//unsigned int mr4data = mr4.getIntData(4);
//std::cout << "mr4.getIntData(4): " << mr4data << std::endl;
//CPPUNIT_ASSERT( mr2data == 22 );
std::cout << "mr3.getPacketType(): " << mr3.getPacketType() << " / " << NMT_SERVERATTR << std::endl;
std::cout << "mr3.getSize(): " << mr3.getSize() << std::endl;
unsigned int n = mr3.getIntData(4);
unsigned int v = mr3.getIntData(8);
std::string msg = mr3.getPacketMessage(12);
std::cout << "mr3:n:" << n << std::endl;
std::cout << "mr3:v:" << v << std::endl;
std::cout << "mr3:msg:" << msg << std::endl;
CPPUNIT_ASSERT( mr3.getPacketType() == NMT_SERVERATTR );
CPPUNIT_ASSERT( mr3.getSequence() == 3 );
CPPUNIT_ASSERT( mr3.getTimeOffset() == 3 );
CPPUNIT_ASSERT( msg.substr(0,n) == "foobar" );
CPPUNIT_ASSERT( msg.substr(n) == "waka waka" );
// unsigned int name_length = in.getIntData(4);
// unsigned int value_length = in.getIntData(8);
// std::string msg = in.getPacketMessage(12);
// std::string name = msg.substr(0,name_length);
// std::string value = msg.substr(name_length);
// std::string ip = in.getAddressStr();
// m_Logger.debug("processSERVERATTR(%s,%s)", name.c_str(), value.c_str() );
// msdo.addServerAttribute(ip,name,value);
}