Lightweight Zstandard decompression for the Java Discord API. (JDA)
This module is typically useful for sharded (large) bots, if you are interested in the performance difference, see here.
This is compatible with Java 8+.
dependencies {
implementation("dev.freya02:discord-zstd-java-jda-integration:VERSION") // TODO replace VERSION with current release
}<dependency>
<groupId>dev.freya02</groupId>
<artifactId>discord-zstd-java-jda-integration</artifactId>
<version>VERSION</version> <!-- TODO replace VERSION with current release -->
</dependency>Tip
To remove the warning when the natives are loaded, add --enable-native-access=ALL-UNNAMED to your JVM arguments.
JDA's gateway decompressor can be configured in GatewayConfig.Builder, in two ways:
useBufferedTransportDecompressionlets you use decompress payloads all at once, this is what JDA does by default.useStreamedTransportDecompressionlets you decompress payloads progressively, this means no memory allocations for decompression, but also prevents from printing corrupted payloads (though extremely rare)
If you choose to use buffered decompression, use ZstdBufferedTransportGatewayDecompressor, if you want to use streamed decompression, use ZstdStreamedTransportGatewayDecompressor.
For example:
void main(String[] args) {
DefaultShardManagerBuilder
.createDefault(args[0])
.setGatewayConfig(
GatewayConfig.builder()
.useStreamedTransportDecompression(ZstdStreamedTransportGatewayDecompressor.supplier())
.build())
.build();
}If you want to load a different version of the native library,
you can do so by calling ZstdNativesLoader.load(Path) or loadFromJar(String). These functions will return false if the natives were already loaded, as they can't be replaced.