本文整理汇总了C++中MemoryBuffer::bytes方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryBuffer::bytes方法的具体用法?C++ MemoryBuffer::bytes怎么用?C++ MemoryBuffer::bytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryBuffer
的用法示例。
在下文中一共展示了MemoryBuffer::bytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例2: aesDecryptWithRSAEncryptedKey
size32_t aesDecryptWithRSAEncryptedKey(MemoryBuffer &out, size32_t inSz, const void *inBytes, const CLoadedKey &privateKey)
{
MemoryBuffer in;
in.setBuffer(inSz, (void *)inBytes, false);
// read encrypted AES key
size32_t encryptedAESKeySz;
in.read(encryptedAESKeySz);
MemoryBuffer aesKey;
size32_t decryptedAesKeySz = privateKeyDecrypt(aesKey, encryptedAESKeySz, in.readDirect(encryptedAESKeySz), privateKey);
if (decryptedAesKeySz != aesMaxKeySize)
throw makeStringException(0, "aesDecryptWithRSAEncryptedKey - invalid input");
unsigned iVPos = in.getPos(); // read directly further down
in.skip(aesBlockSize);
size32_t aesEncryptedSz;
in.read(aesEncryptedSz);
return aesDecrypt(out, aesEncryptedSz, in.readDirect(aesEncryptedSz), aesMaxKeySize, (const char *)aesKey.bytes(), (const char *)in.bytes()+iVPos);
}