FreeNOS
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
Lz4Decompressor Class Reference

Decompress data using the LZ4 algorithm created by Yann Collet. More...

#include <Lz4Decompressor.h>

Public Types

enum  Result { Success, IOError, InvalidArgument, NotSupported }
 Result codes. More...
 

Public Member Functions

 Lz4Decompressor (const void *data, const Size size)
 Constructor function. More...
 
Result initialize ()
 Initialize the decompressor. More...
 
u64 getUncompressedSize () const
 Get size of the uncompressed data. More...
 
Result read (void *buffer, const Size size) const
 Reads compressed data. More...
 

Private Types

enum  FrameFlgFields {
  FrameDictIdShift = 0, FrameContentChkShift = 2, FrameContentSzShift = 3, FrameBlockChkShift = 4,
  FrameBlockIndShift = 5, FrameVersionShift = 6
}
 Frame FLG Field Shift values. More...
 

Private Member Functions

const u32 decompress (const u8 *input, const Size inputSize, u8 *output, const Size outputSize) const
 Decompress a block of compressed data. More...
 
const u32 integerDecode (const u32 initial, const u8 *next, Size &byteCount) const
 Decode input data as integer (little-endian, 32-bit unsigned) More...
 

Private Attributes

const u8m_inputData
 Compressed input data. More...
 
const Size m_inputSize
 Total size in bytes of the compressed input data. More...
 
Size m_frameDescSize
 Size of the frame descriptor in bytes. More...
 
bool m_blockChecksums
 True if blocks have checksums enabled. More...
 
bool m_contentChecksum
 True if the input data buffer contains content checksum. More...
 
u64 m_contentSize
 Content size as specified in the frame header. More...
 
Size m_blockMaximumSize
 Maximum block size in bytes of the uncompressed content. More...
 

Static Private Attributes

static const u32 FrameMagic = 0x184D2204
 Magic number value marks the start of the frame header. More...
 
static const u8 FrameVersion = 0x01
 Current supported version of the LZ4 algorithm. More...
 
static const u32 EndMark = 0x00000000
 EndMark marks the end of the data stream. More...
 

Detailed Description

Decompress data using the LZ4 algorithm created by Yann Collet.

See also
http://www.lz4.org
https://lz4.github.io/lz4/
https://en.wikipedia.org/wiki/LZ4_(compression_algorithm)

Definition at line 39 of file Lz4Decompressor.h.

Member Enumeration Documentation

◆ FrameFlgFields

Frame FLG Field Shift values.

Enumerator
FrameDictIdShift 
FrameContentChkShift 
FrameContentSzShift 
FrameBlockChkShift 
FrameBlockIndShift 
FrameVersionShift 

Definition at line 49 of file Lz4Decompressor.h.

◆ Result

Result codes.

Enumerator
Success 
IOError 
InvalidArgument 
NotSupported 

Definition at line 70 of file Lz4Decompressor.h.

Constructor & Destructor Documentation

◆ Lz4Decompressor()

Lz4Decompressor::Lz4Decompressor ( const void *  data,
const Size  size 
)

Constructor function.

Parameters
dataInput data buffer
sizeSize in bytes of the input buffer

Definition at line 24 of file Lz4Decompressor.cpp.

Member Function Documentation

◆ decompress()

const u32 Lz4Decompressor::decompress ( const u8 input,
const Size  inputSize,
u8 output,
const Size  outputSize 
) const
private

Decompress a block of compressed data.

Parameters
inputCompressed block data
inputSizeNumber of compressed bytes
outputOutput buffer to decompress to
outputSizeMaximum number of bytes to decompress
Returns
Number of bytes decompressed

Definition at line 204 of file Lz4Decompressor.cpp.

References assert, MemoryBlock::copy(), DEBUG, integerDecode(), m_blockMaximumSize, and readLe16().

Referenced by read().

◆ getUncompressedSize()

u64 Lz4Decompressor::getUncompressedSize ( ) const

Get size of the uncompressed data.

Returns
Total size in bytes

Definition at line 125 of file Lz4Decompressor.cpp.

References m_contentSize.

Referenced by Decompress::decompressFile(), forkexec(), MpiTarget::initializeMaster(), CoreServer::loadKernel(), RecoveryServer::reloadProgram(), and MpiProxy::startRemoteProcess().

◆ initialize()

Lz4Decompressor::Result Lz4Decompressor::initialize ( )

◆ integerDecode()

const u32 Lz4Decompressor::integerDecode ( const u32  initial,
const u8 next,
Size byteCount 
) const
inlineprivate

Decode input data as integer (little-endian, 32-bit unsigned)

Parameters
initialThe initial integer value to use
nextPointer to next data to decode as integer
byteCountOn output contains the number of bytes decoded
Returns
Decoded unsigned 32-bit integer value

Definition at line 179 of file Lz4Decompressor.cpp.

Referenced by decompress().

◆ read()

Lz4Decompressor::Result Lz4Decompressor::read ( void *  buffer,
const Size  size 
) const

Reads compressed data.

Parameters
bufferOutput buffer.
sizeNumber of bytes of uncompressed data to copy.
Returns
Result code

Definition at line 130 of file Lz4Decompressor.cpp.

References assert, MemoryBlock::copy(), decompress(), EndMark, m_blockChecksums, m_blockMaximumSize, m_frameDescSize, m_inputData, m_inputSize, readLe32(), and Success.

Referenced by Decompress::decompressFile(), forkexec(), MpiTarget::initializeMaster(), CoreServer::loadKernel(), RecoveryServer::reloadProgram(), and MpiProxy::startRemoteProcess().

Field Documentation

◆ EndMark

const u32 Lz4Decompressor::EndMark = 0x00000000
staticprivate

EndMark marks the end of the data stream.

Definition at line 63 of file Lz4Decompressor.h.

Referenced by read().

◆ FrameMagic

const u32 Lz4Decompressor::FrameMagic = 0x184D2204
staticprivate

Magic number value marks the start of the frame header.

Definition at line 44 of file Lz4Decompressor.h.

Referenced by initialize().

◆ FrameVersion

const u8 Lz4Decompressor::FrameVersion = 0x01
staticprivate

Current supported version of the LZ4 algorithm.

Definition at line 60 of file Lz4Decompressor.h.

Referenced by initialize().

◆ m_blockChecksums

bool Lz4Decompressor::m_blockChecksums
private

True if blocks have checksums enabled.

Definition at line 154 of file Lz4Decompressor.h.

Referenced by initialize(), and read().

◆ m_blockMaximumSize

Size Lz4Decompressor::m_blockMaximumSize
private

Maximum block size in bytes of the uncompressed content.

Definition at line 163 of file Lz4Decompressor.h.

Referenced by decompress(), initialize(), and read().

◆ m_contentChecksum

bool Lz4Decompressor::m_contentChecksum
private

True if the input data buffer contains content checksum.

Definition at line 157 of file Lz4Decompressor.h.

Referenced by initialize().

◆ m_contentSize

u64 Lz4Decompressor::m_contentSize
private

Content size as specified in the frame header.

Definition at line 160 of file Lz4Decompressor.h.

Referenced by getUncompressedSize(), and initialize().

◆ m_frameDescSize

Size Lz4Decompressor::m_frameDescSize
private

Size of the frame descriptor in bytes.

Definition at line 151 of file Lz4Decompressor.h.

Referenced by initialize(), and read().

◆ m_inputData

const u8* Lz4Decompressor::m_inputData
private

Compressed input data.

Definition at line 145 of file Lz4Decompressor.h.

Referenced by initialize(), and read().

◆ m_inputSize

const Size Lz4Decompressor::m_inputSize
private

Total size in bytes of the compressed input data.

Definition at line 148 of file Lz4Decompressor.h.

Referenced by initialize(), and read().


The documentation for this class was generated from the following files: