SOL9 Sample: QPEncDec

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * QPEncDec.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// 2008/10/10
// Sample program to use QPEncoder and QPDecoder class.

#include <sol\QPEncoder.h>
#include <sol\QPDecoder.h>


void dump(unsigned char* data, size_t len)
{
  for (size_t i = 0; i<len; i++) {
    if (i >0 && (i %16) == 0) {
      printf("\n");
    }

    printf("%02X ", data[i]); 
  }
  printf("\n");
}

/**
 *
 */
void _tmain(int argc, TCHAR** argv)
{
  unsigned char input[128];
  for (int i = 0; i<sizeof(input); i++) {
    input[i] = (i+1)*(i+2)*(i+3) % 128;  
  }  
  printf("Original bytes len=%d\n", sizeof(input));

  dump(input, sizeof(input));

  // 1 QPEncode
  Bytes byteArray(input, sizeof(input));
  String encString = _T("");

  QPEncoder encoder;
  encoder.encode(byteArray, encString);

  _tprintf(_T("Encoded=[%s]\n"), (const TCHAR*)encString);
  
  // 2 QPEncode
  char* enc = NULL;
  encoder.encode(input, sizeof(input), &enc);
  printf("Encoded2=[%s]\n", (const char*)enc);
  

  // 3 QPDecode
  unsigned char* dec = NULL;
  unsigned int   len = 0;

  QPDecoder decoder;

  decoder.decode(enc, &dec, &len);
  printf("Decoded declen=%d\n", len);    
  dump(dec, len);
  
  // 4 QPDecode 
  Bytes decByteArray;
  decoder.decode(enc, decByteArray);

  unsigned char* contents = decByteArray.getContents();
  int size = decByteArray.getSize();
  printf("Decoded2 declen=%d\n", size);

  dump(contents, size);

  delete [] enc;

  delete [] dec;
}

Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.