本文整理汇总了C++中Stat::Add方法的典型用法代码示例。如果您正苦于以下问题:C++ Stat::Add方法的具体用法?C++ Stat::Add怎么用?C++ Stat::Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stat
的用法示例。
在下文中一共展示了Stat::Add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CompressProtoBuff
//.........这里部分代码省略.........
if( hint != *i )
{
sn_CheckMessage( source, *i, size, bestDifference, best, lastMessageID );
}
++count;
}
if ( best )
{
// found a good previous message. yay!
nProtoBuf const & cached = best->GetProtoBuf();
// calculate diff message
nProtoBufDescriptorBase::
DiffMessages( cached, source, target );
#ifdef DEBUG_STRINGS_X
con << "Size = " << size << ", diff = " << bestDifference << "\n";
con << lastMessageID << ", " << best->MessageIDBig() << "\n";
con << "Base : " << cached.ShortDebugString() << "\n";
con << "Source: " << source.ShortDebugString() << "\n";
con << "Diff : " << target.ShortDebugString() << "\n";
#ifdef DEBUG_X
// test zlib
{
#define SIZE 10000
Bytef basebuf[SIZE], diffbuf[SIZE], fullbuf[SIZE];
Bytef buf[SIZE];
cached.SerializeToArray(&basebuf,SIZE);
target.SerializeToArray(&diffbuf,SIZE);
source.SerializeToArray(&fullbuf,SIZE);
z_stream stream;
memset( &stream, 0, sizeof( stream ) );
stream.next_in = basebuf;
stream.avail_in = cached.GetCachedSize();
stream.next_out = buf;
stream.avail_out = SIZE;
stream.total_in = 0;
stream.total_out = 0;
stream.msg = NULL;
stream.state = NULL;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
deflateInit( &stream, 9 );
// flush 1
deflate( &stream, Z_SYNC_FLUSH );
tASSERT( stream.avail_in == 0 );
int base = stream.total_out;
// update
stream.next_in = fullbuf;
// stream.avail_in = source.GetCachedSize();
stream.avail_in = 1;
// flush 2
deflate( &stream, Z_SYNC_FLUSH );
tASSERT( stream.avail_in == 0 );
deflateEnd( &stream );
tASSERT( stream.avail_in == 0 );
int second = stream.total_out;
int reduced = second - base;
static Stat stat;
stat.Add( target.GetCachedSize(), target.GetCachedSize() - reduced );
std::cout.flush();
con << "zlib: "
<< cached.GetCachedSize() << " to "
<< target.GetCachedSize() << " to "
<< reduced << "\n";
std::cout.flush();
}
#endif
#endif
// and return the message ID
return static_cast< unsigned short >( best->MessageID() );
}
else
{
// no message found, return full protobuf
target.CopyFrom( source );
return 0;
}
}