FreeNOS
Lz4Decompressor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __LIB_LIBEXEC_LZ4DECOMPRESSOR_H
19 #define __LIB_LIBEXEC_LZ4DECOMPRESSOR_H
20 
21 #include <Types.h>
22 #include <Index.h>
23 
40 {
41  private:
42 
44  static const u32 FrameMagic = 0x184D2204;
45 
50  {
57  };
58 
60  static const u8 FrameVersion = 0x01;
61 
63  static const u32 EndMark = 0x00000000;
64 
65  public:
66 
70  enum Result
71  {
76  };
77 
78  public:
79 
86  Lz4Decompressor(const void *data, const Size size);
87 
94 
100  u64 getUncompressedSize() const;
101 
110  Result read(void *buffer, const Size size) const;
111 
112  private:
113 
124  const u32 decompress(const u8 *input,
125  const Size inputSize,
126  u8 *output,
127  const Size outputSize) const;
128 
138  inline const u32 integerDecode(const u32 initial,
139  const u8 *next,
140  Size &byteCount) const;
141 
142  private:
143 
145  const u8 *m_inputData;
146 
149 
152 
155 
158 
161 
164 };
165 
171 #endif /* __LIB_LIBEXEC_LZ4DECOMPRESSOR_H */
Lz4Decompressor::FrameVersionShift
@ FrameVersionShift
Definition: Lz4Decompressor.h:56
Types.h
Lz4Decompressor::InvalidArgument
@ InvalidArgument
Definition: Lz4Decompressor.h:74
Lz4Decompressor::m_blockMaximumSize
Size m_blockMaximumSize
Maximum block size in bytes of the uncompressed content.
Definition: Lz4Decompressor.h:163
Lz4Decompressor::FrameContentSzShift
@ FrameContentSzShift
Definition: Lz4Decompressor.h:53
Index.h
Lz4Decompressor::FrameMagic
static const u32 FrameMagic
Magic number value marks the start of the frame header.
Definition: Lz4Decompressor.h:44
Lz4Decompressor::getUncompressedSize
u64 getUncompressedSize() const
Get size of the uncompressed data.
Definition: Lz4Decompressor.cpp:125
Lz4Decompressor::m_frameDescSize
Size m_frameDescSize
Size of the frame descriptor in bytes.
Definition: Lz4Decompressor.h:151
Lz4Decompressor::FrameVersion
static const u8 FrameVersion
Current supported version of the LZ4 algorithm.
Definition: Lz4Decompressor.h:60
Lz4Decompressor::initialize
Result initialize()
Initialize the decompressor.
Definition: Lz4Decompressor.cpp:35
Lz4Decompressor::FrameBlockChkShift
@ FrameBlockChkShift
Definition: Lz4Decompressor.h:54
Lz4Decompressor::m_inputData
const u8 * m_inputData
Compressed input data.
Definition: Lz4Decompressor.h:145
Lz4Decompressor::FrameDictIdShift
@ FrameDictIdShift
Definition: Lz4Decompressor.h:51
Lz4Decompressor::FrameContentChkShift
@ FrameContentChkShift
Definition: Lz4Decompressor.h:52
Lz4Decompressor::Success
@ Success
Definition: Lz4Decompressor.h:72
u64
unsigned long long u64
Unsigned 64-bit number.
Definition: Types.h:50
Lz4Decompressor::m_inputSize
const Size m_inputSize
Total size in bytes of the compressed input data.
Definition: Lz4Decompressor.h:148
Lz4Decompressor::m_blockChecksums
bool m_blockChecksums
True if blocks have checksums enabled.
Definition: Lz4Decompressor.h:154
Lz4Decompressor::decompress
const u32 decompress(const u8 *input, const Size inputSize, u8 *output, const Size outputSize) const
Decompress a block of compressed data.
Definition: Lz4Decompressor.cpp:204
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
Lz4Decompressor::IOError
@ IOError
Definition: Lz4Decompressor.h:73
Lz4Decompressor::Result
Result
Result codes.
Definition: Lz4Decompressor.h:70
Lz4Decompressor::NotSupported
@ NotSupported
Definition: Lz4Decompressor.h:75
Lz4Decompressor::Lz4Decompressor
Lz4Decompressor(const void *data, const Size size)
Constructor function.
Definition: Lz4Decompressor.cpp:24
Lz4Decompressor::m_contentChecksum
bool m_contentChecksum
True if the input data buffer contains content checksum.
Definition: Lz4Decompressor.h:157
Lz4Decompressor::read
Result read(void *buffer, const Size size) const
Reads compressed data.
Definition: Lz4Decompressor.cpp:130
u8
unsigned char u8
Unsigned 8-bit number.
Definition: Types.h:59
Lz4Decompressor
Decompress data using the LZ4 algorithm created by Yann Collet.
Definition: Lz4Decompressor.h:39
Lz4Decompressor::FrameBlockIndShift
@ FrameBlockIndShift
Definition: Lz4Decompressor.h:55
Lz4Decompressor::EndMark
static const u32 EndMark
EndMark marks the end of the data stream.
Definition: Lz4Decompressor.h:63
Lz4Decompressor::m_contentSize
u64 m_contentSize
Content size as specified in the frame header.
Definition: Lz4Decompressor.h:160
Lz4Decompressor::integerDecode
const u32 integerDecode(const u32 initial, const u8 *next, Size &byteCount) const
Decode input data as integer (little-endian, 32-bit unsigned)
Definition: Lz4Decompressor.cpp:179
Lz4Decompressor::FrameFlgFields
FrameFlgFields
Frame FLG Field Shift values.
Definition: Lz4Decompressor.h:49