File: base.rb

package info (click to toggle)
ruby-websocket 1.2.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 412 kB
  • sloc: ruby: 2,667; makefile: 4
file content (41 lines) | stat: -rw-r--r-- 1,120 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

module WebSocket
  module Frame
    module Handler
      class Base
        def initialize(frame)
          @frame = frame
        end

        # Convert data to raw frame ready to send to client
        # @return [String] Encoded frame
        def encode_frame
          raise NotImplementedError
        end

        # Convert raw data to decoded frame
        # @return [WebSocket::Frame::Incoming] Frame if found, nil otherwise
        def decode_frame
          raise NotImplementedError
        end

        private

        # Check if frame is one of control frames
        # @param [Symbol] frame_type Frame type
        # @return [Boolean] True if given frame type is control frame
        def control_frame?(frame_type)
          !%i[text binary continuation].include?(frame_type)
        end

        # Check if frame is one of data frames
        # @param [Symbol] frame_type Frame type
        # @return [Boolean] True if given frame type is data frame
        def data_frame?(frame_type)
          %i[text binary].include?(frame_type)
        end
      end
    end
  end
end