本文整理汇总了C++中MemoryBuffer::setLength方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryBuffer::setLength方法的具体用法?C++ MemoryBuffer::setLength怎么用?C++ MemoryBuffer::setLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryBuffer
的用法示例。
在下文中一共展示了MemoryBuffer::setLength方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ThorCompress
size32_t ThorCompress(const void * src, size32_t srcSz, MemoryBuffer & dest, size32_t threshold)
{
size32_t prev = dest.length();
size32_t dSz = srcSz + sizeof(size32_t);
void * d = dest.reserve(dSz);
size32_t ret = ThorCompress(src, srcSz, d, dSz, threshold);
dest.setLength(prev+ret);
return ret;
}
示例2: LZMACompressToBuffer
void LZMACompressToBuffer(MemoryBuffer & out, size32_t len, const void * src)
{
CLZMA lzma;
size32_t outbase = out.length();
size32_t *sz = (size32_t *)out.reserve(len+sizeof(size32_t)*2);
*sz = len;
sz++;
*sz = lzma.compress(src,len,sz+1);
if (*sz>len) {
*sz = len;
memcpy(sz+1,src,len);
}
else
out.setLength(outbase+sizeof(size32_t)*2+*sz);
}
示例3: aesDecrypt
size32_t aesDecrypt(MemoryBuffer &out, size32_t inSz, const void *inBytes, size32_t keyLen, const char *key, const char *iv)
{
if (0 == inSz)
return 0;
OwnedEVPCipherCtx ctx(EVP_CIPHER_CTX_new());
if (!ctx)
throw makeEVPException(0, "Failed EVP_CIPHER_CTX_new");
const size32_t cipherBlockSz = 128;
// from man page - "should have sufficient room for (inl + cipher_block_size) bytes unless the cipher block size is 1 in which case inl bytes is sufficient"
size32_t outMaxSz = (cipherBlockSz==1) ? inSz : (inSz + cipherBlockSz/8);
size32_t startSz = out.length();
byte *outPtr = (byte *)out.reserveTruncate(outMaxSz);
/* Initialise the decryption operation. IMPORTANT - ensure you use a key
* and IV size appropriate for your cipher
* In this example we are using 256 bit AES (i.e. a 256 bit key). The
* IV size for *most* modes is the same as the block size. For AES this
* is 128 bits
* */
if (!iv) iv = staticAesIV;
if (1 != EVP_DecryptInit_ex(ctx, getAesCipher(keyLen), nullptr, (const unsigned char *)key, (const unsigned char *)iv))
throw makeEVPException(0, "Failed EVP_DecryptInit_ex");
/* Provide the message to be decrypted, and obtain the plaintext output.
* EVP_DecryptUpdate can be called multiple times if necessary
*/
int outSz;
if (1 != EVP_DecryptUpdate(ctx, outPtr, &outSz, (const unsigned char *)inBytes, inSz))
throw makeEVPException(0, "Failed EVP_DecryptUpdate");
int plaintext_len = outSz;
/* Finalise the decryption. Further plaintext bytes may be written at
* this stage.
*/
if (1 != EVP_DecryptFinal_ex(ctx, outPtr + outSz, &outSz))
throw makeEVPException(0, "Failed EVP_DecryptFinal_ex");
plaintext_len += outSz;
out.setLength(startSz+plaintext_len); // truncate length of 'out' to final size
return (size32_t)plaintext_len;
}
示例4: gatherData
size32_t gatherData(MemoryBuffer &mb)
{
CriticalBlock b(crit);
if (progressEnabled)
{
MemoryBuffer progressData;
{
CriticalBlock b(crit);
ForEachItemIn(g, activeGraphs) // NB: 1 for each slavesPerProcess
{
CGraphBase &graph = activeGraphs.item(g);
progressData.append((unsigned)graph.queryJobChannel().queryMyRank()-1);
if (!graph.serializeStats(progressData))
progressData.setLength(progressData.length()-sizeof(unsigned));
}
}
size32_t sz = progressData.length();
if (sz)
{
ThorCompress(progressData, mb, 0x200);
return sz;
}
}