本文整理汇总了C++中MemoryBuffer::write方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryBuffer::write方法的具体用法?C++ MemoryBuffer::write怎么用?C++ MemoryBuffer::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryBuffer
的用法示例。
在下文中一共展示了MemoryBuffer::write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assemble
void assemble(const char *binfname, void *fin)
{
MemoryBuffer buffer;
assemble_to_buffer(&buffer, fin);
// Buffer compression logic.
sp_file_hdr_t *header = (sp_file_hdr_t *)buffer.bytes();
size_t region_size = header->imagesize - header->dataoffs;
size_t zbuf_max = compressBound(region_size);
Bytef *zbuf = (Bytef *)malloc(zbuf_max);
uLong new_disksize = zbuf_max;
int err = compress2(
zbuf,
&new_disksize,
(Bytef *)(buffer.bytes() + header->dataoffs),
region_size,
Z_BEST_COMPRESSION
);
if (err != Z_OK) {
free(zbuf);
pc_printf("Unable to compress, error %d\n", err);
pc_printf("Falling back to no compression.\n");
splat_to_binary(binfname, buffer.bytes(), buffer.size());
return;
}
header->disksize = new_disksize + header->dataoffs;
header->compression = SmxConsts::FILE_COMPRESSION_GZ;
buffer.rewind(header->dataoffs);
buffer.write(zbuf, new_disksize);
free(zbuf);
splat_to_binary(binfname, buffer.bytes(), buffer.size());
}