|
17 | 17 | #include <esp_spi_flash.h> |
18 | 18 | #include <sys/stat.h> |
19 | 19 |
|
| 20 | +#include "shox96_0_2_0.h" |
| 21 | + |
20 | 22 | #undef dbg_printf |
21 | 23 | //#define dbg_printf(...) Serial.printf(__VA_ARGS__) |
22 | 24 | #define dbg_printf(...) 0 |
@@ -620,8 +622,57 @@ int esp32_CurrentTime( sqlite3_vfs * vfs, double * result ) |
620 | 622 | return SQLITE_OK; |
621 | 623 | } |
622 | 624 |
|
| 625 | +static void shox96_0_2c(sqlite3_context *context, int argc, sqlite3_value **argv) { |
| 626 | + int nIn, nOut; |
| 627 | + long int nOut2; |
| 628 | + const unsigned char *inBuf; |
| 629 | + unsigned char *outBuf; |
| 630 | + assert( argc==1 ); |
| 631 | + nIn = sqlite3_value_bytes(argv[0]); |
| 632 | + inBuf = (unsigned char *) sqlite3_value_blob(argv[0]); |
| 633 | + nOut = 13 + nIn + (nIn+999)/1000; |
| 634 | + outBuf = (unsigned char *) malloc( nOut+4 ); |
| 635 | + outBuf[0] = nIn>>24 & 0xff; |
| 636 | + outBuf[1] = nIn>>16 & 0xff; |
| 637 | + outBuf[2] = nIn>>8 & 0xff; |
| 638 | + outBuf[3] = nIn & 0xff; |
| 639 | + //nOut2 = (long int)nOut; |
| 640 | + nOut2 = shox96_0_2_0_compress((const char *) inBuf, nIn, (char *) &outBuf[4], NULL); |
| 641 | + sqlite3_result_blob(context, outBuf, nOut2+4, free); |
| 642 | +} |
| 643 | + |
| 644 | +static void shox96_0_2d(sqlite3_context *context, int argc, sqlite3_value **argv) { |
| 645 | + unsigned int nIn, nOut, rc; |
| 646 | + const unsigned char *inBuf; |
| 647 | + unsigned char *outBuf; |
| 648 | + long int nOut2; |
| 649 | + |
| 650 | + assert( argc==1 ); |
| 651 | + nIn = sqlite3_value_bytes(argv[0]); |
| 652 | + if( nIn<=4 ){ |
| 653 | + return; |
| 654 | + } |
| 655 | + inBuf = (unsigned char *) sqlite3_value_blob(argv[0]); |
| 656 | + nOut = (inBuf[0]<<24) + (inBuf[1]<<16) + (inBuf[2]<<8) + inBuf[3]; |
| 657 | + outBuf = (unsigned char *) malloc( nOut ); |
| 658 | + //nOut2 = (long int)nOut; |
| 659 | + nOut2 = shox96_0_2_0_decompress((const char *) &inBuf[4], nIn - 4, (char *) outBuf, NULL); |
| 660 | + //if( rc!=Z_OK ){ |
| 661 | + // free(outBuf); |
| 662 | + //}else{ |
| 663 | + sqlite3_result_blob(context, outBuf, nOut2, free); |
| 664 | + //} |
| 665 | +} |
| 666 | + |
| 667 | +int registerShox96_0_2(sqlite3 *db, const char **pzErrMsg, const struct sqlite3_api_routines *pThunk) { |
| 668 | + sqlite3_create_function(db, "shox96_0_2c", 1, SQLITE_UTF8, 0, shox96_0_2c, 0, 0); |
| 669 | + sqlite3_create_function(db, "shox96_0_2d", 1, SQLITE_UTF8, 0, shox96_0_2d, 0, 0); |
| 670 | + return SQLITE_OK; |
| 671 | +} |
| 672 | + |
623 | 673 | int sqlite3_os_init(void){ |
624 | 674 | sqlite3_vfs_register(&esp32Vfs, 1); |
| 675 | + sqlite3_auto_extension((void (*)())registerShox96_0_2); |
625 | 676 | return SQLITE_OK; |
626 | 677 | } |
627 | 678 |
|
|
0 commit comments