-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add presets for LZ4 1.9.3 (pull #1094)
- Loading branch information
1 parent
7fdc4e3
commit a70841e
Showing
26 changed files
with
2,247 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: lz4 | ||
on: | ||
push: | ||
paths: | ||
- lz4/** | ||
pull_request: | ||
paths: | ||
- lz4/** | ||
workflow_dispatch: | ||
env: | ||
CI_DEPLOY_MODULE: ${{ github.workflow }} | ||
CI_DEPLOY_PLATFORM: ${{ github.job }} | ||
CI_DEPLOY_SETTINGS: ${{ secrets.CI_DEPLOY_SETTINGS }} | ||
CI_DEPLOY_USERNAME: ${{ secrets.CI_DEPLOY_USERNAME }} | ||
CI_DEPLOY_PASSWORD: ${{ secrets.CI_DEPLOY_PASSWORD }} | ||
STAGING_REPOSITORY: ${{ secrets.STAGING_REPOSITORY }} | ||
jobs: | ||
linux-x86: | ||
runs-on: ubuntu-18.04 | ||
container: centos:7 | ||
steps: | ||
- uses: bytedeco/javacpp-presets/.github/actions/deploy-centos@actions | ||
linux-x86_64: | ||
runs-on: ubuntu-18.04 | ||
container: centos:7 | ||
steps: | ||
- uses: bytedeco/javacpp-presets/.github/actions/deploy-centos@actions | ||
macosx-x86_64: | ||
runs-on: macos-10.15 | ||
steps: | ||
- uses: bytedeco/javacpp-presets/.github/actions/deploy-macosx@actions | ||
windows-x86: | ||
runs-on: windows-2019 | ||
steps: | ||
- uses: bytedeco/javacpp-presets/.github/actions/deploy-windows@actions | ||
windows-x86_64: | ||
runs-on: windows-2019 | ||
steps: | ||
- uses: bytedeco/javacpp-presets/.github/actions/deploy-windows@actions | ||
redeploy: | ||
needs: [linux-x86, linux-x86_64, macosx-x86_64, windows-x86, windows-x86_64] | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- uses: bytedeco/javacpp-presets/.github/actions/redeploy@actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
LZ4 Library | ||
Copyright (c) 2011-2020, Yann Collet | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, this | ||
list of conditions and the following disclaimer in the documentation and/or | ||
other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
JavaCPP Presets for LZ4 | ||
======================= | ||
|
||
[](https://gitter.im/bytedeco/javacpp) [](https://maven-badges.herokuapp.com/maven-central/org.bytedeco/lz4) [](http://bytedeco.org/builds/) | ||
<sup>Build status for all platforms:</sup> [](https://github.com/bytedeco/javacpp-presets/actions?query=workflow%3Alz4) <sup>Commercial support:</sup> [](https://xscode.com/bytedeco/javacpp-presets) | ||
|
||
|
||
Introduction | ||
------------ | ||
This directory contains the JavaCPP Presets module for: | ||
|
||
* LZ4 1.9.3 https://github.com/lz4/lz4/ | ||
|
||
Please refer to the parent README.md file for more detailed information about the JavaCPP Presets. | ||
|
||
|
||
Documentation | ||
------------- | ||
Java API documentation is available here: | ||
|
||
* http://bytedeco.org/javacpp-presets/lz4/apidocs/ | ||
|
||
|
||
Sample Usage | ||
------------ | ||
Here is a simple example of LZ4 frame compression. | ||
|
||
We can use [Maven 3](http://maven.apache.org/) to download and install automatically all the class files as well as the native binaries. To run this sample code, after creating the `pom.xml` and `LZ4FrameCompressionExample.java` source files below, simply execute on the command line: | ||
```bash | ||
$ mvn compile exec:java | ||
``` | ||
|
||
### The `pom.xml` build file | ||
```xml | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.bytedeco.lz4</groupId> | ||
<artifactId>lz4-frame-compression-example</artifactId> | ||
<version>1.5.7-SNAPSHOT</version> | ||
<properties> | ||
<exec.mainClass>LZ4FrameCompressionExample</exec.mainClass> | ||
<maven.compiler.source>1.7</maven.compiler.source> | ||
<maven.compiler.target>1.7</maven.compiler.target> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.bytedeco</groupId> | ||
<artifactId>lz4-platform</artifactId> | ||
<version>1.9.3-1.5.7-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<sourceDirectory>.</sourceDirectory> | ||
</build> | ||
</project> | ||
``` | ||
|
||
### The `LZ4FrameCompressionExample.java` source file | ||
```java | ||
import java.nio.ByteBuffer; | ||
import org.bytedeco.javacpp.*; | ||
import org.bytedeco.lz4.*; | ||
import org.bytedeco.lz4.global.lz4; | ||
|
||
public final class LZ4FrameCompressionExample { | ||
|
||
private static final int NUM_VALUES = 10 * 1024 * 1024; // 10MB | ||
|
||
public static void main(String[] args) throws LZ4Exception { | ||
// Print LZ4 version | ||
System.out.println("LZ4 Version: " + lz4.LZ4_VERSION_STRING.getString()); | ||
|
||
// Generate some data | ||
final ByteBuffer data = ByteBuffer.allocateDirect(NUM_VALUES); | ||
for (int i = 0; i < NUM_VALUES; i++) { | ||
data.put((byte) i); | ||
} | ||
data.position(0); | ||
|
||
// Compress | ||
final ByteBuffer compressed = compress(data); | ||
System.out.println("Uncompressed size: " + data.limit()); | ||
System.out.println("Compressed size: " + compressed.limit()); | ||
|
||
// Decompress | ||
final ByteBuffer decompressed = decompress(compressed, data.limit()); | ||
|
||
// Verify that decompressed == data | ||
for (int i = 0; i < NUM_VALUES; i++) { | ||
if (data.get(i) != decompressed.get(i)) { | ||
throw new IllegalStateException("Input and output differ."); | ||
} | ||
} | ||
System.out.println("Verified that input data == output data"); | ||
} | ||
|
||
private static ByteBuffer compress(ByteBuffer data) { | ||
// Output buffer | ||
final int maxCompressedSize = (int) lz4.LZ4F_compressFrameBound(data.limit(), null); | ||
final ByteBuffer compressed = ByteBuffer.allocateDirect(maxCompressedSize); | ||
|
||
final Pointer dataPointer = new Pointer(data); | ||
final Pointer dstPointer = new Pointer(compressed); | ||
final long compressedSize = lz4.LZ4F_compressFrame(dstPointer, compressed.limit(), dataPointer, data.limit(), | ||
null); | ||
compressed.limit((int) compressedSize); | ||
return compressed; | ||
} | ||
|
||
private static ByteBuffer decompress(ByteBuffer compressed, int uncompressedSize) throws LZ4Exception { | ||
final LZ4FDecompressionContext dctx = new LZ4FDecompressionContext(); | ||
final long ctxError = lz4.LZ4F_createDecompressionContext(dctx, lz4.LZ4F_VERSION); | ||
checkForError(ctxError); | ||
|
||
// Output buffer | ||
final ByteBuffer decompressed = ByteBuffer.allocateDirect(uncompressedSize); | ||
|
||
final SizeTPointer dstSize = new SizeTPointer(1); | ||
final SizeTPointer srcSize = new SizeTPointer(1); | ||
|
||
try { | ||
long ret; | ||
do { | ||
dstSize.put(decompressed.remaining()); | ||
srcSize.put(compressed.limit()); | ||
final Pointer dstPointer = new Pointer(decompressed); | ||
final Pointer compressedPointer = new Pointer(compressed); | ||
|
||
ret = lz4.LZ4F_decompress(dctx, dstPointer, dstSize, compressedPointer, srcSize, null); | ||
checkForError(ret); | ||
decompressed.position(decompressed.position() + (int) dstSize.get()); | ||
compressed.position(compressed.position() + (int) srcSize.get()); | ||
} while (ret != 0); | ||
|
||
} finally { | ||
lz4.LZ4F_freeDecompressionContext(dctx); | ||
} | ||
|
||
decompressed.position(0); | ||
return decompressed; | ||
} | ||
|
||
private static void checkForError(long errorCode) throws LZ4Exception { | ||
if (lz4.LZ4F_isError(errorCode) != 0) { | ||
throw new LZ4Exception(lz4.LZ4F_getErrorName(errorCode).getString()); | ||
} | ||
} | ||
|
||
private static final class LZ4Exception extends Exception { | ||
public LZ4Exception(final String message) { | ||
super(message); | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
# This file is meant to be included by the parent cppbuild.sh script | ||
if [[ -z "$PLATFORM" ]]; then | ||
pushd .. | ||
bash cppbuild.sh "$@" lz4 | ||
popd | ||
exit | ||
fi | ||
|
||
LZ4_VERSION=1.9.3 | ||
download https://github.com/lz4/lz4/archive/refs/tags/v$LZ4_VERSION.tar.gz lz4-$LZ4_VERSION.tar.gz | ||
mkdir -p $PLATFORM | ||
cd $PLATFORM | ||
INSTALL_PATH=`pwd` | ||
tar -xzvf ../lz4-$LZ4_VERSION.tar.gz | ||
cd lz4-$LZ4_VERSION | ||
|
||
# TODO add other platforms | ||
case $PLATFORM in | ||
linux-x86) | ||
CC="gcc -m32 -fPIC" make -j $MAKEJ | ||
PREFIX=$INSTALL_PATH make install | ||
;; | ||
linux-x86_64) | ||
CC="gcc -m64 -fPIC" make -j $MAKEJ | ||
PREFIX=$INSTALL_PATH make install | ||
;; | ||
macosx-x86_64) | ||
make -j $MAKEJ | ||
PREFIX=$INSTALL_PATH make install | ||
;; | ||
windows-x86) | ||
cd build/cmake | ||
export CC="cl.exe" | ||
export CXX="cl.exe" | ||
"$CMAKE" -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH -DBUILD_SHARED_LIBS=OFF . | ||
ninja -j $MAKEJ | ||
ninja install | ||
cd ../.. | ||
;; | ||
windows-x86_64) | ||
cd build/cmake | ||
export CC="cl.exe" | ||
export CXX="cl.exe" | ||
"$CMAKE" -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH -DBUILD_SHARED_LIBS=OFF . | ||
ninja -j $MAKEJ | ||
ninja install | ||
cd ../.. | ||
;; | ||
*) | ||
echo "Error: Platform \"$PLATFORM\" is not supported" | ||
;; | ||
esac | ||
|
||
cd ../.. |
Oops, something went wrong.