![]() |
VRS
A file format for sensor data.
|
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 |
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.
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.
file | A file open for writing. |
data | A pointer to the data to add to the frame. |
dataSize | Number of bytes to add to the frame. |
inOutCompressedSize | Updated number of bytes written out to the file. |
maxCompressedSize | Max 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. |
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.
data | Pointer to the data to compress. |
dataSize | Number of bytes in the buffer to compress. |
preset | Compression preset to use. |
headerSpace | Number of bytes to reserve at the beginning of the buffer for a header initialized manually later. |
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.
file | A file open for writing. |
inOutCompressedSize | Updated number of bytes written out to the file. |
maxCompressedSize | Max 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. |
|
inline |
Get the compressed data after compression. The size to consider was returned by compress().
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.
frameSize | exact number of bytes that will be added to the frame in total. |
zstdPreset | compression preset to use. Only zstd presets are supported by this API. |
outSize | total number of compressed bytes written. |