Class PerMessageDeflateExtension

java.lang.Object
de.craftsblock.craftsnet.api.websocket.extensions.WebSocketExtension
de.craftsblock.craftsnet.api.websocket.extensions.builtin.PerMessageDeflateExtension

public class PerMessageDeflateExtension extends WebSocketExtension
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 Details

    • PerMessageDeflateExtension

      public PerMessageDeflateExtension()
      Constructs a new PerMessageDeflateExtension with the protocol name "permessage-deflate".
  • Method Details

    • encode

      @NotNull public @NotNull Frame encode(@NotNull @NotNull Frame frame)
      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:
      encode in class WebSocketExtension
      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

      @NotNull public @NotNull Frame decode(@NotNull @NotNull Frame frame)
      Decodes a WebSocket frame using per-message deflate decompression. Control frames and frames without the RSV1 bit set are not decompressed.
      Specified by:
      decode in class WebSocketExtension
      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.