当前位置: 首页>>代码示例>>C++>>正文


C++ DataBuffer::drainData方法代码示例

本文整理汇总了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());
}
开发者ID:AllanXiang,项目名称:Source,代码行数:11,代码来源:databuffertf.cpp

示例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;
}
开发者ID:AllanXiang,项目名称:Source,代码行数:26,代码来源:defaultpacketstreamertf.cpp

示例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));

    
}
开发者ID:AllanXiang,项目名称:Source,代码行数:24,代码来源:defaultpacketstreamertf.cpp


注:本文中的DataBuffer::drainData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。