Skip to content

Commit

Permalink
Add snappy as compression algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
kripton committed Jun 10, 2021
1 parent 920ebc7 commit 7897b20
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/snappy
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pico_sdk_init()
include(../lib/heatshrink/CMakeLists.txt)
include(../lib/zlib/interfaceLibForPicoSDK.cmake)
include(../lib/zstd/interfaceLibForPicoSDK.cmake)
include(../lib/snappy/interfaceLibForPicoSDK.cmake)

## Add our own C/C++ files here
## Sorted alphabetically
Expand All @@ -22,6 +23,7 @@ add_executable(${CMAKE_PROJECT_NAME}
algo-heatshrink.c
algo-zlib.c
algo-zstd.c
algo-snappy.c
main.c
)

Expand Down Expand Up @@ -51,6 +53,7 @@ target_link_libraries(${CMAKE_PROJECT_NAME}
pico_stdlib
zlib
zstd
snappy
)

## enable usb output, disable uart output
Expand Down
17 changes: 17 additions & 0 deletions src/algo-snappy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "algo-zlib.h"

#include "../lib/snappy/snappy-c.h"

void mysnappy_init()
{
}

void mysnappy_compress(uint8_t *input, size_t insize, uint8_t *output, size_t *outsize)
{
snappy_compress(input, insize, output, outsize);
}

void mysnappy_uncompress(uint8_t *input, size_t insize, uint8_t *output, size_t *outsize)
{
snappy_uncompress(input, insize, output, outsize);
}
10 changes: 10 additions & 0 deletions src/algo-snappy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef __ALGO_SNAPPY_H__
#define __ALGO_SNAPPY_H__

#include "pico/stdlib.h"

void mysnappy_init();
void mysnappy_compress(uint8_t* input, size_t insize, uint8_t* output, size_t* outsize);
void mysnappy_uncompress(uint8_t* input, size_t insize, uint8_t* output, size_t* outsize);

#endif // __ALGO_SNAPPY_H__
9 changes: 9 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "algo-heatshrink.h"
#include "algo-zlib.h"
#include "algo-zstd.h"
#include "algo-snappy.h"


// TEST VECTORS
Expand Down Expand Up @@ -54,6 +55,7 @@ enum {
ALGO_HEATSHRINK,
ALGO_ZLIB,
ALGO_ZSTD,
ALGO_SNAPPY,
// Add more HERE
ALGO_NUM_TOTAL
};
Expand Down Expand Up @@ -198,6 +200,13 @@ int main() {
algos[ALGO_ZSTD].uncompress = zstd_uncompress;
algos[ALGO_ZSTD].init();

// Algo 2: snappy
sprintf(algos[ALGO_SNAPPY].name, "SNAPPY");
algos[ALGO_SNAPPY].init = mysnappy_init;
algos[ALGO_SNAPPY].compress = mysnappy_compress;
algos[ALGO_SNAPPY].uncompress = mysnappy_uncompress;
algos[ALGO_SNAPPY].init();

finish_time = time_us_32();
elapsed_time = finish_time - start_time;
printf("%luµs\n", elapsed_time);
Expand Down

0 comments on commit 7897b20

Please sign in to comment.