Interface ZstdDecompressor
- All Known Implementing Classes:
AbstractZstdDecompressor
@NullMarked
public interface ZstdDecompressor
A Zstandard streaming decompressor for Discord gateway messages.
Each message needs to be passed in the same order they were received, none must be skipped.
Each message needs to be passed in the same order they were received, none must be skipped.
Note: Instances are not thread safe, as there should be an instance per gateway connection, which uses 1 read thread.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default buffer size for decompression, 8 KBstatic final intThe minimum buffer size for decompression, 1 KBstatic final intThe "recommended" buffer size as defined byZSTD_DStreamOutSize()(128 KB as of v1.5.7). -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the decompressor and frees the associated resources.byte[]decompress(byte[] data) Decompresses the provided data.voidreset()Resets the decompressor, the next decompressed message must be the first message of the Zstd stream, meaning you will have to close your websocket connection and start a new one.
-
Field Details
-
ZSTD_RECOMMENDED_BUFFER_SIZE
static final int ZSTD_RECOMMENDED_BUFFER_SIZEThe "recommended" buffer size as defined byZSTD_DStreamOutSize()(128 KB as of v1.5.7). This isn't a default.For the use case of Discord's gateway, the value returned is overkill as it would mean at least 128 KB (Zstd's context has even more data) allocated for every shard, for this reason we recommend you to stick to the default buffer size, as it should be enough for most gateway messages without requiring multiple passes.
- See Also:
-
DEFAULT_BUFFER_SIZE
static final int DEFAULT_BUFFER_SIZEThe default buffer size for decompression, 8 KB- See Also:
-
MIN_BUFFER_SIZE
static final int MIN_BUFFER_SIZEThe minimum buffer size for decompression, 1 KB- See Also:
-
-
Method Details
-
reset
void reset()Resets the decompressor, the next decompressed message must be the first message of the Zstd stream, meaning you will have to close your websocket connection and start a new one.If this decompressor was in an errored state, calling this will render it usable again.
- Throws:
IllegalStateException- If this decompressor is closed
-
close
void close()Closes the decompressor and frees the associated resources.
A new decompressor needs be created for further operations.If this decompressor is already closed, this is a no-op.
-
decompress
byte[] decompress(byte[] data) Decompresses the provided data.Each Discord gateway message is a full websocket message, as such, you can pass the binary data from your websocket directly to this method, no buffering required.
- Throws:
IllegalArgumentException- If the passed data isnullIllegalStateException- If this decompressor is closed, or if the decompressor is an errored state and needs to be resetZstdException- If Zstd was unable to decompress the data for any reason, if this exception occurs, the decompressor will be in an errored state and will need to be reset
-