I'm who I am .

LoadRunner中,利用zlib.dll对字符串进行gzip压缩

上一篇 / 下一篇  2015-01-27 10:25:32 / 个人分类:LR

vuser_init()
{
    //加载C:\Windows\System32目录下面的dll。"zlib.dll"中含有gzip压缩的工具
    lr_load_dll("zlib.dll");
    return 0;
}

Action()
{

      /* 原始数据 */
  unsigned char strSrc[] = "我们是地球亚洲中国人"
                           "1234567890"
                          "1234567890"
                          "abcdefghij"
                        "1234567890";

  //压缩后的字符
  unsigned char buf[1024] = {0};
  //目标数据
  unsigned char strDst[1024] = {0};
  //数据的长度
  unsigned long srcLen = sizeof(strSrc);//中文算2个字节
  unsigned long bufLen = sizeof(buf);
  unsigned long dstLen = sizeof(strDst);

  //压缩前log信息
  lr_log_message("====原来的字符串:%s\n", strSrc);
  lr_log_message("====压缩前的长度:%ld\n", srcLen);

  /* 压缩 */
  compress(buf, &bufLen, strSrc, srcLen);

  //压缩后log信息
  lr_log_message("====压缩后的字符:%s\n", buf);
  lr_log_message("====压缩后长度:%ld\n", bufLen);




  /* 解压缩 */
  uncompress(strDst, &dstLen, buf, bufLen);
  //压缩后的log信息
  lr_log_message("====原来的字符串:%ld\n",dstLen);
  lr_log_message("====原来的字符串长度:%s\n",strDst);

    return 0;
}
/*脚本使用
1、参考资料: zlib的安装与使用  http://blog.csdn.net/htttw/article/details/7616124  
调用外部dll  http://www.cnblogs.com/coderzh/archive/2008/04/02/1135118.html
2、在网上下载zlib.dll
3、查看zlib.dll是否是想要的,可以用反编译工具Depends Walker ,看看dll里面的函数中,是否含有compress和uncompress,如果有,说明是想要的dll了。
4、把zlib.dll复制到C:\Windows\System32
5、在LR中新建一个脚本,并在vuser_init块中输入lr_load_dll("zlib.dll");
6、在Action()中使用compress和uncompress函数,对字符进行压缩和解压缩。
*/

    /*
     * 我们用到了两个函数:compress和uncompress:
     *
     * 压缩:
     *
     * int compress(unsigned char * dest, unsigned long * destLen, unsigned char * source, unsigned long sourceLen);
     *
     * dest:压缩后数据保存的目标缓冲区
     *
     * destLen:目标缓冲区的大小(必须在调用前设置,并且它是一个指针)
     *
     * source:要压缩的数据
     *
     * sourceLen:要压缩的数据长度
     *
     * compress()函数成功返回Z_OK,如果内存不够,返回Z_MEM_ERROR,如果目标缓冲区太小,返回Z_BUF_ERROR
     *
     *
     * 解压缩:
     *
     * int uncompress(unsigned char * dest,  unsigned long * destLen, unsigned char * source, unsigned long sourceLen);
     *
     * dest:解压后数据保存的目标缓冲区
     *
     * destLen:目标缓冲区的大小(必须在调用前设置,并且它是一个指针)
     *
     * source:要解压的数据
     *
     * sourceLen:要解压的数据长度
     *
     * uncompress()函数成功返回Z_OK,如果内存不够,返回Z_MEM_ERROR,如果目标缓冲区太小,返回Z_BUF_ERROR,如果要解压的数据损坏或不完整,返回Z_DATA_ERROR。
     */



TAG:

 

评分:0

我来说两句

日历

« 2024-04-11  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 54103
  • 日志数: 51
  • 建立时间: 2015-01-04
  • 更新时间: 2015-05-27

RSS订阅

Open Toolbar