本文整理汇总了C++中Msg::ByteSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Msg::ByteSize方法的具体用法?C++ Msg::ByteSize怎么用?C++ Msg::ByteSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Msg
的用法示例。
在下文中一共展示了Msg::ByteSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
BufferPtr
serializeMsg(const Msg& msg)
{
int size = msg.ByteSize();
BufferPtr bytes = std::make_shared<Buffer>(size);
msg.SerializeToArray(bytes->buf(), size);
return bytes;
}
示例2: sendPackage
void SocketClient::sendPackage(void)
{
Msg msg;
Packer::packLua2Protobuf(LuaEngine::getInstance()->getLuaStack()->getLuaState(),&msg);
static union
{
struct
{
int packageLen;
int flags;
int seqId;
int crc32;
char data[1];
};
char ssssssssss[SocketClientSendBufferLength];
}sPackage;
int protobufLength = msg.ByteSize();
CCAssert(protobufLength <= sizeof(sPackage),"发送缓冲区将溢出!");
msg.SerializeToArray(sPackage.ssssssssss,SocketClientSendBufferLength);
int flags = FLAG_COMPRESSED; // 开启加密
int encryptLength;
void* encryptData;
if(isCompressed(flags))
{
encryptData = Encrypt::encryptForNet(&encryptLength,sPackage.ssssssssss,protobufLength,(rand()<<16) + (rand()&0xFFFF));
}
else
{
encryptData = Encrypt::doXorForNet(&encryptLength,sPackage.ssssssssss,protobufLength,(rand()<<16) + (rand()&0xFFFF));
}
CCAssert(encryptLength <= SocketClientSendBufferLength-16,"发送缓冲区将溢出!");
memcpy(sPackage.data,encryptData,encryptLength); //todo可优化,不拷贝。
delete[]((char*)encryptData);
sPackage.packageLen = htonl(encryptLength+12);
sPackage.flags = htonl(flags);
sPackage.seqId = htonl(_sendSequenceNumber);
_sendSequenceNumber+=SEQUENCE_NUMBER_INCREMENT;
sPackage.crc32 = htonl(crc32(sPackage.data,encryptLength,0));
int nLen = send(&sPackage,encryptLength+16);
CCAssert(nLen == encryptLength+16,"");
CCLOG(__FUNCTION__);
}