Interoperability issue with other l4z libraries
raffi-semerciyan opened this issue · 1 comments
raffi-semerciyan commented
I'm using two github versions of lz4: yours for java and github.com/bkaradzic/go-lz4 for Golang.
I used Golang version in the code below:
package main
import (
lz4 "github.com/bkaradzic/go-lz4"
"fmt"
"os"
"encoding/base64"
)
func main() {
var data []byte
var err error
to_compress:="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
if data,err=lz4.Encode(nil,[]byte(to_compress)); err!=nil {
fmt.Fprintf(os.Stderr,"Failed to compress: '%s'",err)
return
}
fmt.Fprintf(os.Stderr,"Success! Length=%d\n",len(to_compress))
fmt.Fprintf(os.Stdout,"%s\n",base64.StdEncoding.EncodeToString(data))
}
and obtain following output:
raffi@iot-micro-raffi ~/tmp > go run ./test_lz4.go
Success! Length=100
ZAAAAB94AQBLUHh4eHh4
raffi@iot-micro-raffi ~/tmp >
Then I inject this output into a Java version below using your library to decode the result:
import java.util.Base64;
import net.jpountz.lz4.LZ4Factory;
import net.jpountz.lz4.LZ4FastDecompressor;
public class test_lz4_decomp {
public static void main(String[] args) {
String compressed_base64= "ZAAAAB94AQBLUHh4eHh4";
int original_size = 100;
byte [] compressed = Base64.getDecoder().decode(compressed_base64);
LZ4Factory _factory= LZ4Factory.fastestInstance();
LZ4FastDecompressor decompressor = _factory.fastDecompressor();
byte []restored = new byte[original_size];
decompressor.decompress(compressed, 0, restored, 0,original_size);
String decompressed_str=new String(restored);
System.out.println(decompressed_str);
}
}
but obtain the following output:
raffi@iot-micro-raffi ~/tmp > java -cp ".:lz4-1.3.0.jar" test_lz4_decompException in thread "main" net.jpountz.lz4.LZ4Exception: Error decoding offset 58 of input buffer
at net.jpountz.lz4.LZ4JNIFastDecompressor.decompress(LZ4JNIFastDecompressor.java:39)
at test_lz4_decomp.main(test_lz4_decomp.java:16)
raffi@iot-micro-raffi ~/tmp >
The expected result would be that the Java version should be able to decompress the output of the Golang version.
raffi-semerciyan commented
I used another Golang library (https://github.com/pwaller/go-clz4) and succeeded to make it work with your library.
So I believe the issue was in the golang library.
Thanks for your nice work!