blob: 15564d3e6ffc93a7078ca88dcfb0c40fa4bd4d4f [file] [log] [blame]
Kino Roya9da9eb2022-10-07 23:13:01 -07001// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18import Foundation
19import Thrift
20import Common
21
22class TestServer {
23 var server: Any?
24
25 func run() throws {
26 let parameters = try TestServerParameters(arguments: CommandLine.arguments)
27
28 if parameters.showHelp {
29 parameters.printHelp()
30 return
31 }
32
33 let service = ThriftTestImpl()
34 let processor = ThriftTestProcessor(service: service)
35
36
37 switch (parameters.proto, parameters.transport) {
38 case (.binary, .buffered):
39 let proto = TBinaryProtocol.self
40 server = try TSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor)
41 case (.binary, .framed):
42 let proto = TBinaryProtocol.self
43 server = try TFramedSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor)
44 case (.compact, .buffered):
45 let proto = TCompactProtocol.self
46 server = try TSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor)
47 case (.compact, .framed):
48 let proto = TCompactProtocol.self
49 server = try TFramedSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor)
50 default:
51 throw ParserError.unsupportedOption
52 }
53 }
54}
55
56let server = TestServer()
57try server.run()
58
59RunLoop.main.run()