本文整理汇总了C++中Header::ParseFromArray方法的典型用法代码示例。如果您正苦于以下问题:C++ Header::ParseFromArray方法的具体用法?C++ Header::ParseFromArray怎么用?C++ Header::ParseFromArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Header
的用法示例。
在下文中一共展示了Header::ParseFromArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UnPackBaseMsg
int Base :: UnPackBaseMsg(const std::string & sBuffer, Header & oHeader, size_t & iBodyStartPos, size_t & iBodyLen)
{
uint16_t iHeaderLen = 0;
memcpy(&iHeaderLen, sBuffer.data() + GROUPIDXLEN, HEADLEN_LEN);
size_t iHeaderStartPos = GROUPIDXLEN + HEADLEN_LEN;
iBodyStartPos = iHeaderStartPos + iHeaderLen;
if (iBodyStartPos > sBuffer.size())
{
BP->GetAlgorithmBaseBP()->UnPackHeaderLenTooLong();
NLErr("Header headerlen too loog %d", iHeaderLen);
return -1;
}
bool bSucc = oHeader.ParseFromArray(sBuffer.data() + iHeaderStartPos, iHeaderLen);
if (!bSucc)
{
NLErr("Header.ParseFromArray fail, skip this msg");
return -1;
}
NLDebug("buffer_size %zu header len %d cmdid %d gid %lu rid %lu version %d body_startpos %zu",
sBuffer.size(), iHeaderLen, oHeader.cmdid(), oHeader.gid(), oHeader.rid(), oHeader.version(), iBodyStartPos);
if (oHeader.version() >= 1)
{
if (iBodyStartPos + CHECKSUM_LEN > sBuffer.size())
{
NLErr("no checksum, body start pos %zu buffersize %zu", iBodyStartPos, sBuffer.size());
return -1;
}
iBodyLen = sBuffer.size() - CHECKSUM_LEN - iBodyStartPos;
uint32_t iBufferChecksum = 0;
memcpy(&iBufferChecksum, sBuffer.data() + sBuffer.size() - CHECKSUM_LEN, CHECKSUM_LEN);
uint32_t iNewCalBufferChecksum = crc32(0, (const uint8_t *)sBuffer.data(), sBuffer.size() - CHECKSUM_LEN, NET_CRC32SKIP);
if (iNewCalBufferChecksum != iBufferChecksum)
{
BP->GetAlgorithmBaseBP()->UnPackChecksumNotSame();
NLErr("Data.bring.checksum %u not equal to Data.cal.checksum %u",
iBufferChecksum, iNewCalBufferChecksum);
return -1;
}
/*
NLDebug("Checksum compare ok, Data.bring.checksum %u, Data.cal.checksum %u",
iBufferChecksum, iNewCalBufferChecksum)
*/
}
else
{
iBodyLen = sBuffer.size() - iBodyStartPos;
}
return 0;
}
示例2:
bool Battlenet::Session::ReadHeaderHandler()
{
Header header;
if (!header.ParseFromArray(_headerBuffer.GetReadPointer(), _headerBuffer.GetActiveSize()))
return false;
_packetBuffer.Resize(header.size());
return true;
}
示例3: read_event
void client::read_event()
{
try {
char hdr_data[5];
read(hdr_data, 5);
Header hdr;
hdr.ParseFromArray(hdr_data, 5);
size_t sz = hdr.size();
char msg_data[sz];
read(msg_data, sz);
Command cmd;
cmd.ParseFromArray(msg_data, sz);
parse_command(cmd);
} catch(finch::net::socket::disconnected_exception& e) {
_serv->drop_client(this);
}
}
示例4: ASSERT
bool Battlenet::Session::ReadDataHandler()
{
Header header;
ASSERT(header.ParseFromArray(_headerBuffer.GetReadPointer(), _headerBuffer.GetActiveSize()));
if (header.service_id() != 0xFE)
{
sServiceDispatcher.Dispatch(this, header.service_hash(), header.token(), header.method_id(), std::move(_packetBuffer));
}
else
{
auto itr = _responseCallbacks.find(header.token());
if (itr != _responseCallbacks.end())
{
itr->second(std::move(_packetBuffer));
_responseCallbacks.erase(header.token());
}
else
_packetBuffer.Reset();
}
return true;
}