cpp/src/io/orc/orc.cpp
/**
 * @brief ORC block decompression
 *
 * @param[in] srcBytes compressed data
 * @param[in] srcLen length of compressed data
 * @param[out] dstLen length of uncompressed data
 *
 * @returns pointer to uncompressed data, nullptr if error
 */
@brief ORC block decompression
@param[in] srcBytes compressed data
@param[in] srcLen length of compressed data
@param[out] dstLen length of uncompressed data

@returns pointer to uncompressed data, nullptr if error
@brief ORC block decompression @param [ in ] srcBytes compressed data @param [ in ] srcLen length of compressed data @param [ out ] dstLen length of uncompressed data @returns pointer to uncompressed data nullptr if error
const uint8_t* OrcDecompressor::Decompress(const uint8_t* srcBytes, size_t srcLen, size_t* dstLen)
{
  if (m_kind == NONE) {
    *dstLen = srcLen;
    return srcBytes;
  }
  size_t max_dst_length = 0;
  for (size_t i = 0; i + 3 < srcLen;) {
    uint32_t block_len       = srcBytes[i] | (srcBytes[i + 1] << 8) | (srcBytes[i + 2] << 16);
    uint32_t is_uncompressed = block_len & 1;
    i += 3;
    block_len >>= 1;
    if (is_uncompressed) {
      max_dst_length += block_len;
    } else {
      max_dst_length += m_blockSize;
    }
    i += block_len;
    if (i > srcLen || block_len > m_blockSize) { return nullptr; }
  }
  if (max_dst_length < m_blockSize) {
    if (srcLen < 3) {
      return nullptr;
    }
    *dstLen = srcLen - 3;
    return srcBytes + 3;
  }
  m_buf.resize(max_dst_length);
  auto dst          = m_buf.data();
  size_t dst_length = 0;
  for (size_t i = 0; i + 3 < srcLen;) {
    uint32_t block_len       = srcBytes[i] | (srcBytes[i + 1] << 8) | (srcBytes[i + 2] << 16);
    uint32_t is_uncompressed = block_len & 1;
    i += 3;
    block_len >>= 1;
    if (is_uncompressed) {
      memcpy(dst + dst_length, srcBytes + i, block_len);
      dst_length += block_len;
    } else {
      dst_length +=
        m_decompressor->Decompress(dst + dst_length, m_blockSize, srcBytes + i, block_len);
    }
    i += block_len;
  }
  *dstLen = dst_length;
  return m_buf.data();
}
const uint8_t * OrcDecompressor :: Decompress ( const uint8_t * srcBytes , size_t srcLen , size_t * dstLen ) { if ( m_kind == NONE ) { * dstLen = srcLen ; return srcBytes ; } size_t max_dst_length = 0 ; for ( size_t i = 0 ; i + 3 < srcLen ; ) { uint32_t block_len = srcBytes [ i ] | ( srcBytes [ i + 1 ] << 8 ) | ( srcBytes [ i + 2 ] << 16 ) ; uint32_t is_uncompressed = block_len & 1 ; i += 3 ; block_len >>= 1 ; if ( is_uncompressed ) { max_dst_length += block_len ; } else { max_dst_length += m_blockSize ; } i += block_len ; if ( i > srcLen || block_len > m_blockSize ) { return nullptr ; } } if ( max_dst_length < m_blockSize ) { if ( srcLen < 3 ) { return nullptr ; } * dstLen = srcLen - 3 ; return srcBytes + 3 ; } m_buf . resize ( max_dst_length ) ; auto dst = m_buf . data ( ) ; size_t dst_length = 0 ; for ( size_t i = 0 ; i + 3 < srcLen ; ) { uint32_t block_len = srcBytes [ i ] | ( srcBytes [ i + 1 ] << 8 ) | ( srcBytes [ i + 2 ] << 16 ) ; uint32_t is_uncompressed = block_len & 1 ; i += 3 ; block_len >>= 1 ; if ( is_uncompressed ) { memcpy ( dst + dst_length , srcBytes + i , block_len ) ; dst_length += block_len ; } else { dst_length += m_decompressor -> Decompress ( dst + dst_length , m_blockSize , srcBytes + i , block_len ) ; } i += block_len ; } * dstLen = dst_length ; return m_buf . data ( ) ; }
@brief ORC block decompression
 @param[in] srcBytes compressed data
 @param[in] srcLen length of compressed data
 @param[out] dstLen length of uncompressed data
@brief ORC block decompression @param [ in ] srcBytes compressed data @param [ in ] srcLen length of compressed data @param [ out ] dstLen length of uncompressed data
// If uncompressed, just pass-through the input // First, scan the input for the number of blocks and worst-case output size // Uncompressed block // Check if we have a single uncompressed block, or no blocks // Total size is less than the 3-byte header // Uncompressed block // Compressed block