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 as defined byZSTD_DStreamOutSize()(128 KB as of v1.5.7)static final intThe minimum buffer size for decompression, 8 KB -
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
-
DEFAULT_BUFFER_SIZE
static final int DEFAULT_BUFFER_SIZEThe default buffer size as defined byZSTD_DStreamOutSize()(128 KB as of v1.5.7)- See Also:
-
MIN_BUFFER_SIZE
static final int MIN_BUFFER_SIZEThe minimum buffer size for decompression, 8 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
-