Class: WebSocket::Frame::Data

### Home Classes Methods

### In Files

- lib/websocket/frame/data.rb

### Parent

String

### Methods

- ::new
- #<<
- #convert_args
- #getbytes
- #mask
- #set_mask
- #unset_mask

### Class/Module Index

Quicksearch

- WebSocket
- WebSocket::Error
- WebSocket::Error::Frame
- WebSocket::Error::Frame::ControlFramePayloadTooLong
- WebSocket::Error::Frame::DataFrameInsteadContinuation
- WebSocket::Error::Frame::FragmentedControlFrame
- WebSocket::Error::Frame::Invalid
- WebSocket::Error::Frame::InvalidPayloadEncoding
- WebSocket::Error::Frame::MaskTooShort
- WebSocket::Error::Frame::ReservedBitUsed
- WebSocket::Error::Frame::TooLong
- WebSocket::Error::Frame::UnexpectedContinuationFrame
- WebSocket::Error::Frame::UnknownCloseCode
- WebSocket::Error::Frame::UnknownFrameType
- WebSocket::Error::Frame::UnknownOpcode
- WebSocket::Error::Frame::UnknownVersion
- WebSocket::Error::Handshake
- WebSocket::Error::Handshake::GetRequestRequired
- WebSocket::Error::Handshake::InvalidAuthentication
- WebSocket::Error::Handshake::InvalidHeader
- WebSocket::Error::Handshake::InvalidStatusCode
- WebSocket::Error::Handshake::NoHostProvided
- WebSocket::Error::Handshake::UnknownVersion
- WebSocket::ExceptionHandler
- WebSocket::ExceptionHandler::ClassMethods
- WebSocket::Frame
- WebSocket::Frame::Base
- WebSocket::Frame::Data
- WebSocket::Frame::Handler
- WebSocket::Frame::Handler::Base
- WebSocket::Frame::Handler::Handler03
- WebSocket::Frame::Handler::Handler04
- WebSocket::Frame::Handler::Handler05
- WebSocket::Frame::Handler::Handler07
- WebSocket::Frame::Handler::Handler75
- WebSocket::Frame::Incoming
- WebSocket::Frame::Incoming::Client
- WebSocket::Frame::Incoming::Server
- WebSocket::Frame::Outgoing
- WebSocket::Frame::Outgoing::Client
- WebSocket::Frame::Outgoing::Server
- WebSocket::Handshake
- WebSocket::Handshake::Base
- WebSocket::Handshake::Client
- WebSocket::Handshake::Handler
- WebSocket::Handshake::Handler::Base
- WebSocket::Handshake::Handler::Client
- WebSocket::Handshake::Handler::Client01
- WebSocket::Handshake::Handler::Client04
- WebSocket::Handshake::Handler::Client11
- WebSocket::Handshake::Handler::Client75
- WebSocket::Handshake::Handler::Client76
- WebSocket::Handshake::Handler::Server
- WebSocket::Handshake::Handler::Server04
- WebSocket::Handshake::Handler::Server75
- WebSocket::Handshake::Handler::Server76
- WebSocket::Handshake::Server

No matching classes.

# WebSocket::Frame::Data

### Public Class Methods

new(*args) click to toggle source

    # File lib/websocket/frame/data.rb, line 5
    def initialize(*args)
      super(*convert_args(args))
    end

### Public Instance Methods

<<(*args) click to toggle source

    # File lib/websocket/frame/data.rb, line 9
    def <<(*args)
      super(*convert_args(args))
    end

convert_args(args) click to toggle source

Convert all arguments to ASCII-8BIT for easier traversing

    # File lib/websocket/frame/data.rb, line 14
    def convert_args(args)
      args.each { |arg| arg.force_encoding('ASCII-8BIT') }
    end

getbytes(start_index, count) click to toggle source

Extract `count` bytes starting from `start_index` and unmask it if needed.

    # File lib/websocket/frame/data.rb, line 30
    def getbytes(start_index, count)
      data = self[start_index, count]
      data = mask(data.bytes.to_a, @masking_key).pack('C*') if @masking_key
      data
    end

mask(payload, mask) click to toggle source

Mask whole payload using mask key

    # File lib/websocket/frame/data.rb, line 37
    def mask(payload, mask)
      return mask_native(payload, mask) if respond_to?(:mask_native)
      result = []
      payload.each_with_index do |byte, i|
        result[i] = byte ^ mask[i % 4]
      end
      result
    end

set_mask() click to toggle source

Extract mask from 4 first bytes according to spec

    # File lib/websocket/frame/data.rb, line 19
    def set_mask
      raise WebSocket::Error::Frame::MaskTooShort if bytesize < 4
      @masking_key = self[0..3].bytes.to_a
    end

unset_mask() click to toggle source

Remove mask flag - it will still be present in payload

    # File lib/websocket/frame/data.rb, line 25
    def unset_mask
      @masking_key = nil
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.