source: icGREP/icgrep-devel/icgrep/lz4FrameDecoder.h @ 6020

Last change on this file since 6020 was 6020, checked in by xwa163, 6 weeks ago
  1. New version of lz4_swizzled_match_copy kernel with higher performance
  2. Adjust related pipeline code
  3. Remove legacy comments
File size: 1.5 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#ifndef LZ4_FRAME_DECODER_H
8#define LZ4_FRAME_DECODER_H
9
10#include <cassert>
11#include <string>
12
13/**
14 * Only works on little-endian architectures for now.
15 * Does not support multi-frame files (streams) (optional in the spec).
16 * Checksums are always ignored.
17 */
18class LZ4FrameDecoder {
19public:
20
21    LZ4FrameDecoder(const std::string &filename);
22    LZ4FrameDecoder();
23
24    void init(const std::string &filename);
25
26    size_t getBlocksStart() const {
27        assert(mValid && "Invalid LZ4 frame.");
28        return mBlocksStart;
29    }
30
31    size_t getBlocksLength() const {
32        assert(mValid && "Invalid LZ4 frame.");
33        return mBlocksLength;
34    }
35
36    bool hasBlockChecksum() const {
37        assert(mValid && "Invalid LZ4 frame.");
38        return mHasBlockChecksum;
39    }
40
41    bool isValid() const {
42        return mValid;
43    }
44
45protected:
46    virtual size_t endMarkSize() const;
47    virtual size_t contentChecksumSize() const;
48
49private:
50    bool mValid = false;
51    size_t mFilesize;
52    size_t mBlocksStart;
53    size_t mBlocksLength;
54    size_t mFDLength;
55    bool mHasContentChecksum;
56    bool mHasBlockChecksum;
57
58    bool decodeFrameDescriptor(std::ifstream &f);
59
60    size_t getMinFileSize() {
61        return 4 +         // Magic number
62               3 +         // Frame descriptor (3-11 bytes)
63               this->endMarkSize();          // End mark
64    }
65};
66
67#endif
Note: See TracBrowser for help on using the repository browser.