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


C++ MessageBuffer::GetWritePointer方法代码示例

本文整理汇总了C++中MessageBuffer::GetWritePointer方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageBuffer::GetWritePointer方法的具体用法?C++ MessageBuffer::GetWritePointer怎么用?C++ MessageBuffer::GetWritePointer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MessageBuffer的用法示例。


在下文中一共展示了MessageBuffer::GetWritePointer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WritePacketToBuffer

void WorldSocket::WritePacketToBuffer(WorldPacket const& packet, MessageBuffer& buffer)
{
    ServerPktHeader header;
    uint32 sizeOfHeader = SizeOfServerHeader[_authCrypt.IsInitialized()];
    uint32 opcode = packet.GetOpcode();
    uint32 packetSize = packet.size();

    // Reserve space for buffer
    uint8* headerPos = buffer.GetWritePointer();
    buffer.WriteCompleted(sizeOfHeader);

    if (packetSize > 0x400)
    {
        CompressedWorldPacket cmp;
        cmp.UncompressedSize = packetSize + 4;
        cmp.UncompressedAdler = adler32(adler32(0x9827D8F1, (Bytef*)&opcode, 4), packet.contents(), packetSize);

        // Reserve space for compression info - uncompressed size and checksums
        uint8* compressionInfo = buffer.GetWritePointer();
        buffer.WriteCompleted(sizeof(CompressedWorldPacket));

        uint32 compressedSize = CompressPacket(buffer.GetWritePointer(), packet);

        cmp.CompressedAdler = adler32(0x9827D8F1, buffer.GetWritePointer(), compressedSize);

        memcpy(compressionInfo, &cmp, sizeof(CompressedWorldPacket));
        buffer.WriteCompleted(compressedSize);
        packetSize = compressedSize + sizeof(CompressedWorldPacket);

        opcode = SMSG_COMPRESSED_PACKET;
    }
    else if (!packet.empty())
        buffer.Write(packet.contents(), packet.size());

    if (_authCrypt.IsInitialized())
    {
        header.Normal.Size = packetSize;
        header.Normal.Command = opcode;
        _authCrypt.EncryptSend((uint8*)&header, sizeOfHeader);
    }
    else
    {
        header.Setup.Size = packetSize + 4;
        header.Setup.Command = opcode;
    }

    memcpy(headerPos, &header, sizeOfHeader);
}
开发者ID:DrYaling,项目名称:eluna-wod,代码行数:48,代码来源:WorldSocket.cpp

示例2: EndianConvertReverse

void Battlenet::Session::SendResponse(uint32 token, pb::Message const* response)
{
    Header header;
    header.set_token(token);
    header.set_service_id(0xFE);
    header.set_size(response->ByteSize());

    uint16 headerSize = header.ByteSize();
    EndianConvertReverse(headerSize);

    MessageBuffer packet;
    packet.Write(&headerSize, sizeof(headerSize));
    uint8* ptr = packet.GetWritePointer();
    packet.WriteCompleted(header.ByteSize());
    header.SerializeToArray(ptr, header.ByteSize());
    ptr = packet.GetWritePointer();
    packet.WriteCompleted(response->ByteSize());
    response->SerializeToArray(ptr, response->ByteSize());

    AsyncWrite(&packet);
}
开发者ID:Diyvol,项目名称:TrinityCore,代码行数:21,代码来源:Session.cpp

示例3: WritePacketToBuffer

void Socket::WritePacketToBuffer(Packet const& packet, MessageBuffer& buffer)
{
    ServerHeader header;
    uint32 sizeOfHeader = SizeOfServerHeader;
    uint32 opcode = packet.GetOpcode();
    uint32 packetSize = packet.size();

    // Reserve space for buffer
    uint8* headerPos = buffer.GetWritePointer();
    buffer.WriteCompleted(sizeOfHeader);

    if (!packet.empty())
        buffer.Write(packet.contents(), packet.size());

    header.Size = packetSize;
    header.Command = opcode;
    memcpy(headerPos, &header, sizeOfHeader);
}
开发者ID:ShipsInc,项目名称:ServerCPP,代码行数:18,代码来源:Socket.cpp


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