本文整理汇总了C++中Message::ByteSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Message::ByteSize方法的具体用法?C++ Message::ByteSize怎么用?C++ Message::ByteSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message::ByteSize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: header
MumblePacket::MumblePacket(MumblePacketType type, const Message &message) {
int msgSize = message.ByteSize();
this->messageData = new char[msgSize];
message.SerializePartialToArray(this->messageData, msgSize);
this->packetHeader.packetType = static_cast<short>(type);
this->packetHeader.packetLength = message.ByteSize() + 6; //The 6 more bytes are for the header (2 + 4 bytes -> type + size)
this->rawData = new char[this->packetHeader.packetLength];
memcpy(this->rawData, static_cast<void *>(&this->packetHeader), 6); //We copy the header.
memcpy(this->rawData+6, this->messageData, msgSize); //We copy the message
}
示例2: sendMessage
void Communication::sendMessage(Socket& socket, const Message& message) {
int serialized_size = message.ByteSize();
char *serialized_pb = new char[serialized_size];
message.SerializeToArray(serialized_pb, serialized_size);
sendReplyMessage(socket, serialized_pb, serialized_size);
delete[] serialized_pb;
}
示例3: serialize_message
serialized_message serialize_message(Message const &message)
{
size_t msg_size = message.ByteSize();
size_t size = msg_size + MAX_VARINT_BYTES;
std::shared_ptr<uint8> buffer(new uint8[size]);
auto it = CodedOutputStream::WriteVarint32ToArray(msg_size, buffer.get());
bool written = message.SerializeToArray(it, msg_size);
assert(written);
return serialized_message(msg_size + (it - buffer.get()), buffer);
}
示例4: TryDequeueCommands
void CNetworkPlayer::TryDequeueCommands () {
while (m_unreliableQueue.size() > 0) {
if ((m_nextMessage.ByteSize() + m_unreliableQueue.front().ByteSize()) > SOCKET_MAX_MESSAGE_SIZE) {
return;
}
*m_nextMessage.add_commands() = m_unreliableQueue.front();
m_unreliableQueue.pop();
}
}
示例5: sendMessage
bool Caster::sendMessage(const Message& message) {
int msg_size = message.ByteSize();
QByteArray data;
data.resize(msg_size + 4);
qToBigEndian<uint32_t>(msg_size,
reinterpret_cast<unsigned char*>(data.data()));
if (!message.SerializeToArray(data.data() + 4, msg_size)) {
return false;
}
return socket_.write(data) == data.size();
}
示例6:
int MetaSerializer::Pack(void* obj,Buffer & buffer)
{
Message* msg = (Message*)obj;//m_pObjFactory->GetPrototype(meta);
//const Descriptor* meta = msg->GetDescriptor();
bool ret = msg->SerializeToArray(buffer.pBuffer, buffer.iCap);
if(!ret)
{
LOG_ERROR("meta name = %s pack error !",msg->GetDescriptor()->name().c_str());
buffer.iUsed = 0;
return -1;
}
buffer.iUsed = msg->ByteSize();
return 0;
}
示例7: TryDequeueReliableCommands
void CNetworkPlayer::TryDequeueReliableCommands () {
unsigned seq = (m_currentSeq == m_lastSentSeq) ? m_currentSeq + 1 : m_currentSeq;
ReliableCommand rc;
rc.set_sequence(seq);
while (m_reliableQueue.size() > 0) {
*rc.mutable_command() = m_reliableQueue.front();
if ((m_nextMessage.ByteSize() + rc.ByteSize()) > SOCKET_MAX_MESSAGE_SIZE) {
return;
}
*m_nextMessage.add_reliablecommands() = rc;
m_currentSeq = seq;
m_reliableQueue.pop();
}
}
示例8: send
bool Robot::send(int msgId, Message &msg)
{
if (!m_link->isopen()) {
// LOG_ERROR << "robot<" << m_robotId << "> [" << m_link->m_localAddr.toIpPort() << "] <-> gatesvr [" << m_link->m_peerAddr.toIpPort() << "] is not open";
return false;
}
if (!m_isEncrypt) {
m_link->send(msgId, msg);
return true;
}
uint32 headSize = sizeof(NetMsgHead);
int size = msg.ByteSize();
bool ok = msg.SerializeToArray(m_link->m_net->g_encryptBuf + headSize + EncryptHeadLen, size);
if (!ok) {
LOG_ERROR << "robot<" << m_robotId << "> [" << m_link->getLocalAddr().toIpPort() << "] <-> gatesvr [" << m_link->getPeerAddr().toIpPort()
<< "] send msg failed, SerializeToArray error, [len=" << size << "] failed, content = [" << msgtool::getMsgDebugString(msg) << "]";
return false;
}
// 添加加解密头尾
uint8* decryptBuf = (uint8*)(m_link->m_net->g_encryptBuf + headSize);
int decryptBufLen = size + EncryptHeadLen + EncryptTailLen;
encrypttool::encrypt(decryptBuf, decryptBufLen, m_encryptKey, sizeof(m_encryptKey));
NetMsgHead* pHeader = (NetMsgHead*)m_link->m_net->g_encryptBuf;
int packetLen = msgtool::buildNetHeader(pHeader, msgId, decryptBufLen);
if (packetLen <= 0) {
LOG_ERROR << "robot<" << m_robotId << "> [" << m_link->getLocalAddr().toIpPort() << "] <-> gatesvr [" << m_link->getPeerAddr().toIpPort()
<< "] pakcetLen = " << packetLen;
return false;
}
m_link->send(m_link->m_net->g_encryptBuf, packetLen);
return true;
}