Go to the documentation of this file.
18 #include <FreeNOS/User.h>
25 : m_inputData(static_cast<const
u8 *>(data))
28 , m_blockChecksums(false)
29 , m_contentChecksum(false)
31 , m_blockMaximumSize(0)
69 ERROR(
"inter-dependent blocks not supported");
86 ERROR(
"content size must not be zero");
117 ERROR(
"invalid maximum block size value: " << (bd >> 4));
131 const Size size)
const
135 u8 *output =
static_cast<u8 *
>(buffer);
138 while (copied < size && input < inputEnd)
142 const u32 blockSize = blockSizeByte & ~(1 << 31);
143 const bool isCompressed = blockSizeByte & (1 << 31) ?
false :
true;
152 input +=
sizeof(
u32);
157 uncompSize =
decompress(input, blockSize, output, size - copied);
163 uncompSize = blockSize;
167 copied += uncompSize;
168 output += uncompSize;
172 input +=
sizeof(
u32);
181 Size &byteCount)
const
190 for (byteCount = 1; ; byteCount++)
192 const u8 byte = *next++;
205 const Size inputSize,
207 const Size outputSize)
const
209 const u8 *inputEnd = input + inputSize;
210 Size outputOffset = 0;
213 while (input < inputEnd && outputOffset < outputSize)
215 u32 literalBytes = 0;
219 const u8 token = *input;
224 input += literalBytes;
225 DEBUG(
"token = " << token <<
" literalsCount = " << literalsCount <<
" literalBytes = " << literalBytes);
228 if (literalsCount > 0)
231 input += literalsCount;
232 outputOffset += literalsCount;
236 if (input >= inputEnd)
243 assert(off <= outputOffset);
244 const u32 matchOffset = outputOffset - off;
245 input +=
sizeof(
u16);
252 DEBUG(
"matchOffset = " << matchOffset <<
" matchCount = " << matchCount);
254 outputOffset += matchCount;
static Size copy(void *dest, const void *src, Size count)
Copy memory from one place to another.
const u16 readLe16(const void *data)
Read 16-bit little endian integer.
Size m_blockMaximumSize
Maximum block size in bytes of the uncompressed content.
static const u32 FrameMagic
Magic number value marks the start of the frame header.
u64 getUncompressedSize() const
Get size of the uncompressed data.
Size m_frameDescSize
Size of the frame descriptor in bytes.
static const u8 FrameVersion
Current supported version of the LZ4 algorithm.
Result initialize()
Initialize the decompressor.
const u8 * m_inputData
Compressed input data.
const u64 readLe64(const void *data)
Read 64-bit little endian integer.
#define MegaByte(v)
Convert megabytes to bytes.
unsigned long long u64
Unsigned 64-bit number.
const Size m_inputSize
Total size in bytes of the compressed input data.
#define KiloByte(v)
Convert kilobytes to bytes.
#define DEBUG(msg)
Output a debug message to standard output.
bool m_blockChecksums
True if blocks have checksums enabled.
unsigned short u16
Unsigned 16-bit number.
const u32 decompress(const u8 *input, const Size inputSize, u8 *output, const Size outputSize) const
Decompress a block of compressed data.
unsigned int u32
Unsigned 32-bit number.
unsigned int Size
Any sane size indicator cannot go negative.
const u32 readLe32(const void *data)
Read 32-bit little endian integer.
Lz4Decompressor(const void *data, const Size size)
Constructor function.
bool m_contentChecksum
True if the input data buffer contains content checksum.
#define assert(exp)
Insert program diagnostics.
Result read(void *buffer, const Size size) const
Reads compressed data.
#define ERROR(msg)
Output an error message.
unsigned char u8
Unsigned 8-bit number.
static const u32 EndMark
EndMark marks the end of the data stream.
u64 m_contentSize
Content size as specified in the frame header.
const u32 integerDecode(const u32 initial, const u8 *next, Size &byteCount) const
Decode input data as integer (little-endian, 32-bit unsigned)