]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Make sqlite_encode_binary() and sqlite_decode_binary() an official part of
authordrh <drh@noemail.net>
Sun, 14 Mar 2004 22:11:59 +0000 (22:11 +0000)
committerdrh <drh@noemail.net>
Sun, 14 Mar 2004 22:11:59 +0000 (22:11 +0000)
the library. (CVS 1295)

FossilOrigin-Name: 786fe545560ec6c42bb0e344345031f425bf177a

main.mk
manifest
manifest.uuid
publish.sh
src/encode.c

diff --git a/main.mk b/main.mk
index 840b336981b4d622a4cffdd3437ad8fb50cb7cf4..2d9f0be50207a5183180f976bf9d1dbb695a4465 100644 (file)
--- a/main.mk
+++ b/main.mk
@@ -72,6 +72,7 @@ SRC = \
   $(TOP)/src/copy.c \
   $(TOP)/src/date.c \
   $(TOP)/src/delete.c \
+  $(TOP)/src/encode.c \
   $(TOP)/src/expr.c \
   $(TOP)/src/func.c \
   $(TOP)/src/hash.c \
@@ -268,6 +269,9 @@ date.o:     $(TOP)/src/date.c $(HDR)
 delete.o:      $(TOP)/src/delete.c $(HDR)
        $(TCCX) -c $(TOP)/src/delete.c
 
+encode.o:      $(TOP)/src/encode.c
+       $(TCCX) -c $(TOP)/src/encode.c
+
 expr.o:        $(TOP)/src/expr.c $(HDR)
        $(TCCX) -c $(TOP)/src/expr.c
 
index c3b56b6dc75a3de82c2c03923cb92b8c2a911f94..3e768c03bfca485da0d465c6550d8a8cf6af0418 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Updates\sto\sthe\sarchitecture\sdocument.\s(CVS\s1294)
-D 2004-03-14T11:57:58
+C Make\ssqlite_encode_binary()\sand\ssqlite_decode_binary()\san\sofficial\spart\sof\nthe\slibrary.\s(CVS\s1295)
+D 2004-03-14T22:12:00
 F Makefile.in 46788b65500865e3fd965f7617d41697da8a11a1
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -15,8 +15,8 @@ F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
 F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
 F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826
-F main.mk d88d460c46a12ceb33daad7a7a8725e4bc2dbaad
-F publish.sh d413bc45500e6d76db0535e46628fa5c88df1c6f
+F main.mk 1b27efb94be53a96c4333584a00a59fcc87ddc37
+F publish.sh 1cd5c982388560fa91eedf6a338e210f713b35c8
 F spec.template a38492f1c1dd349fc24cb0565e08afc53045304b
 F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
 F sqlite.def a4d2ada1c3667fd1bc18a37bf2ff9dcf138e0d51
@@ -30,7 +30,7 @@ F src/build.c c8ab8b467d9a64254b0d4d42083f6313b3a980d1
 F src/copy.c 750e13828c3e4a293123e36aaa7cf0f22466248a
 F src/date.c f055419d602bde622c70f831350b6b52f2235de0
 F src/delete.c 82001c74882319f94dab5f6b92a27311b31092ae
-F src/encode.c 9e70ea1e4e746f23f18180949e94f1bb1c2220d3
+F src/encode.c e6518a1e3326a07539a88d2082cbaa3389cdf6e0
 F src/expr.c 95ea5d47d11b5085aaeeb77d60b17c2cba13383a
 F src/func.c 34fead7a33e82095f6412d3fafd379d47864b3be
 F src/hash.c 9b56ef3b291e25168f630d5643a4264ec011c70e
@@ -188,7 +188,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
 F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P 31c94acc72d318b5dec0fef1485621943add45c8
-R 4444a9fae45099d79266fa1def7dab13
+P c661cc81b6981c536c107f40525ad9783b11ea82
+R 53b6160aa94d763507d1d66642e02dba
 U drh
-Z 8aa570decc2b64f7981738dac3c42536
+Z 751dfdf95f809133e2f24efbf8215847
index e3c4aa55281a922a4046113643b68db9dab1f785..f4677ec2cbce537e95eba7189afc76fe64980fa9 100644 (file)
@@ -1 +1 @@
-c661cc81b6981c536c107f40525ad9783b11ea82
\ No newline at end of file
+786fe545560ec6c42bb0e344345031f425bf177a
\ No newline at end of file
index 4691dee6e58ff14f8edbc49272d6e84f239648ad..d15e9bf7034ffbb5ea5ff546b3e56e2ee3eb65c1 100644 (file)
@@ -122,6 +122,8 @@ sqlite_finalize
 sqlite_reset
 sqlite_bind
 sqlite_last_statement_changes
+sqlite_encode_binary
+sqlite_decode_binary
 END_OF_FILE
 i386-mingw32msvc-dllwrap \
      --def sqlite.def -v --export-all \
index 925995d190855060c077465a10c6875b6d13ca73..712619c4c7dc4b188bce9225ef45bf9b91f3419c 100644 (file)
 ** data in an SQLite database.  The code in this file is not used by any other
 ** part of the SQLite library.
 **
-** $Id: encode.c,v 1.10 2004/01/14 21:59:23 drh Exp $
+** $Id: encode.c,v 1.11 2004/03/14 22:12:00 drh Exp $
 */
 #include <string.h>
+#include <assert.h>
 
 /*
 ** How This Encoder Works
 **
 ** The return value is the number of characters in the encoded
 ** string, excluding the "\000" terminator.
+**
+** If out==NULL then no output is generated but the routine still returns
+** the number of characters that would have been generated if out had
+** not been NULL.
 */
 int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out){
   int i, j, e, m;
   int cnt[256];
   if( n<=0 ){
-    out[0] = 'x';
-    out[1] = 0;
+    if( out ){
+      out[0] = 'x';
+      out[1] = 0;
+    }
     return 1;
   }
   memset(cnt, 0, sizeof(cnt));
@@ -136,16 +143,16 @@ int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out){
       if( m==0 ) break;
     }
   }
+  if( out==0 ){
+    return n+m+1;
+  }
   out[0] = e;
   j = 1;
   for(i=0; i<n; i++){
     int c = (in[i] - e)&0xff;
-    if( c==0 ){
-      out[j++] = 1;
+    if( c==0 || c==1 ){
       out[j++] = 1;
-    }else if( c==1 ){
-      out[j++] = 1;
-      out[j++] = 2;
+      out[j++] = c+1;
     }else if( c=='\'' ){
       out[j++] = 1;
       out[j++] = 3;
@@ -154,6 +161,7 @@ int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out){
     }
   }
   out[j] = 0;
+  assert( j==n+m+1 );
   return j;
 }
 
@@ -174,10 +182,8 @@ int sqlite_decode_binary(const unsigned char *in, unsigned char *out){
   while( (c = *(in++))!=0 ){
     if( c==1 ){
       c = *(in++);
-      if( c==1 ){
-        c = 0;
-      }else if( c==2 ){
-        c = 1;
+      if( c==1 || c==2 ){
+        c--;
       }else if( c==3 ){
         c = '\'';
       }else{
@@ -197,11 +203,11 @@ int sqlite_decode_binary(const unsigned char *in, unsigned char *out){
 ** and run the result.
 */
 int main(int argc, char **argv){
-  int i, j, n, m, nOut, nByte;
+  int i, j, n, m, nOut, nByteIn, nByteOut;
   unsigned char in[30000];
   unsigned char out[33000];
 
-  nByte = 0;
+  nByteIn = nByteOut = 0;
   for(i=0; i<sizeof(in); i++){
     printf("Test %d: ", i+1);
     n = rand() % (i+1);
@@ -215,12 +221,17 @@ int main(int argc, char **argv){
     }else{
       for(j=0; j<n; j++) in[j] = rand() & 0xff;
     }
-    nByte += n;
+    nByteIn += n;
     nOut = sqlite_encode_binary(in, n, out);
+    nByteOut += nOut;
     if( nOut!=strlen(out) ){
       printf(" ERROR return value is %d instead of %d\n", nOut, strlen(out));
       exit(1);
     }
+    if( nOut!=sqlite_encode_binary(in, n, 0) ){
+      printf(" ERROR actual output size disagrees with predicted size\n");
+      exit(1);
+    }
     m = (256*n + 1262)/253;
     printf("size %d->%d (max %d)", n, strlen(out)+1, m);
     if( strlen(out)+1>m ){
@@ -244,6 +255,9 @@ int main(int argc, char **argv){
     }
     printf(" OK\n");
   }
-  fprintf(stderr, "Finished.  Total encoding: %d bytes\n", nByte);
+  fprintf(stderr,"Finished.  Total encoding: %d->%d bytes\n",
+          nByteIn, nByteOut);
+  fprintf(stderr,"Avg size increase: %.3f%%\n",
+    (nByteOut-nByteIn)*100.0/(double)nByteIn);
 }
 #endif /* ENCODER_TEST */