class WebSocket::Driver::Hybi

def parse_opcode(octet)

def parse_opcode(octet)
  rsvs = [RSV1, RSV2, RSV3].map { |rsv| (octet & rsv) == rsv }
  @frame = Frame.new
  @frame.final  = (octet & FIN) == FIN
  @frame.rsv1   = rsvs[0]
  @frame.rsv2   = rsvs[1]
  @frame.rsv3   = rsvs[2]
  @frame.opcode = (octet & OPCODE)
  @stage = 1
  unless @extensions.valid_frame_rsv?(@frame)
    return fail(:protocol_error,
        "One or more reserved bits are on: reserved1 = #{ @frame.rsv1 ? 1 : 0 }" +
        ", reserved2 = #{ @frame.rsv2 ? 1 : 0 }" +
        ", reserved3 = #{ @frame.rsv3 ? 1 : 0 }")
  end
  unless OPCODES.values.include?(@frame.opcode)
    return fail(:protocol_error, "Unrecognized frame opcode: #{ @frame.opcode }")
  end
  unless MESSAGE_OPCODES.include?(@frame.opcode) or @frame.final
    return fail(:protocol_error, "Received fragmented control frame: opcode = #{ @frame.opcode }")
  end
  if @message and OPENING_OPCODES.include?(@frame.opcode)
    return fail(:protocol_error, 'Received new data frame but previous continuous frame is unfinished')
  end
end