Unity 2022.2.18 & 2022.2.19
Test code:
public unsafe class TestCompress : MonoBehaviour
{
private const string DllName = "liblz4";
[DllImport(DllName, EntryPoint = "LZ4_compressBound")]
private static extern int CompressBoundLZ4(int srcSize);
[DllImport(DllName, EntryPoint = "LZ4_compress_default")]
private static extern int CompressLZ4(byte* src, byte* dst, int srcSize, int dstCapacity);
[DllImport(DllName, EntryPoint = "LZ4_decompress_safe")]
private static extern int DecompressLZ4(byte* src, byte* dst, int compressedSize, int dstCapacity);
public void Awake()
{
var payload = new NativeArray<byte>(1234, Allocator.Temp);
for (var i = 0; i < payload.Length; i++)
{
payload[i] = (byte)(i % byte.MaxValue);
}
var boundedSize = CompressBoundLZ4(payload.Length);
var compressed = new NativeArray<byte>(boundedSize, Allocator.Temp);
var compressedSize = CompressLZ4((byte*)payload.GetUnsafePtr(), (byte*)compressed.GetUnsafePtr(), payload.Length, boundedSize);
var decompressed = new NativeArray<byte>(1234, Allocator.Temp);
var result = DecompressLZ4((byte*)compressed.GetUnsafePtr(), (byte*)decompressed.GetUnsafePtr(), compressedSize, decompressed.Length);
if (result > 0)
{
Debug.Log("Success");
}
else
{
Debug.LogError("Fail");
}
}
}```