Class PerMessageDeflateExtension
java.lang.Object
de.craftsblock.craftsnet.api.websocket.extensions.WebSocketExtension
de.craftsblock.craftsnet.api.websocket.extensions.builtin.PerMessageDeflateExtension
WebSocket extension that implements per-message deflate compression as described in
RFC 7692. This extension allows for
compressing and decompressing WebSocket frames.
- Since:
- 3.0.6-SNAPSHOT
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newPerMessageDeflateExtensionwith the protocol name "permessage-deflate". -
Method Summary
Modifier and TypeMethodDescription@NotNull FrameDecodes a WebSocket frame using per-message deflate decompression.@NotNull FrameEncodes a WebSocket frame using per-message deflate compression.static intGets the threshold for compression.static intGets the deflate flush mode.static intGets the deflate compression level.static intGets the deflate compression strategy.static intGets the maximum allowed data length for decompressed data.static voidsetCompressWhenHigher(int compressWhenHigher) Sets the threshold for compression.static voidsetDeflateFlush(int deflateFlush) Sets the deflate flush mode.static voidsetDeflateLevel(int deflateLevel) Sets the deflate compression level.static voidsetDeflateStrategy(int deflateStrategy) Sets the deflate compression strategy.static voidsetMaxDataLength(int maxDataLength) Sets the maximum allowed data length for decompressed data.Methods inherited from class de.craftsblock.craftsnet.api.websocket.extensions.WebSocketExtension
getProtocolName
-
Constructor Details
-
PerMessageDeflateExtension
public PerMessageDeflateExtension()Constructs a newPerMessageDeflateExtensionwith the protocol name "permessage-deflate".
-
-
Method Details
-
encode
Encodes a WebSocket frame using per-message deflate compression. Control frames are not compressed, and frames smaller than the specified threshold are not compressed.- Specified by:
encodein classWebSocketExtension- Parameters:
frame- the frame to be encoded. Must not be null.- Returns:
- the compressed frame if applicable, or the original frame if no compression was applied.
-
decode
Decodes a WebSocket frame using per-message deflate decompression. Control frames and frames without the RSV1 bit set are not decompressed.- Specified by:
decodein classWebSocketExtension- Parameters:
frame- the frame to be decoded. Must not be null.- Returns:
- the decompressed frame if applicable, or the original frame if no decompression was applied.
-
setCompressWhenHigher
public static void setCompressWhenHigher(int compressWhenHigher) Sets the threshold for compression. Frames with data length less than this value will not be compressed.- Parameters:
compressWhenHigher- the new threshold for compression in bytes.
-
getCompressWhenHigher
public static int getCompressWhenHigher()Gets the threshold for compression.- Returns:
- the threshold for compression in bytes.
-
setMaxDataLength
public static void setMaxDataLength(int maxDataLength) Sets the maximum allowed data length for decompressed data. Exceeding this limit will cause an exception.- Parameters:
maxDataLength- the new maximum data length in bytes.
-
getMaxDataLength
public static int getMaxDataLength()Gets the maximum allowed data length for decompressed data.- Returns:
- the maximum data length in bytes.
-
setDeflateLevel
public static void setDeflateLevel(int deflateLevel) Sets the deflate compression level.- Parameters:
deflateLevel- the new compression level.
-
getDeflateLevel
public static int getDeflateLevel()Gets the deflate compression level.- Returns:
- the compression level.
-
setDeflateStrategy
public static void setDeflateStrategy(int deflateStrategy) Sets the deflate compression strategy.- Parameters:
deflateStrategy- the new compression strategy.
-
getDeflateStrategy
public static int getDeflateStrategy()Gets the deflate compression strategy.- Returns:
- the compression strategy.
-
setDeflateFlush
public static void setDeflateFlush(int deflateFlush) Sets the deflate flush mode.- Parameters:
deflateFlush- the new flush mode.
-
getDeflateFlush
public static int getDeflateFlush()Gets the deflate flush mode.- Returns:
- the flush mode.
-