45 #define DEBUG(...) fprintf(stderr, __VA_ARGS__) 62 return ((buffer[0] << 0) | (buffer[1] << 8) |
63 (buffer[2] << 16) | (buffer[3] << 24));
67 buffer[0] = val & 0xFF;
68 buffer[1] = (val >> 8) & 0xFF;
69 buffer[2] = (val >> 16) & 0xFF;
70 buffer[3] = (val >> 24) & 0xFF;
117 char *
dest = (
char*) dest_val;
119 memcpy(dest + *offset, str->
input_next, to_copy);
133 *(out+4) = ((
unsigned)version &
k2Bits) << 6;
144 DEBUG(
"writeHeader() Put 7 bytes in output\n");
176 DEBUG(
"bufferToOutput() Not enough space left in output\n");
180 DEBUG(
"bufferToOutput() Flushing %i bytes, %i left in output\n",
190 DEBUG(
"bufferToOutput() Compressed to %i bytes\n", comp_size);
192 wrote = 4 + comp_size;
196 DEBUG(
"bufferToOutput() Can't compress, copying input\n");
200 wrote = 4 + uncomp_size;
207 DEBUG(
"bufferToOutput() Ate %i from buffer, wrote %i to output (%i)\n",
230 DEBUG(
"inputToBuffer() Wrote % 5i bytes to buffer (size=% 5i)\n",
271 if (!(4 <= block_size_id && block_size_id <= 7)) {
300 return (1 << (8 + (2 * block_id)));
305 if (ret < 0) {
return ret; }
320 if (ret < 0) {
return ret; }
325 int read = 0, wrote = 0;
328 if (read < 0) {
return read; }
333 if (wrote < 0) {
return wrote; }
335 }
while (read > 0 || wrote > 0);
378 int version = (header[4] >> 6) &
k2Bits;
379 int block_independence_flag = (header[4] >> 5) &
k1Bits;
380 int block_checksum_flag = (header[4] >> 4) &
k1Bits;
381 int stream_size_flag = (header[4] >> 3) &
k1Bits;
382 int stream_checksum_flag = (header[4] >> 2) &
k1Bits;
383 int reserved1 = (header[4] >> 1) &
k1Bits;
384 int preset_dictionary_flag = (header[4] >> 0) &
k1Bits;
386 int reserved2 = (header[5] >> 7) &
k1Bits;
387 int block_max_id = (header[5] >> 4) &
k3Bits;
388 int reserved3 = (header[5] >> 0) &
k4Bits;
394 if (reserved1 != 0 || reserved2 != 0 || reserved3 != 0) {
397 if (!(4 <= block_max_id && block_max_id <= 7)) {
402 if (stream_size_flag != 0) {
405 if (preset_dictionary_flag != 0) {
408 if (block_independence_flag != 1) {
411 if (block_checksum_flag != 0) {
414 if (stream_checksum_flag != 1) {
418 int header_checksum = (
XXH32(header + 4, 2, 0) >> 8) &
k8Bits;
419 int stored_header_checksum = (header[6] >> 0) &
k8Bits;
420 if (header_checksum != stored_header_checksum) {
441 DEBUG(
"readBlockSize() Block size = %i uncompressed = %i\n",
464 DEBUG(
"readBlock() Read %i bytes from input (block = %i/%i)\n",
493 if (decomp_size < 0) {
551 else if (ret < 0) {
return ret; }
554 if (ret < 0) {
return ret; }
566 char *output,
unsigned int *output_size,
597 char *output,
unsigned int *output_size) {
const int ROSLZ4_MEMORY_ERROR
GLboolean GLboolean GLboolean b
int writeEOS(roslz4_stream *str)
void advanceOutput(roslz4_stream *str, int nbytes)
void advanceInput(roslz4_stream *str, int nbytes)
int writeHeader(roslz4_stream *str)
int LZ4_decompress_safe(const char *source, char *dest, int compressedSize, int maxDecompressedSize)
uint32_t readUInt32(unsigned char *buffer)
const int ROSLZ4_OUTPUT_SMALL
std_msgs::Header * header(M &m)
returns Header<M>::pointer(m);
int LZ4_compress_default(const char *source, char *dest, int inputSize, int maxOutputSize)
void roslz4_decompressEnd(roslz4_stream *str)
int block_independence_flag
void streamStateFree(roslz4_stream *str)
XXH_PUBLIC_API unsigned int XXH32_digest(const XXH32_state_t *state_in)
GLboolean GLboolean GLboolean GLboolean a
int roslz4_compress(roslz4_stream *str, int action)
void roslz4_compressEnd(roslz4_stream *str)
int processHeader(roslz4_stream *str)
const int ROSLZ4_STREAM_END
int roslz4_buffToBuffCompress(char *input, unsigned int input_size, char *output, unsigned int *output_size, int block_size_id)
int readBlockSize(roslz4_stream *str)
int streamStateAlloc(roslz4_stream *str)
void fillUInt32(roslz4_stream *str, uint32_t *dest_val, int *offset)
void * XXH32_init(U32 seed)
const int ROSLZ4_PARAM_ERROR
int readBlock(roslz4_stream *str)
int roslz4_decompressStart(roslz4_stream *str)
int bufferToOutput(roslz4_stream *str)
void writeUInt32(unsigned char *buffer, uint32_t val)
const int ROSLZ4_DATA_ERROR
const uint32_t kEndOfStream
int decompressBlock(roslz4_stream *str)
GLenum GLenum GLenum input
const uint32_t kMagicNumber
int readChecksum(roslz4_stream *str)
int streamResizeBuffer(roslz4_stream *str, int block_size_id)
XXH_PUBLIC_API XXH_errorcode XXH32_update(XXH32_state_t *state_in, const void *input, size_t len)
int inputToBuffer(roslz4_stream *str)
XXH_PUBLIC_API unsigned int XXH32(const void *input, size_t len, unsigned int seed)
int roslz4_decompress(roslz4_stream *str)
int roslz4_compressStart(roslz4_stream *str, int block_size_id)
int roslz4_blockSizeFromIndex(int block_id)
int roslz4_buffToBuffDecompress(char *input, unsigned int input_size, char *output, unsigned int *output_size)