WebSocketFrameDecoder

public final class WebSocketFrameDecoder : ByteToMessageDecoder

An inbound ChannelHandler that deserializes websocket frames into a structured format for further processing.

This decoder has limited enforcement of compliance to RFC 6455. In particular, to guarantee that the decoder can handle arbitrary extensions, only normative MUST/MUST NOTs that do not relate to extensions (e.g. the requirement that control frames not have lengths larger than 125 bytes) are enforced by this decoder.

This decoder does not have any support for decoding extensions. If you wish to support extensions, you should implement a message-to-message decoder that performs the appropriate frame transformation as needed. All the frame data is assumed to be application data by this parser.

  • Undocumented

    Declaration

    Swift

    public typealias InboundIn = ByteBuffer
  • Declaration

    Swift

    public typealias InboundOut = WebSocketFrame
  • Undocumented

    Declaration

    Swift

    public typealias OutboundOut = WebSocketFrame
  • Construct a new WebSocketFrameDecoder

    Declaration

    Swift

    public init(maxFrameSize: Int = 1 << 14)

    Parameters

    maxFrameSize

    The maximum frame size the decoder is willing to tolerate from the remote peer. WebSockets in principle allows frame sizes up to 2**64 bytes, but this is an objectively unreasonable maximum value (on AMD64 systems it is not possible to even allocate a buffer large enough to handle this size), so we set a lower one. The default value is the same as the default HTTP/2 max frame size, 2**14 bytes. Users may override this to any value up to UInt32.max. Users are strongly encouraged not to increase this value unless they absolutely must, as the decoder will not produce partial frames, meaning that it will hold on to data until the entire body is received.

    automaticErrorHandling

    Whether this ChannelHandler should automatically handle protocol errors in frame serialization, or whether it should allow the pipeline to handle them.

  • Undocumented

    Declaration

    Swift

    public func decode(context: ChannelHandlerContext, buffer: inout ByteBuffer) throws -> DecodingState
  • Undocumented

    Declaration

    Swift

    public func decodeLast(context: ChannelHandlerContext, buffer: inout ByteBuffer, seenEOF: Bool) throws -> DecodingState