本文整理汇总了C++中CBuffer::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ CBuffer::Clear方法的具体用法?C++ CBuffer::Clear怎么用?C++ CBuffer::Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBuffer
的用法示例。
在下文中一共展示了CBuffer::Clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RecvData
int CAppCtrl::RecvData(unsigned int uiDPKey, CBuffer& stBuff)
{
//找到key对应的管道
PCShmQ pstShm = GetShm(uiDPKey);
if(pstShm == NULL)
{
SL_ERROR("shm %u fand fails!", uiDPKey);
return -1;
}
else if(!pstShm->HasCode())
{
//管道里没有数据
return 0;
}
m_Stat.Put(app_stat_recvpkg);
stBuff.Clear();
int iCodeLen = 0;
//从管道里取出一个code
int iRet = pstShm->GetOneCode(stBuff.GetFreeBuf(), stBuff.GetFreeLen(), iCodeLen);
if(iRet || iCodeLen < (int)sizeof(CNetHead))
{
SL_ERROR("get one code but data fails (ret: %d, clen:%d)",iRet, iCodeLen);
return -2;
}
stBuff.Append(iCodeLen);
return iCodeLen;
}
示例2: EmbedChunkName
// If compiled script, make sure correct chunkname is embedded
void CLuaShared::EmbedChunkName(SString strChunkName, const char** pcpOutBuffer, uint* puiOutSize)
{
const char*& cpBuffer = *pcpOutBuffer;
uint& uiSize = *puiOutSize;
if (!IsLuaCompiledScript(cpBuffer, uiSize))
return;
if (uiSize < 12)
return;
// Get size of name in original
uint uiStringSizeOrig = *(uint*)(cpBuffer + 12);
if (uiSize < 12 + 4 + uiStringSizeOrig)
return;
static CBuffer store;
store.Clear();
CBufferWriteStream stream(store);
// Ensure name starts with @ and ends with NULL
if (!strChunkName.BeginsWith("@"))
strChunkName = "@" + strChunkName;
if (strChunkName[strChunkName.length() - 1] != '\0')
strChunkName.push_back('\0');
// Header
stream.WriteBytes(cpBuffer, 12);
// New name size
stream.Write(strChunkName.length());
// New name bytes incl zero termination
stream.WriteBytes(strChunkName.c_str(), strChunkName.length());
// And the rest
stream.WriteBytes(cpBuffer + 12 + 4 + uiStringSizeOrig, uiSize - 12 - 4 - uiStringSizeOrig);
cpBuffer = store.GetData();
uiSize = store.GetSize();
}