本文整理汇总了C++中StdBuf::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ StdBuf::Write方法的具体用法?C++ StdBuf::Write怎么用?C++ StdBuf::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StdBuf
的用法示例。
在下文中一共展示了StdBuf::Write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
StdBuf C4NetpuncherPacketCReq::PackInto() const {
StdBuf buf;
auto sin6 = static_cast<sockaddr_in6>(addr.AsIPv6());
auto port = addr.GetPort();
buf.New(sizeof(port) + sizeof(sin6.sin6_addr));
size_t offset = 0;
buf.Write(&port, sizeof(port), offset);
offset += sizeof(port);
buf.Write(&sin6.sin6_addr, sizeof(sin6.sin6_addr), offset);
static_assert(sizeof(sin6.sin6_addr) == 16, "expected sin6_addr to be 16 bytes");
return buf;
}
示例2: GetID
StdBuf C4NetpuncherPacketID<TYPE>::PackInto() const {
StdBuf buf;
auto id = GetID();
buf.New(sizeof(id));
buf.Write(&id, sizeof(id));
return buf;
}
示例3:
void C4Network2IRCClient::PackPacket(const C4NetIOPacket &rPacket, StdBuf &rOutBuf)
{
// Enlarge buffer
int iSize = rPacket.getSize(),
iPos = rOutBuf.getSize();
rOutBuf.Grow(iSize + 2);
// Write packet
rOutBuf.Write(rPacket, iPos);
// Terminate
uint8_t *pPos = getMBufPtr<uint8_t>(rOutBuf, iPos + iSize);
*pPos = '\r'; *(pPos + 1) = '\n';
}
示例4: StdBuf
StdBuf C4Playback::ReWriteBinary() {
const int OUTPUT_GROW = 16 * 1024;
StdBuf Output;
int iPos = 0;
bool fFinished = false;
uint32_t iFrame = 0;
for (chunks_t::const_iterator i = chunks.begin();
!fFinished && i != chunks.end(); i++) {
// Check frame difference
if (i->Frame - iFrame < 0 || i->Frame - iFrame > 0xff)
LogF(
"ERROR: Invalid frame difference between chunks (0-255 allowed)! "
"Data will be invalid!");
// Pack data
StdBuf Chunk;
try {
switch (i->Type) {
case RCT_Ctrl:
Chunk = DecompileToBuf<StdCompilerBinWrite>(*i->pCtrl);
break;
case RCT_CtrlPkt:
Chunk = DecompileToBuf<StdCompilerBinWrite>(*i->pPkt);
break;
case RCT_End:
fFinished = true;
break;
default: // debugrec
if (i->pDbg) Chunk = DecompileToBuf<StdCompilerBinWrite>(*i->pDbg);
break;
}
} catch (StdCompiler::Exception *pEx) {
LogF("Record: Binary unpack error: %s", pEx->Msg.getData());
delete pEx;
return StdBuf();
}
// Grow output
while (Output.getSize() - iPos <
sizeof(C4RecordChunkHead) + Chunk.getSize())
Output.Grow(OUTPUT_GROW);
// Write header
C4RecordChunkHead *pHead = getMBufPtr<C4RecordChunkHead>(Output, iPos);
pHead->Type = i->Type;
pHead->iFrm = i->Frame - iFrame;
iPos += sizeof(C4RecordChunkHead);
iFrame = i->Frame;
// Write chunk
Output.Write(Chunk, iPos);
iPos += Chunk.getSize();
}
Output.SetSize(iPos);
return Output;
}