Example #1
1
// lzo 算法
static void lzo(pbuf_t *pbuf)
{
    uint8_t wrkmem[LZO1X_1_MEM_COMPRESS];
    uint8_t out[2048+2048/16+64+3];
    lzo_uint olen;
    lzo1x_1_compress(pbuf->payload, pbuf->len, out, &olen, wrkmem);
    if (olen < pbuf->len)
    {
        memcpy(pbuf->payload, out, olen);
        pbuf->flag |= 0x04;
        pbuf->len = olen;
    }
}
Example #2
1
static void lzo_compress_chunk(void *fptr)
{
    int r;
    struct lzo_data *ld = fptr;

    r = lzo1x_1_compress(ld->in, ld->in_len, ld->out, &ld->out_len, ld->wrkmem);
    if (r != LZO_E_OK)
	bail("LZF internal compression error: %d", r);

    ld->bytesout += ld->out_len;

    ld->in_len = 0;
}
Example #3
0
int KScriptClient::Call(Lua_State* L)
{
    int         nRetCode        = 0;
    int         nParamCount     = 0;
    const char* pszFunction     = NULL;
    BYTE*       pbyOffset       = m_byOriginalBuffer;
    BYTE*       pbyTail         = m_byOriginalBuffer + sizeof(m_byOriginalBuffer);
    size_t      uSrcLen         = 0;
    size_t      uDstLen         = 0;

	nParamCount = Lua_GetTopIndex(L);
	KGLOG_PROCESS_ERROR(nParamCount >= 1);

	pszFunction = Lua_ValueToString(L, 1);
	KGLOG_PROCESS_ERROR(pszFunction);

    for (int i = 2; i <= nParamCount; i++)
    {
        pbyOffset = LuaPackup(L, i, pbyOffset, (size_t)(pbyTail - pbyOffset));
        KGLOG_PROCESS_ERROR(pbyOffset);
    }

    uSrcLen = (size_t)(pbyOffset - m_byOriginalBuffer);

    nRetCode = lzo1x_1_compress(m_byOriginalBuffer, (lzo_uint)uSrcLen, m_byCompressBuffer, (lzo_uint*)&uDstLen, m_LzoWorkBuffer);
    KGLOG_PROCESS_ERROR(nRetCode == LZO_E_OK);

    g_PlayerClient.DoRemoteLuaCall(pszFunction, m_byCompressBuffer, uDstLen);

Exit0:
    return 0;
}
Example #4
0
static int algo_lzo_compress(const unsigned char *in, size_t in_size,
                    unsigned char *out, size_t *out_size,
                    void *data) {
    int ret;
    ret = lzo1x_1_compress(in, in_size, out, out_size, data);
    return ret == LZO_E_OK ? 0 : ret;
}
Example #5
0
static bool compress_with_lzo(JCR *jcr,
                              char *rbuf,
                              uint32_t rsize,
                              unsigned char *cbuf,
                              uint32_t max_compress_len,
                              uint32_t *compress_len)
{
   int lzores;
   lzo_uint len = 0;

   Dmsg3(400, "cbuf=0x%x rbuf=0x%x len=%u\n", cbuf, rbuf, rsize);

   lzores = lzo1x_1_compress((const unsigned char *)rbuf, rsize,
                             cbuf, &len, jcr->compress.workset.pLZO);
   *compress_len = len;

   if (lzores != LZO_E_OK || *compress_len > max_compress_len) {
      /*
       * This should NEVER happen
       */
      Jmsg(jcr, M_FATAL, 0, _("Compression LZO error: %d\n"), lzores);
      jcr->setJobStatus(JS_ErrorTerminated);
      return false;
   }

   Dmsg2(400, "LZO compressed len=%d uncompressed len=%d\n", *compress_len, rsize);

   return true;
}
JNIEXPORT jint JNICALL Java_com_dynatrace_diagnostics_sdk_io_LZOCompression_dynMemCompress
(JNIEnv *env, jclass, jbyteArray src, jint offset, jint srcLen, jbyteArray dest){

	lzo_uint destLen=0;
	jbyte *srcBuf = (jbyte*)malloc(srcLen*sizeof(jbyte));
	if (srcBuf==NULL) return -1;

	env->GetByteArrayRegion(src, offset, srcLen, srcBuf);
	if (env->ExceptionOccurred()) {
		return -1;
	}	

	int maxDestLen = srcLen + srcLen / 16 + 64 +3;
	jbyte *destBuf = (jbyte*)malloc(maxDestLen*sizeof(jbyte));
	if (destBuf==NULL) return -1;

	int result = lzo1x_1_compress((unsigned char*)srcBuf,srcLen, (unsigned char*)destBuf, &destLen, wrkmem);
	if (result!=LZO_E_OK)  {
		free(srcBuf);
		free(destBuf);
		return -1;
	}

	env->SetByteArrayRegion(dest, 0, (jsize)destLen, destBuf);	
	if (env->ExceptionOccurred()) {
		return -1;
	}

	free(srcBuf);
	free(destBuf);
	return (jsize)destLen;
}
Example #7
0
rt_private void parsing_compiler_write(size_t size)
{
	RT_GET_CONTEXT
	char* cmps_out_ptr = cmps_general_buffer;
	lzo_uint cmps_out_size = (lzo_uint) cmp_buffer_size;
	int signed_cmps_out_size;
	int number_written;

	REQUIRE("cmp_buffer_size not too big", cmp_buffer_size <= 0x7FFFFFFF);
	REQUIRE("size not too big", size <= 0x7FFFFFFF);
	
	lzo1x_1_compress (
					(unsigned char *) general_buffer,		/* Current buffer location */
					(lzo_uint) size,	/* Current buffer size */
					(unsigned char *) cmps_out_ptr,		/* Output buffer for compressed data */
					&cmps_out_size,		/* Size of output buffer and then size of compressed data */
					wrkmem);			/* Memory allocator */

	signed_cmps_out_size = (int) cmps_out_size;

		/* Write size of compressed data */
	if (write (file_descriptor, (char *) &signed_cmps_out_size, sizeof(int)) <= 0)
		eraise ("Unable to write compressed data size", EN_IO);

		/* Write compressed data */
	while (signed_cmps_out_size > 0) {
		number_written = write (file_descriptor, cmps_out_ptr, signed_cmps_out_size);
		if (number_written <= 0)
			eio();
		signed_cmps_out_size -= number_written;
		cmps_out_ptr += number_written;
	}
}
Example #8
0
int main(int argc, char *argv[]) {
    FILE *f = fopen(argv[1], "rb");
    if (!f) {
        return 0;
    }

    fseek(f, 0, SEEK_END);
    long file_size = ftell(f);
    fseek(f, 0, SEEK_SET);

    if (file_size >= 0x100000000)
        file_size = 0xFFFFFFFF;

    void* inpbuffer = malloc((size_t) file_size);
    void* outbuffer = malloc((size_t) file_size);

    fread(inpbuffer, 1, (size_t) file_size, f);

    lzo_uint compressed_size = file_size;

    void* wrkmem = malloc(((LZO1X_1_MEM_COMPRESS) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t));

    gettimeofday(&time_start, NULL);
    lzo1x_1_compress(inpbuffer, (unsigned int) file_size, outbuffer, &compressed_size, wrkmem);
    gettimeofday(&time_end, NULL);

    printf("Duration: %lu\n", ((time_end.tv_sec * 1000) + (time_end.tv_usec / 1000)) - ((time_start.tv_sec * 1000) + (time_start.tv_usec / 1000)));
    printf("Original: %lu\n",file_size);
    printf("Compressed: %lu\n",compressed_size);
}
Example #9
0
File: lzo.cpp Project: anqin/toft
bool LzoCompression::DoCompress(const char* str, size_t length, std::string* out) {
    size_t outsize = (length + length / 16 + 64 + 3);
    if (c_buff_size_ < outsize) {
        delete [] compressed_buff_;
        c_buff_size_ *= 2;
        compressed_buff_ = new unsigned char[c_buff_size_];
        VLOG(28) << "malloc larger space :" << c_buff_size_;
        CHECK(compressed_buff_) << "fail to new space";
    }

    lzo_uint out_len = c_buff_size_;
    int r = lzo1x_1_compress(reinterpret_cast<const unsigned char*>(str), length,
                             compressed_buff_,
                             &out_len, wrkmem_);

    if (r == LZO_E_OK) {
        VLOG(28) << "compressed  " << length << "  bytes into  " << out_len << " bytes";
    } else {
        LOG(ERROR)<< "internal error - compression failed";
        return false;
    }

    out->assign(reinterpret_cast<const char*>(compressed_buff_), out_len);
    return true;
}
Example #10
0
rt_private void parsing_store_write(size_t size)
{
	RT_GET_CONTEXT
	char* cmps_out_ptr = cmps_general_buffer;
	lzo_uint cmps_out_size = (lzo_uint) cmp_buffer_size;
	int signed_cmps_out_size;
	
	REQUIRE("cmp_buffer_size not too big", cmp_buffer_size <= 0x7FFFFFFF);
	REQUIRE("size not too big", size <= 0x7FFFFFFF);

	lzo1x_1_compress (
					(unsigned char *) general_buffer,		/* Current buffer location */
					(lzo_uint) size,	/* Current buffer size */
					(unsigned char *) cmps_out_ptr,		/* Output buffer for compressed data */
					&cmps_out_size,		/* Size of output buffer and then size of compressed data */
					wrkmem);			/* Memory allocator */

	signed_cmps_out_size = (int) cmps_out_size;

		/* Write size of compressed data */
	if (parsing_char_write ((char *) &signed_cmps_out_size, sizeof(int)) <= 0)
		eraise ("Unable to write compressed data size", EN_IO);

		/* Write compressed data */
	if (parsing_char_write (cmps_out_ptr, signed_cmps_out_size) <= 0)
		eraise ("Unable to write on specified device", EN_IO);
}
Example #11
0
static length_t compress_packet(uint8_t *dest, const uint8_t *source, length_t len, int level) {
	if(level == 0) {
		memcpy(dest, source, len);
		return len;
	} else if(level == 10) {
#ifdef HAVE_LZO
		lzo_uint lzolen = MAXSIZE;
		lzo1x_1_compress(source, len, dest, &lzolen, lzo_wrkmem);
		return lzolen;
#else
		return -1;
#endif
	} else if(level < 10) {
#ifdef HAVE_ZLIB
		unsigned long destlen = MAXSIZE;
		if(compress2(dest, &destlen, source, len, level) == Z_OK)
			return destlen;
		else
#endif
			return -1;
	} else {
#ifdef HAVE_LZO
		lzo_uint lzolen = MAXSIZE;
		lzo1x_999_compress(source, len, dest, &lzolen, lzo_wrkmem);
		return lzolen;
#else
		return -1;
#endif
	}
	
	return -1;
}
Example #12
0
//
// MSG_CompressMinilzo
//
bool MSG_CompressMinilzo (buf_t &buf, size_t start_offset, size_t write_gap)
{
	if(buf.size() < MINILZO_COMPRESS_MINPACKETSIZE)
		return false;

	lzo_uint outlen = OUT_LEN(buf.maxsize() - start_offset - write_gap);
	size_t total_len = outlen + start_offset + write_gap;

	if(compressed.maxsize() < total_len)
		compressed.resize(total_len);

	int r = lzo1x_1_compress (buf.ptr() + start_offset,
							  buf.size() - start_offset,
							  compressed.ptr() + start_offset + write_gap,
							  &outlen,
							  wrkmem);

	// worth the effort?
	if(r != LZO_E_OK || outlen >= (buf.size() - start_offset - write_gap))
		return false;

	memcpy(compressed.ptr(), buf.ptr(), start_offset);

	SZ_Clear(&buf);
	MSG_WriteChunk(&buf, compressed.ptr(), outlen + start_offset + write_gap);

	return true;
}
Example #13
0
File: stream.c Project: epa/lrzip
static void lzo_compress_buf(struct stream *s, int *c_type, i64 *c_len)
{
	uchar *c_buf;
	lzo_bytep wrkmem;
	lzo_uint in_len = s->buflen;
	lzo_uint dlen = in_len + in_len / 16 + 64 + 3;
	lzo_int return_var;	/* lzo1x_1_compress does not return anything but LZO_OK */

	wrkmem = (lzo_bytep) malloc(LZO1X_1_MEM_COMPRESS);
	if (wrkmem == NULL)
		return;

	c_buf = malloc(dlen);
	if (!c_buf)
		goto out_free;

	return_var = lzo1x_1_compress((uchar *)s->buf, in_len, (uchar *)c_buf,
				      &dlen,wrkmem);

	if (dlen >= in_len){
		/* Incompressible, leave as CTYPE_NONE */
		free(c_buf);
		goto out_free;
	}

	*c_len = dlen;
	free(s->buf);
	s->buf = c_buf;
	*c_type = CTYPE_LZO;
out_free:
	free(wrkmem);
}
Example #14
0
	void CompressBufferLZO( CMemData& bufOut,const char* szData,size_t stSize )
	{
		//计算保险长度的方法看testmini.c中的例子,这个文件是minilzo附带的
		lzo_uint uOutSize=lzo_uint(  stSize + stSize / 16 + 64 + 3 );

		const size_t stOrgOutSize = bufOut.Size();

		bufOut.ReSize( uOutSize + stOrgOutSize );
		
		if( LZO_E_OK != lzo1x_1_compress ( reinterpret_cast<const lzo_bytep>(szData), lzo_uint(stSize)
			, bufOut.AsPtr<lzo_byte>( stOrgOutSize ),&uOutSize,CLzoWorkBuffer::ms_Inst.GetBuffer() ) )
		{
			GenErr("lzo compress failed!");
		}

		bufOut.ReSize( uOutSize + stOrgOutSize );


		//CMemData test(bufOut);
		//test.ReSize(stSize);
		//DecompressBufferLZO(test.Data(),stSize,bufOut.AsPtr<const char>(4),bufOut.Size()-4);

		//printf("%d %d %0.2f\n",int(bufOut.Size()),int(stSize),bufOut.Size()/(float)stSize );

		//FILE* fp=fopen("compress.txt","a");
		//fwrite( &bufOut[ stOrgOutSize ],1,bufOut.Size()-stOrgOutSize,fp);
		//fclose(fp);
	}
Example #15
0
int
bmz_lz_pack(const void *in, size_t in_len, void *out, size_t *out_len_p,
            void *work_mem) {
  lzo_uint olen = *out_len_p;
  int ret = lzo1x_1_compress((Byte *)in, in_len, (Byte *)out, &olen, work_mem);
  *out_len_p = olen;
  return ret;
}
Example #16
0
void
vncEncodeUltra::SendUltrarects(VSocket *outConn)
{
	int NRects=m_nNbRects;
	const lzo_uint rawDataSize = (m_Queuelen);

	if (NRects==0) return; // NO update
	if (m_nNbRects<3 && !must_be_zipped) 
	{
		outConn->SendExactQueue( (char *)m_Queuebuffer, m_Queuelen); // 1 Small update
		m_nNbRects=0;
		m_Queuelen=0;
		encodedSize += m_Queuelen-sz_rfbFramebufferUpdateRectHeader;
		rectangleOverhead += sz_rfbFramebufferUpdateRectHeader;
		return;
	}
	m_nNbRects=0;
	m_Queuelen=0;
	must_be_zipped=false;

	lzo1x_1_compress(m_Queuebuffer,rawDataSize,m_QueueCompressedbuffer,&out_len,wrkmem);

	if (out_len>rawDataSize)
				{
					outConn->SendExactQueue( (char *)m_Queuebuffer, m_Queuelen); // 1 Small update
					m_nNbRects=0;
					m_Queuelen=0;
					encodedSize += m_Queuelen-sz_rfbFramebufferUpdateRectHeader;
					rectangleOverhead += sz_rfbFramebufferUpdateRectHeader;
					return;
				}

	int rawDataSize1=rawDataSize/65535;
	int rawDataSize2=rawDataSize%65535;

	rfbFramebufferUpdateRectHeader CacheRectsHeader;
	CacheRectsHeader.r.x = (CARD16)(NRects);
	CacheRectsHeader.r.y = (CARD16)(rawDataSize2);
	CacheRectsHeader.r.w = (CARD16)(rawDataSize1);
	CacheRectsHeader.r.x = Swap16IfLE(CacheRectsHeader.r.x);
	CacheRectsHeader.r.y = Swap16IfLE(CacheRectsHeader.r.y);
	CacheRectsHeader.r.w = Swap16IfLE(CacheRectsHeader.r.w);
 	CacheRectsHeader.r.h = 0;
	CacheRectsHeader.encoding = Swap32IfLE(rfbEncodingUltraZip);

	// Format the UltraHeader
	rfbZlibHeader CacheZipHeader;
	CacheZipHeader.nBytes = Swap32IfLE(out_len);

	vnclog.Print(LL_INTINFO, VNCLOG("********QUEUEQUEUE********** %d %d %d\r\n"),out_len,rawDataSize,NRects);
	outConn->SendExactQueue((char *)&CacheRectsHeader, sizeof(CacheRectsHeader));
	outConn->SendExactQueue((char *)&CacheZipHeader, sizeof(CacheZipHeader));
	outConn->SendExactQueue((char *)m_QueueCompressedbuffer, out_len);
	// Update statistics
	encodedSize += sz_rfbZlibHeader + out_len;
	rectangleOverhead += sz_rfbFramebufferUpdateRectHeader;
	transmittedSize += out_len+sz_rfbFramebufferUpdateRectHeader+sz_rfbZlibHeader;
}
Example #17
0
/*
 * log_zip - compress(zip) log data into LOG_ZIP
 *   return: true on success, false on failure
 *   log_zip(in/out): LOG_ZIP structure allocated by log_zip_alloc
 *   length(in): length of given data
 *   data(in): log data to be compressed
 */
bool
log_zip (LOG_ZIP * log_zip, LOG_ZIP_SIZE_T length, const void *data)
{
  lzo_uint zip_len = 0;
  LOG_ZIP_SIZE_T buf_size;
  int rc;

  assert (length > 0 && data != NULL);
  assert (log_zip != NULL);

  log_zip->data_length = 0;

  buf_size = LOG_ZIP_BUF_SIZE (length);
  if (buf_size > log_zip->buf_size)
    {
      if (log_zip->log_data)
	{
	  free_and_init (log_zip->log_data);
	}

      log_zip->log_data = (unsigned char *) malloc (buf_size);
      if (log_zip->log_data == NULL)
	{
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY,
		  1, buf_size);
	}
      log_zip->buf_size = buf_size;
    }

  if (log_zip->log_data == NULL)
    {
      log_zip->data_length = 0;
      log_zip->buf_size = 0;
      return false;
    }

  /* save original data length */
  memcpy (log_zip->log_data, &length, sizeof (LOG_ZIP_SIZE_T));

  rc = lzo1x_1_compress ((lzo_bytep) data,
			 (lzo_uint) length,
			 log_zip->log_data + sizeof (LOG_ZIP_SIZE_T),
			 &zip_len, log_zip->wrkmem);
  if (rc == LZO_E_OK)
    {
      log_zip->data_length = zip_len + sizeof (LOG_ZIP_SIZE_T);
      /* if the compressed data length >= orginal length,
       * then it means that compression failed */
      if (log_zip->data_length < length)
	{
	  return true;
	}
    }
  return false;
}
Example #18
0
bool NetPlayServer::CompressBufferIntoPacket(const std::vector<u8>& in_buffer, sf::Packet& packet)
{
  const sf::Uint64 size = in_buffer.size();
  packet << size;

  if (size == 0)
    return true;

  std::vector<u8> out_buffer(NETPLAY_LZO_OUT_LEN);
  std::vector<u8> wrkmem(LZO1X_1_MEM_COMPRESS);

  lzo_uint i = 0;
  while (true)
  {
    lzo_uint32 cur_len = 0;  // number of bytes to read
    lzo_uint out_len = 0;    // number of bytes to write

    if ((i + NETPLAY_LZO_IN_LEN) >= size)
    {
      cur_len = static_cast<lzo_uint32>(size - i);
    }
    else
    {
      cur_len = NETPLAY_LZO_IN_LEN;
    }

    if (cur_len <= 0)
      break;  // end of buffer

    if (lzo1x_1_compress(&in_buffer[i], cur_len, out_buffer.data(), &out_len, wrkmem.data()) !=
        LZO_E_OK)
    {
      PanicAlertT("Internal LZO Error - compression failed");
      return false;
    }

    // The size of the data to write is 'out_len'
    packet << static_cast<u32>(out_len);
    for (size_t j = 0; j < out_len; j++)
    {
      packet << out_buffer[j];
    }

    if (cur_len != NETPLAY_LZO_IN_LEN)
      break;

    i += cur_len;
  }

  // Mark end of data
  packet << static_cast<u32>(0);

  return true;
}
Example #19
0
int lzo(char *srcfile, char *destfile)
{
	int result;
	int fd;
	struct stat s;
	lzo_bytep in;
	lzo_bytep out;
	lzo_uint in_len, out_len;

	rt_memset(&s, 0, sizeof(struct stat));
	stat(srcfile, &s);
	in_len = s.st_size; 
	
	in = rt_malloc(in_len); 
	if (in == RT_NULL) return -1;
	out = rt_malloc(LZO1X_WORST(in_len));
	if (out == RT_NULL)	return -1;

	fd = open(srcfile, O_RDONLY, 0);
	if(fd < 0) 
	{
		result = -1;
		goto _exit;
	}
	read(fd, in, in_len); 
	close(fd);

	result = lzo1x_1_compress(in, in_len, out, &out_len, wrkmem);
	if(result != LZO_E_OK)
	{
		rt_kprintf("internal error - compression failed: \nerr_code:(%d) %s, %s.\n", 
			result, parse_lzo_error_code(result), "Please use the binary access");
		goto _exit;
	}

	fd = open(destfile, O_WRONLY | O_BINARY | O_CREAT, 0);
	if(fd < 0)
	{
		result = -1;
		goto _exit;
	}
	
	write(fd, &in_len, sizeof(lzo_uint));	/* source file len */
	write(fd, out, out_len); 
	close(fd);
	rt_kprintf("compress lzo ok!\n");
	result = 0;

_exit:
	rt_free(in);
	rt_free(out);
	return result;
}
Example #20
0
static int compress_lzo(const void *in, void *out, size_t inlen, size_t outlen)
{
	int ret;

	ret = lzo1x_1_compress(in, inlen, out, &outlen, workspace);
	if (ret != LZO_E_OK) {
		pr_err("lzo_compress error, ret = %d!\n", ret);
		return -EIO;
	}

	return outlen;
}
Example #21
0
static int lzo_wwrite_block(const char *buffer, off_t len, struct buffer_t *outbuf)
{
	char b2[MAX_BUFFER_SIZE];
	int err;
	lzo_uint dst_len;
	char scratch[LZO1X_1_MEM_COMPRESS];

	outbuf->offset=0;

	memset(scratch,0,sizeof(scratch));
	err=lzo1x_1_compress((void*)buffer, len, 
			(void*)b2, &dst_len, 
			scratch);

	switch(err) {
		case LZO_E_OK:
			break;
		case LZO_E_ERROR:
			return -EINVAL; /* WTF? */
		case LZO_E_OUT_OF_MEMORY:
			return -ENOMEM; /* Uh oh */
		case LZO_E_NOT_COMPRESSIBLE:
			return -EINVAL; /* Claimed not to be used, dunno what we'll do */
		case LZO_E_INPUT_OVERRUN:
			return -EINVAL;  /* Can't happen on compress? */
		case LZO_E_OUTPUT_OVERRUN:
			return -ENOMEM;
		case LZO_E_LOOKBEHIND_OVERRUN:
			return -EINVAL;
		case LZO_E_EOF_NOT_FOUND:
			return -ENOENT; /* Can't happen on compress? */
		case LZO_E_INPUT_NOT_CONSUMED:
			return -EINVAL;
		case LZO_E_NOT_YET_IMPLEMENTED:
			return -ENOSYS;
		default:
			fprintf(stderr,"Unknown lzo error %d\n",err);
			return -EINVAL;
	}

	write32(outbuf, len); /* Original length */
	write32(outbuf, min((uint32_t)len,(uint32_t)dst_len));
	/* CRC32 of the uncompressed buffer */
#if 0
	write32(outbuf, lzo_crc32(CRC32_INIT_VALUE, (void*)buffer, len));
#endif
	write32(outbuf, 
		lzo_adler32(ADLER32_INIT_VALUE, (const void*)buffer, len));
	write_buf(outbuf, b2, dst_len);

	/* Return the number of bytes compressed */
	return len;
}
Example #22
0
void ts_comp(BYTE *flag, BYTE *pbuff, size_t *pbuff_len, BYTE *mid_buff, BYTE *lz4hc_wrkmem)
{	size_t mid_buff_size = 0;

	///if(lz4hc_compress( (const unsigned char *)pbuff, (*pbuff_len), (unsigned char *)mid_buff, &mid_buff_size, (void *)lz4hc_wrkmem)<0) return;
	if(lzo1x_1_compress( (const unsigned char *)pbuff, (*pbuff_len), (unsigned char *)mid_buff, &mid_buff_size, (void *)lz4hc_wrkmem)<0) return;
		
	if(((mid_buff_size+TS_FLAG_SIZE) < (*pbuff_len)) && (mid_buff_size!=0))
	{	memcpy((BYTE *)pbuff, (BYTE *)mid_buff, mid_buff_size); (*pbuff_len)=mid_buff_size; (*flag) |= TS_FLAG_COMP;
		#ifdef CONFIG_TRAFFICSQUEEZER_DEBUG
		printk("comp - prossd [LZ4-HC] [mid_buff_size: %zu] [flag: %d]\n", mid_buff_size, *flag);
		#endif
	}
}
Example #23
0
void lzowrite_wbuf(struct lzowrite_buffer* lzowrite_buffer) {
	lzo1x_1_compress(lzowrite_buffer->buffer, lzowrite_buffer->length, lzowrite_buffer->out_buffer, (lzo_uintp)&lzowrite_buffer->out_length, lzowrite_buffer->workmemory);

	//Write block header
	fwrite_int32_be(&lzowrite_buffer->length, lzowrite_buffer->output);
	fwrite_int32_be(&lzowrite_buffer->out_length, lzowrite_buffer->output);

	//Write content
	fwrite(lzowrite_buffer->out_buffer, sizeof(unsigned char), lzowrite_buffer->out_length, lzowrite_buffer->output);

	//Reset buffer
	lzowrite_buffer->length = 0;
}
Example #24
0
void SGuildMarkBlock::Compress(const Pixel * pxBuf)
{
	m_sizeCompBuf = MAX_COMP_SIZE;

	if (LZO_E_OK != lzo1x_1_compress((const BYTE *) pxBuf, sizeof(Pixel) * SGuildMarkBlock::SIZE, m_abCompBuf, &m_sizeCompBuf, CLZO::Instance().GetWorkMemory()))
	{
		sys_err("SGuildMarkBlock::Compress: Error! %u > %u", sizeof(Pixel) * SGuildMarkBlock::SIZE, m_sizeCompBuf);
		return;
	}

	//sys_log(0, "SGuildMarkBlock::Compress %u > %u", sizeof(Pixel) * SGuildMarkBlock::SIZE, m_sizeCompBuf);
	m_crc = GetCRC32((const char *) pxBuf, sizeof(Pixel) * SGuildMarkBlock::SIZE);
}
Example #25
0
void FLZOFile::Implode ()
{
	lzo_uint outlen = 0;
	unsigned int len = m_BufferSize;
	lzo_byte *compressed = NULL;
	lzo_byte *wrkmem;
	byte *oldbuf = m_Buffer;
	int r;

	if (!m_NoCompress)
	{
		compressed = new lzo_byte[OUT_LEN(len)];
		wrkmem = new lzo_byte[LZO1X_1_MEM_COMPRESS];
		r = lzo1x_1_compress (m_Buffer, len, compressed, &outlen, wrkmem);
		delete[] wrkmem;

		// If the data could not be compressed, store it as-is.
		if (r != LZO_E_OK || outlen > len)
		{
			DPrintf ("LZOFile could not be imploded\n");
			outlen = 0;
		}
		else
		{
			DPrintf ("LZOFile shrunk from %u to %u bytes\n", len, outlen);
		}
	}
	else
	{
		outlen = 0;
	}

	m_MaxBufferSize = m_BufferSize = ((outlen == 0) ? len : outlen);
	m_Buffer = (BYTE *)Malloc (m_BufferSize + 8);
	m_Pos = 0;

	DWORD *lens = (DWORD *)(m_Buffer);
	lens[0] = BELONG((unsigned int)outlen);
	lens[1] = BELONG(len);

	if (outlen == 0)
		memcpy (m_Buffer + 8, oldbuf, len);
	else
		memcpy (m_Buffer + 8, compressed, outlen);

	delete[] compressed;
    compressed = NULL;
    
	M_Free(oldbuf);
}
Example #26
0
File: lzo.c Project: 274914765/C
static int lzo_compress(struct crypto_tfm *tfm, const u8 *src,
                unsigned int slen, u8 *dst, unsigned int *dlen)
{
    struct lzo_ctx *ctx = crypto_tfm_ctx(tfm);
    size_t tmp_len = *dlen; /* size_t(ulong) <-> uint on 64 bit */
    int err;

    err = lzo1x_1_compress(src, slen, dst, &tmp_len, ctx->lzo_comp_mem);

    if (err != LZO_E_OK)
        return -EINVAL;

    *dlen = tmp_len;
    return 0;
}
Example #27
0
		bool Compress::ToLZO(	U8*		pSrcData,
								UInt	uiSrcSize,
								U8*		pDstData,
								U32*	uiDstSize){
				int r = lzo1x_1_compress(pSrcData,uiSrcSize,pDstData,uiDstSize,wrkmem);
				if (r == LZO_E_OK){
					if (*uiDstSize >= uiSrcSize){
						return false;
					}
				}else{
					return false;
				}
	
				return true;
		}
Example #28
0
BOOL KScriptServer::Call(int nConnIndex, const char cszFunction[])
{
    BOOL        bResult     = false;
    int         nRetCode    = 0;
    size_t      uOrgLen     = (size_t)(m_pbyPos - m_byOriginalBuffer);
    size_t      uCpsLen     = 0;

    nRetCode = lzo1x_1_compress(m_byOriginalBuffer, (lzo_uint)uOrgLen, m_byCompressBuffer, (lzo_uint*)&uCpsLen, m_LzoWorkBuffer);
    KGLOG_PROCESS_ERROR(nRetCode == LZO_E_OK);

    g_PlayerServer.DoRemoteLuaCall(nConnIndex, cszFunction, m_byCompressBuffer, uCpsLen);

    bResult = true;
Exit0:
    return bResult;
}
Example #29
0
int bufferEncrypt(char *buf, int size, char *target, int targetSize, char *key, int keySize)
{
	char tmp[LZO1X_MEM_COMPRESS];
	int ret;
	lzo_uint retSize=targetSize;
	xorEncode(buf, size, key, keySize);
	ret=lzo1x_1_compress((lzo_byte*)buf, size, (lzo_byte*)target, &retSize, tmp);
	if(ret==LZO_E_OK)
	{
		xorEncode2(target, retSize);
//		printf("Encrpt(%d->%d),key=%s(%d): %02X%02X...%02X%02X ->  %02X%02X...%02X%02X\n",size,retSize,key,keySize,
//				buf[0],buf[1],buf[size-2],buf[size-1], target[0], target[1], target[retSize-2], target[retSize-1]);
//		if(retSize<256) DumpData(target, retSize);
		return retSize;
	}
	return ret;
}
Example #30
0
void *_tc_recencode(const void *ptr, int size, int *sp, void *op){
  if(!_tc_lzo_init){
    if(lzo_init() != LZO_E_OK) return NULL;
    _tc_lzo_init = false;
  }
  lzo_bytep buf = MYMALLOC(size + (size >> 4) + 80);
  if(!buf) return NULL;
  lzo_uint bsiz;
  char wrkmem[LZO1X_1_MEM_COMPRESS];
  if(lzo1x_1_compress((lzo_bytep)ptr, size, buf, &bsiz, wrkmem) != LZO_E_OK){
    MYFREE(buf);
    return NULL;
  }
  buf[bsiz] = '\0';
  *sp = bsiz;
  return (char *)buf;
}