WebSocketFrame

public struct WebSocketFrame

A structured representation of a single WebSocket frame.

  • fin

    The value of the fin bit. If set, this is the last frame in a fragmented frame. If not set, this frame is one of the intermediate frames in a fragmented frame. Must be set if a frame is not fragmented at all.

    Declaration

    Swift

    public var fin: Bool { get set }
  • The value of the first reserved bit. Must be false unless using an extension that defines its use.

    Declaration

    Swift

    public var rsv1: Bool { get set }
  • The value of the second reserved bit. Must be false unless using an extension that defines its use.

    Declaration

    Swift

    public var rsv2: Bool { get set }
  • The value of the third reserved bit. Must be false unless using an extension that defines its use.

    Declaration

    Swift

    public var rsv3: Bool { get set }
  • The opcode for this frame.

    Declaration

    Swift

    public var opcode: WebSocketOpcode { get set }
  • The total length of the data in the frame.

    Declaration

    Swift

    public var length: Int { get }
  • The masking key, if any.

    A masking key is used to prevent specific byte sequences from appearing in the network stream. This is primarily used by entities like browsers, but should be used any time it is possible for a malicious user to control the data that appears in a websocket stream.

    If this value is nil, and this frame was received from the network, the data in data is not masked. If this value is nil, and this frame is being sent to the network, the data in data will not be masked.

    Declaration

    Swift

    public var maskKey: WebSocketMaskingKey?
  • The application data.

    On frames received from the network, this data is not necessarily unmasked. This is to provide as much information as possible. If unmasked data is desired, either use the computed unmaskedData property to obtain it, or transform this data directly by calling data.unmask(maskKey).

    Declaration

    Swift

    public var data: ByteBuffer
  • The extension data, if any.

    On frames received from the network, this data is not necessarily unmasked. This is to provide as much information as possible. If unmasked data is desired, either use the computed unmaskedExtensionData property to obtain it, or transform this data directly by calling extensionData.unmask(maskKey).

    Declaration

    Swift

    public var extensionData: ByteBuffer?
  • The unmasked application data.

    If a masking key is present on the frame, this property will automatically unmask the underlying data and return the unmasked data to the user. This is a convenience method that should only be used when persisting the underlying masked data is worthwhile: otherwise, performance will often be better to manually unmask the data with data.unmask(maskKey).

    Declaration

    Swift

    public var unmaskedData: ByteBuffer { get }
  • The unmasked extension data.

    If a masking key is present on the frame, this property will automatically unmask the underlying data and return the unmasked data to the user. This is a convenience method that should only be used when persisting the underlying masked data is worthwhile: otherwise, performance will often be better to manually unmask the data with data.unmask(maskKey).

    Declaration

    Swift

    public var unmaskedExtensionData: ByteBuffer? { get }
  • Creates an empty WebSocketFrame.

    Declaration

    Swift

    public init(allocator: ByteBufferAllocator)

    Parameters

    allocator

    The ByteBufferAllocator to use when editing the empty buffers.

  • Create a WebSocketFrame with the given properties.

    Declaration

    Swift

    public init(fin: Bool = false, rsv1: Bool = false, rsv2: Bool = false, rsv3: Bool = false,
                opcode: WebSocketOpcode = .continuation, maskKey: WebSocketMaskingKey? = nil,
                data: ByteBuffer, extensionData: ByteBuffer? = nil)

    Parameters

    fin

    The value of the fin bit. Defaults to false.

    rsv1

    The value of the first reserved bit. Defaults to false.

    rsv2

    The value of the second reserved bit. Defaults to false.

    rsv3

    The value of the third reserved bit. Defaults to false.

    opcode

    The opcode for the frame. Defaults to .continuation.

    maskKey

    The masking key for the frame, if any. Defaults to nil.

    data

    The application data for the frame.

    extensionData

    The extension data for the frame.