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

Helper class to compress data using lz4 or zstd presets. More...

#include <Compressor.h>

Classes

class  CompressorImpl
 
struct  uninitialized_byte
 

Public Member Functions

uint32_t compress (const void *data, size_t dataSize, CompressionPreset preset, size_t headerSpace=0)
 
int startFrame (size_t frameSize, CompressionPreset zstdPreset, uint32_t &outSize)
 
int addFrameData (WriteFileHandler &file, const void *data, size_t dataSize, uint32_t &inOutCompressedSize, size_t maxCompressedSize=0)
 
int endFrame (WriteFileHandler &file, uint32_t &inOutCompressedSize, size_t maxCompressedSize=0)
 
const void * getData () const
 
template<class HeaderType >
HeaderType * getHeader ()
 Get the space reserved for a header.
 
CompressionType getCompressionType () const
 
void clear ()
 Really deallocate the buffer's memory (clear() doesn't do that)
 

Static Public Member Functions

static bool shouldTryToCompress (CompressionPreset preset, size_t size)
 

Static Public Attributes

static const size_t kMinByteCountForCompression = 250
 

Detailed Description

Helper class to compress data using lz4 or zstd presets.

You can switch between presets at no cost. If presets don't work well enough with your data, you can easily experiment with new settings and add your own preset to CompressionPreset.

Member Function Documentation

◆ addFrameData()

int vrs::Compressor::addFrameData ( WriteFileHandler file,
const void *  data,
size_t  dataSize,
uint32_t &  inOutCompressedSize,
size_t  maxCompressedSize = 0 
)

Add data to a frame started before. The total amount of data may not exceed the declared size of the frame when it was started.

Parameters
fileA file open for writing.
dataA pointer to the data to add to the frame.
dataSizeNumber of bytes to add to the frame.
inOutCompressedSizeUpdated number of bytes written out to the file.
maxCompressedSizeMax number of bytes the compressed record may get. Fail if the compressed data is larger, while guarantying that fewer bytes have been written to disk.
Returns
0 for success, or an error code. The input buffer may be recycled immediately, but all the data may not have been written out to the file yet. You may add all the data of the frame in as many calls as you wish, one byte at a time, all at once, and anything in between.

◆ compress()

uint32_t vrs::Compressor::compress ( const void *  data,
size_t  dataSize,
CompressionPreset  preset,
size_t  headerSpace = 0 
)

Compress some data using a specific preset. If the compression setting doesn't lead to a smaller payload, because the data can't be compressed, then the record won't be compressed at all.

Parameters
dataPointer to the data to compress.
dataSizeNumber of bytes in the buffer to compress.
presetCompression preset to use.
headerSpaceNumber of bytes to reserve at the beginning of the buffer for a header initialized manually later.
Returns
The number of bytes of compressed data, or 0 in case of failure.

◆ endFrame()

int vrs::Compressor::endFrame ( WriteFileHandler file,
uint32_t &  inOutCompressedSize,
size_t  maxCompressedSize = 0 
)

Write out all the data left in internal compression buffers to disk, and complete the frame. After this call has been made, a new frame maybe started.

Parameters
fileA file open for writing.
inOutCompressedSizeUpdated number of bytes written out to the file.
maxCompressedSizeMax number of bytes the compressed record may get. Fail if the compressed data is larger, while guarantying that fewer bytes have been written to disk.
Returns
0 for success, or an error code. After this call, inOutSize counts the total number of bytes used for the compressed frame, including compression metadata. This number should be smaller than the frame size, but might be slightly larger, if the data couldn't be compressed.

◆ getData()

const void * vrs::Compressor::getData ( ) const
inline

Get the compressed data after compression. The size to consider was returned by compress().

Returns
Pointer to the compressed data.

◆ startFrame()

int vrs::Compressor::startFrame ( size_t  frameSize,
CompressionPreset  zstdPreset,
uint32_t &  outSize 
)

Frame compression APIs, with streaming to a file. Write to a file a block of data (a "frame") to be compressed. That data will be logically self contained, and its size will be retrievable when decoding the first byte. The frame can be added in multiple calls, making it easy to write a lot of data without needing large intermediate buffers.

Start a new frame, declaring its full size upfront. This size must be respected.

Parameters
frameSizeexact number of bytes that will be added to the frame in total.
zstdPresetcompression preset to use. Only zstd presets are supported by this API.
outSizetotal number of compressed bytes written.
Returns
0 for success, or an error code. This call initializes outSize to 0.

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