How to compress and decompress a string with LZO?

549 Views Asked by At

Trying to figure out what the proper way to plug in my data is. Any help? Doing it in the way seen here results in integer without a cast. I've tried this a few ways but never quite got the hand of it.

lzo_bytep SERV_DATA_SEND = "702D31FA78809907133F1256459ABFECA9769AEAB65F3F125658";

in_len = IN_LEN;
lzo_memset(in,SERV_DATA_SEND,strlen(SERV_DATA_SEND));
printf("memset: %s\n\n", in);
1

There are 1 best solutions below

1
Fatih Aktaş On BEST ANSWER

To prepare the data in a buffer, you should use lzo_memcpy(in, SERV_DATA_SEND, strlen(SERV_DATA_SEND)), which accepts chars in its second parameter.

pub unsafe extern "C" fn lzo_memcpy(
    dst: *mut c_void, 
    src: *const c_void, 
    len: lzo_uint
) -> *mut c_void

In lzo_memset(), the second parameter accepts an integer.

pub unsafe extern "C" fn lzo_memset(
    buf: *mut c_void, 
    c: c_int, 
    len: lzo_uint
) -> *mut c_void

For example, if you want to clear the buffer, you can use the code below. It will set all the blocks to zero.

lzo_memset(in,0,in_len);

Check out the overlap.c and simple.c example in http://www.oberhumer.com/opensource/lzo/#download