// decompress
// [-------------------- LENGTH IN HEADER -----------------------]
// [-----------COMPRESSED LENGTH---------]
// received format = | compressed length + 4 (4B) | decompressed len (4B) | compressed bytes (bytes.length - 4) |
final LZ4Factory factory = lz4Factory.get();
int compressedLength = buffer.getInt() - 4;
int decompressedLength = buffer.getInt();
int compressedBytesOffset = buffer.arrayOffset() + buffer.position();
byte[] compressedBytes = buffer.array();
LZ4FastDecompressor decompressor = factory.fastDecompressor();
byte[] decompressedBytes = new byte[decompressedLength];
int compressedLength2 = decompressor.decompress(compressedBytes, compressedBytesOffset, decompressedBytes, 0, decompressedLength);
assert(compressedLength == compressedLength2);