Functions | Variables

CppSQLite3.cpp File Reference

#include "CppSQLite3.h"
#include <cstdlib>
Include dependency graph for CppSQLite3.cpp:

Go to the source code of this file.

Functions

int sqlite3_encode_binary (const unsigned char *in, int n, unsigned char *out)
int sqlite3_decode_binary (const unsigned char *in, unsigned char *out)

Variables

static const bool DONT_DELETE_MSG = false

Function Documentation

int sqlite3_decode_binary ( const unsigned char *  in,
unsigned char *  out 
)

Definition at line 2959 of file CppSQLite3.cpp.

Referenced by CppSQLite3Binary::getBinary().

                                                                      {

  int i, c, e;

  e = *(in++);

  i = 0;

  while( (c = *(in++))!=0 ){

    if( c==1 ){

      c = *(in++);

      if( c==1 ){

        c = 0;

      }else if( c==2 ){

        c = 1;

      }else if( c==3 ){

        c = '\'';

      }else{

        return -1;

      }

    }

    out[i++] = (c + e)&0xff;

  }

  return i;

}

Here is the caller graph for this function:

int sqlite3_encode_binary ( const unsigned char *  in,
int  n,
unsigned char *  out 
)

Definition at line 2855 of file CppSQLite3.cpp.

Referenced by CppSQLite3Binary::getEncoded().

                                                                             {

  int i, j, e, m;

  int cnt[256];

  if( n<=0 ){

    out[0] = 'x';

    out[1] = 0;

    return 1;

  }

  memset(cnt, 0, sizeof(cnt));

  for(i=n-1; i>=0; i--){ cnt[in[i]]++; }

  m = n;

  for(i=1; i<256; i++){

    int sum;

    if( i=='\'' ) continue;

    sum = cnt[i] + cnt[(i+1)&0xff] + cnt[(i+'\'')&0xff];

    if( sum<m ){

      m = sum;

      e = i;

      if( m==0 ) break;

    }

  }

  out[0] = e;

  j = 1;

  for(i=0; i<n; i++){

    int c = (in[i] - e)&0xff;

    if( c==0 ){

      out[j++] = 1;

      out[j++] = 1;

    }else if( c==1 ){

      out[j++] = 1;

      out[j++] = 2;

    }else if( c=='\'' ){

      out[j++] = 1;

      out[j++] = 3;

    }else{

      out[j++] = c;

    }

  }

  out[j] = 0;

  return j;

}

Here is the caller graph for this function:


Variable Documentation

const bool DONT_DELETE_MSG = false [static]