Class WebSocketExtension

java.lang.Object
de.craftsblock.craftsnet.api.websocket.extensions.WebSocketExtension
Direct Known Subclasses:
PerMessageDeflateExtension

public abstract class WebSocketExtension extends Object
Abstract base class for WebSocket extensions. A WebSocket extension allows for custom encoding and decoding of WebSocket frames to support features such as compression, encryption, or other protocol enhancements.

Each extension has a protocol name that identifies it. Subclasses must implement the encode(Frame) and decode(Frame) methods to define how frames are transformed by the extension.

Since:
3.0.6-SNAPSHOT
  • Constructor Details

    • WebSocketExtension

      public WebSocketExtension(String protocolName)
      Constructs a new WebSocket extension with the specified protocol name.
      Parameters:
      protocolName - the name of the protocol for this extension. This name is used to identify the extension during the WebSocket handshake and negotiation process.
  • Method Details

    • encode

      @NotNull public abstract @NotNull Frame encode(@NotNull @NotNull Frame frame)
      Encodes a WebSocket frame according to the rules of this extension. This method is called before the frame is sent over the network.
      Parameters:
      frame - the frame to be encoded. The frame should not be null.
      Returns:
      the encoded frame. The result should not be null.
    • decode

      @NotNull public abstract @NotNull Frame decode(@NotNull @NotNull Frame frame)
      Decodes a WebSocket frame according to the rules of this extension. This method is called after the frame is received from the network.
      Parameters:
      frame - the frame to be decoded. The frame should not be null.
      Returns:
      the decoded frame. The result should not be null.
    • getProtocolName

      public final String getProtocolName()
      Returns the protocol name of this extension.
      Returns:
      the protocol name. This value is used to identify the extension.