本文整理汇总了C++中DataBuffer::drainData方法的典型用法代码示例。如果您正苦于以下问题:C++ DataBuffer::drainData方法的具体用法?C++ DataBuffer::drainData怎么用?C++ DataBuffer::drainData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataBuffer
的用法示例。
在下文中一共展示了DataBuffer::drainData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testDrainData
void DataBufferTF::testDrainData()
{
DataBuffer buffer;
char str[] = "just for test";
buffer.writeBytes(str, sizeof(str)-1);
int dataLen = buffer.getDataLen();
buffer.drainData(0);
CPPUNIT_ASSERT_EQUAL(dataLen, buffer.getDataLen());
buffer.drainData(sizeof(str)*2);
CPPUNIT_ASSERT_EQUAL(0, buffer.getDataLen());
}
示例2: testEncode
void DEFAULTPACKETSTREAMERTF::testEncode() {
MyPacketFactory *factory = new MyPacketFactory();
DefaultPacketStreamer *streamer
= new DefaultPacketStreamer(factory);
MyPacket packet(16);
DataBuffer buffer;
PacketHeader *header = new PacketHeader;
packet.setPacketHeader(header);
delete header;
header = packet.getPacketHeader();
header->_chid = 1111;
header->_pcode = 2222;
CPPUNIT_ASSERT(streamer->encode(&packet, &buffer));
CPPUNIT_ASSERT_EQUAL(32, (int)buffer.getDataLen());
buffer.drainData(4);
CPPUNIT_ASSERT_EQUAL(1111, (int)buffer.readInt32());
CPPUNIT_ASSERT_EQUAL(2222, (int)buffer.readInt32());
CPPUNIT_ASSERT_EQUAL(16, (int)buffer.readInt32());
MyPacket packet1(100, false);
CPPUNIT_ASSERT(!streamer->encode(&packet1, &buffer));
CPPUNIT_ASSERT_EQUAL(16, (int)buffer.getDataLen());
delete streamer;
delete factory;
}
示例3: testGetPacketInfo
void DEFAULTPACKETSTREAMERTF::testGetPacketInfo() {
DataBuffer buffer;
PacketHeader header;
DefaultPacketStreamer streamer(NULL);
bool broken;
buffer.writeInt32(ANET_PACKET_FLAG);
buffer.writeInt32(1111);
buffer.writeInt32(2222);
buffer.writeInt32(-1);
buffer.writeBytes("data for test", 16);
CPPUNIT_ASSERT(!streamer.getPacketInfo(&buffer, &header, &broken));
CPPUNIT_ASSERT_EQUAL(1111, (int)header._chid);
CPPUNIT_ASSERT_EQUAL(2222, (int)header._pcode);
CPPUNIT_ASSERT_EQUAL(-1, (int)header._dataLen);
CPPUNIT_ASSERT(broken);
buffer.drainData(buffer.getDataLen());
streamer._existPacketHeader = false;
CPPUNIT_ASSERT(!streamer.getPacketInfo(&buffer, &header, &broken));
}