This library implements Exponential Golomb Encoding that can efficiently pack data with lots of small integeral values.
The advantage of the Exponential Golomb Encoding over other compression methods is that it can encode data in a single pass and does not require any buffering of the input or output data. These properties can make Exponential Golomb Encoding a good fit for applications that are tight on memory usage or require low latencies.
The data may need preprocessing before encoding to reduce the size of the values for better efficiency, for example with Delta Encoding.
- Optimized for data with lots of small integeral values.
- Compress and expand data in a single pass.
- No buffering of input data or output data.
A C++20 compliant compiler.
- Use standard C++.
- Minimalistic.
- Flexibile in usage.
- Optimazations for specific compilers and targets.
- Defining a container format.
This library focuses only on converting data to and from Exponential Golomb Encoding. You have to take care for the information such as the original data size, length of the encoded stream, checksums, etc.
Besides the following examples you can take a peek in the sources of the test program and the golomb utility about the usage of the golomb
library.
const std::array< uint8_t, 8 > values = { 0u, 1u, 2u, 3u, 4u, 255u, 0u, 2u };
// Encode using a range as input
std::vector< uint8_t > out_range;
pg::golomb::encode( values, std::back_inserter( out_range ) );
assert( out_range.size() == 5 );
// Encode using iterators as input
std::vector< uint8_t > out_iter;
pg::golomb::encode( std::begin( values ), std::end( values ), std::back_inserter( out_iter ) );
assert( out_iter.size() == 5 );
const std::array< uint8_t, 5 > data = { 0xA6u, 0x42u, 0x80u, 0x40u, 0x2Cu };
// Decode using a range as input
std::vector< int16_t > values_range;
pg::golomb::decode< int16_t >( data, std::back_inserter( values_range ) );
assert( values_range.size() == 8 );
// Decode using iterators as input
std::vector< int32_t > values_iter;
pg::golomb::decode< int32_t >( std::begin( data ), std::end( data ), std::back_inserter( values_iter ) );
assert( values_iter.size() == 8 );
This library encodes golomb data as big endian.
Values fed to the encoder or outputed by the decoder are in the platform's native endianess.
The golomb utility is an implementation for a commandline program that use this library. The utility can be used to test the efficiency of the compression for your use case.
You can build the utility with the provided makefile by running the following make command;
make golomb
Information about the usage is displayed by running the executable with the -h
option.
You can also read the help text that is displayed by the executable from the source file.