当前位置: 首页>>代码示例>>C++>>正文


C++ MemoryBuffer::setLength方法代码示例

本文整理汇总了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;
}
开发者ID:AsherBond,项目名称:HPCC-Platform,代码行数:9,代码来源:thcompressutil.cpp

示例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);
}
开发者ID:Josh-Googler,项目名称:HPCC-Platform,代码行数:15,代码来源:jlzma.cpp

示例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;
}
开发者ID:AttilaVamos,项目名称:HPCC-Platform,代码行数:42,代码来源:ske.cpp

示例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;
         }
     }
开发者ID:RogerDev,项目名称:HPCC-Platform,代码行数:23,代码来源:slwatchdog.cpp


注:本文中的MemoryBuffer::setLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。