Skip to content

Commit

Permalink
Add snappy-c in addition to the existing snappy library
Browse files Browse the repository at this point in the history
  • Loading branch information
kripton committed Nov 17, 2021
1 parent 18513e9 commit 5806ea7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/snappy-c
Submodule snappy-c updated 8 files
+56 −2 compat.h
+4 −4 glue.c
+0 −3 interfaceLibForPicoSDK.cmake
+4 −4 scmd.c
+4 −4 sgverify.c
+23 −23 snappy.c
+8 −4 snappy.h
+3 −3 verify.c
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ include(../lib/heatshrink/CMakeLists.txt)
include(../lib/zlib/interfaceLibForPicoSDK.cmake)
include(../lib/zstd/interfaceLibForPicoSDK.cmake)
include(../lib/snappy/interfaceLibForPicoSDK.cmake)
include(../lib/snappy-c/interfaceLibForPicoSDK.cmake)
include(../lib/brotli/interfaceLibForPicoSDK.cmake)

## Add our own C/C++ files here
Expand All @@ -35,6 +36,7 @@ add_executable(${CMAKE_PROJECT_NAME}
algo-zlib.c
algo-zstd.c
algo-snappy.c
algo-snappyc.c
algo-brotli.c
main.c
)
Expand Down Expand Up @@ -79,6 +81,7 @@ target_link_libraries(${CMAKE_PROJECT_NAME}
zlib
zstd
snappy
snappyc
brotli
)

Expand Down
2 changes: 1 addition & 1 deletion src/algo-snappy.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "algo-zlib.h"
#include "algo-snappy.h"

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

Expand Down
20 changes: 20 additions & 0 deletions src/algo-snappyc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "algo-zlib.h"

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

struct snappy_env env;

void mysnappyc_init()
{
snappy_init_env(&env);
}

void mysnappyc_compress(uint8_t *input, size_t insize, uint8_t *output, size_t *outsize)
{
SNAPPYC_FUNCTION_NAME_PREFIXsnappy_compress(&env, input, insize, output, outsize);
}

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

#include "pico/stdlib.h"

void mysnappyc_init();
void mysnappyc_compress(uint8_t* input, size_t insize, uint8_t* output, size_t* outsize);
void mysnappyc_uncompress(uint8_t* input, size_t insize, uint8_t* output, size_t* outsize);

#endif // __ALGO_SNAPPYC_H__
8 changes: 8 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "algo-zstd.h"
#endif
#include "algo-snappy.h"
#include "algo-snappyc.h"
#if HAVE_ALGO_BROTLI
#include "algo-brotli.h"
#endif
Expand Down Expand Up @@ -63,6 +64,7 @@ enum {
ALGO_ZSTD,
#endif
ALGO_SNAPPY,
ALGO_SNAPPYC,
#if HAVE_ALGO_BROTLI
ALGO_BROTLI,
#endif
Expand Down Expand Up @@ -215,6 +217,12 @@ int main() {
algos[ALGO_SNAPPY].uncompress = mysnappy_uncompress;
algos[ALGO_SNAPPY].init();

sprintf(algos[ALGO_SNAPPYC].name, "SNAPPY-C");
algos[ALGO_SNAPPYC].init = mysnappyc_init;
algos[ALGO_SNAPPYC].compress = mysnappyc_compress;
algos[ALGO_SNAPPYC].uncompress = mysnappyc_uncompress;
algos[ALGO_SNAPPYC].init();

#if HAVE_ALGO_BROTLI
sprintf(algos[ALGO_BROTLI].name, "BROTLI");
algos[ALGO_BROTLI].init = brotli_init;
Expand Down

0 comments on commit 5806ea7

Please sign in to comment.