VRS
A file format for sensor data.
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
vrs::Decompressor Class Reference

Decompressor helper class, to decompresses data at a target location. More...

#include <Decompressor.h>

Classes

class  Lz4Decompressor
 Decompressor for lz4 data. More...
 
class  ZstdDecompressor
 Decompressor for zstd data. More...
 

Public Member Functions

void setCompressionType (CompressionType compressionType)
 
CompressionType getCompressionType () const
 
size_t getRecommendedInputBufferSize () const
 
int decompress (void *destination, uint32_t destinationSize, uint32_t &outReadSize)
 
void * allocateCompressedDataBuffer (size_t requestSize)
 
size_t getRemainingCompressedDataBufferSize () const
 
int initFrame (FileHandler &file, size_t &outFrameSize, size_t &inOutMaxReadSize)
 
int readFrame (FileHandler &file, void *dst, size_t frameSize, size_t &inOutMaxReadSize)
 
void reset ()
 Forget any remaining compressed data, get ready for a new frame.
 

Detailed Description

Decompressor helper class, to decompresses data at a target location.

The data to decompress must be in the internal buffer. Use getBuffer(size) to allocate memory for the internal buffer reserving at least size bytes and get a pointer where to write the data, probably reading from disk directly in that internal buffer. Call decompress to decompress a full record to the DataReference location. The whole record will be decompressed & written at the target location without intermediate memory copy.

Member Function Documentation

◆ allocateCompressedDataBuffer()

void * vrs::Decompressor::allocateCompressedDataBuffer ( size_t  requestSize)

Get a buffer of a specific size where to write the data to be decoded. The decompressor will assume that the buffer will be filed to the requested size.

Parameters
requestSizeSize to allocate.
Returns
Pointer to the buffer.

◆ decompress()

int vrs::Decompressor::decompress ( void *  destination,
uint32_t  destinationSize,
uint32_t &  outReadSize 
)

Decompress a maximum of destinationSize bytes of data, at the pointed to destination, and return the number of bytes read in outReadSize.

Returns
0 if no error occurred, a file system error code otherwise.

◆ getRemainingCompressedDataBufferSize()

size_t vrs::Decompressor::getRemainingCompressedDataBufferSize ( ) const
inline

Tell how many bytes we haven't yet decoded from our compressed data buffer.

Returns
Number of bytes.

◆ initFrame()

int vrs::Decompressor::initFrame ( FileHandler file,
size_t &  outFrameSize,
size_t &  inOutMaxReadSize 
)

Frame compression APIs, to read compressed frames from a file. 1/ call reset() (if the compressor was used before). 2/ call initFrame to know how large the uncompressed frame is. 3/ allocate enough memory for the whole frame. 4/ read the whole frame in the buffer 5/ if reading more than one successive frames, do not call reset, go straight back to 2/

Start to read a frame, by sniffing the upcoming frame's size.

Parameters
fileA file open for reading, at the position of the frame.
frameSizeOn success, set to the size in bytes of the upcoming frame.
maxReadSizeMax number of bytes of compressed frames data. If there are multiple frames, or the size of the compressed frame(s) is unknown, this number maybe the remaining file size. This number is updated as needed, if data is read from the file and placed in an internal decode buffer.
Returns
0 for success, or an error code. This could happen if you try to read data that isn't a compressed frame. Note that the file might be read past the end of the compressed frame, but not beyond the incoming value of inOutMaxReadSize. So when reading successive frames, do not reset the compression object between frames. Instead, just call initFrame again, after successfully reading a frame.

◆ readFrame()

int vrs::Decompressor::readFrame ( FileHandler file,
void *  dst,
size_t  frameSize,
size_t &  inOutMaxReadSize 
)

Read a compressed frame, all at once.

Parameters
fileA file open for reading, at the position of the frame.
dstA pointer to an allocated buffer large enough for the whole frame.
frameSizeThe size of the frame, as returned by initFrame. The buffer must be large enough to read the whole frame at once.
maxReadSizeMax number of bytes of compressed frames data left.

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