Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E3930200CB0 for ; Thu, 18 May 2017 23:51:02 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id E251B160BD0; Thu, 18 May 2017 21:51:02 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 313AD160BB5 for ; Thu, 18 May 2017 23:51:02 +0200 (CEST) Received: (qmail 79562 invoked by uid 500); 18 May 2017 21:51:01 -0000 Mailing-List: contact dev-help@orc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@orc.apache.org Delivered-To: mailing list dev@orc.apache.org Received: (qmail 79457 invoked by uid 99); 18 May 2017 21:51:01 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 May 2017 21:51:01 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EAE21DFC8B; Thu, 18 May 2017 21:51:00 +0000 (UTC) From: majetideepak To: dev@orc.apache.org Reply-To: dev@orc.apache.org References: In-Reply-To: Subject: [GitHub] orc pull request #122: ORC-192 Implement zlib compresion stream Content-Type: text/plain Message-Id: <20170518215100.EAE21DFC8B@git1-us-west.apache.org> Date: Thu, 18 May 2017 21:51:00 +0000 (UTC) archived-at: Thu, 18 May 2017 21:51:03 -0000 Github user majetideepak commented on a diff in the pull request: https://github.com/apache/orc/pull/122#discussion_r117355066 --- Diff: c++/src/Compression.cc --- @@ -33,6 +33,254 @@ namespace orc { + class CompressionStreamBase: public BufferedOutputStream { + public: + CompressionStreamBase(OutputStream * outStream, + int compressionLevel, + uint64_t capacity, + uint64_t blockSize, + MemoryPool& pool); + + virtual bool Next(void** data, int*size) override = 0; + virtual void BackUp(int count) override; + + virtual std::string getName() const override = 0; + virtual uint64_t flush() override; + + virtual bool isCompressed() const override { return true; } + virtual uint64_t getSize() const override; + + protected: + void writeHeader(char * buffer, size_t compressedSize, bool original) { + buffer[0] = static_cast((compressedSize << 1) + (original ? 1 : 0)); + buffer[1] = static_cast(compressedSize >> 7); + buffer[2] = static_cast(compressedSize >> 15); + } + + // Buffer to hold uncompressed data until user calls Next() + DataBuffer rawInputBuffer; + + // Compress level + int level; + + // Compressed data output buffer + char * outputBuffer; + + // Size for compressionBuffer + int bufferSize; + + // Compress output position + int outputPosition; + + // Compress output buffer size + int outputSize; + }; + + CompressionStreamBase::CompressionStreamBase(OutputStream * outStream, + int compressionLevel, + uint64_t capacity, + uint64_t blockSize, + MemoryPool& pool) : + BufferedOutputStream(pool, + outStream, + capacity, + blockSize), + rawInputBuffer(pool, blockSize), + level(compressionLevel), + outputBuffer(nullptr), + bufferSize(0), + outputPosition(0), + outputSize(0) { + // PASS + } + + void CompressionStreamBase::BackUp(int count) { + if (count > bufferSize) { + throw std::logic_error("Can't backup that much!"); + } + bufferSize -= count; + } + + uint64_t CompressionStreamBase::flush() { + void * data; + int size; + if (!Next(&data, &size)) { + throw std::logic_error("Failed to flush compression buffer."); --- End diff -- use `ParseError` here. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---